mirror of
https://github.com/cupcakearmy/advent-of-code.git
synced 2024-07-07 22:24:46 +02:00
solutions
This commit is contained in:
commit
a80cd349b7
129
.gitignore
vendored
Normal file
129
.gitignore
vendored
Normal file
@ -0,0 +1,129 @@
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
pip-wheel-metadata/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
.python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
#Pipfile.lock
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
||||
__pypackages__/
|
||||
|
||||
# Celery stuff
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
200
solutions/1/data.txt
Normal file
200
solutions/1/data.txt
Normal file
@ -0,0 +1,200 @@
|
||||
1472
|
||||
1757
|
||||
1404
|
||||
1663
|
||||
1365
|
||||
1974
|
||||
1649
|
||||
1489
|
||||
1795
|
||||
1821
|
||||
1858
|
||||
1941
|
||||
1943
|
||||
1634
|
||||
1485
|
||||
1838
|
||||
817
|
||||
1815
|
||||
1442
|
||||
639
|
||||
1182
|
||||
1632
|
||||
1587
|
||||
1918
|
||||
1040
|
||||
1441
|
||||
1784
|
||||
1725
|
||||
1951
|
||||
1285
|
||||
285
|
||||
1224
|
||||
1755
|
||||
1748
|
||||
1488
|
||||
1374
|
||||
1946
|
||||
1771
|
||||
1809
|
||||
1929
|
||||
1621
|
||||
1462
|
||||
2001
|
||||
1588
|
||||
1888
|
||||
1959
|
||||
1787
|
||||
1690
|
||||
1363
|
||||
1567
|
||||
1853
|
||||
1990
|
||||
1819
|
||||
1904
|
||||
1458
|
||||
1882
|
||||
1348
|
||||
1957
|
||||
1454
|
||||
1557
|
||||
1471
|
||||
332
|
||||
1805
|
||||
1826
|
||||
1745
|
||||
1154
|
||||
1423
|
||||
1852
|
||||
1751
|
||||
1194
|
||||
1430
|
||||
1849
|
||||
1962
|
||||
1577
|
||||
1470
|
||||
1509
|
||||
1673
|
||||
1883
|
||||
1479
|
||||
1487
|
||||
2007
|
||||
1555
|
||||
1504
|
||||
1570
|
||||
2004
|
||||
978
|
||||
1681
|
||||
1631
|
||||
1791
|
||||
1267
|
||||
1245
|
||||
1383
|
||||
1482
|
||||
1355
|
||||
1792
|
||||
1806
|
||||
1376
|
||||
1199
|
||||
1391
|
||||
1759
|
||||
1474
|
||||
1268
|
||||
1942
|
||||
1936
|
||||
1766
|
||||
1233
|
||||
1876
|
||||
1674
|
||||
1761
|
||||
1542
|
||||
1468
|
||||
1543
|
||||
1986
|
||||
2005
|
||||
1689
|
||||
1606
|
||||
1865
|
||||
1783
|
||||
1807
|
||||
1779
|
||||
1860
|
||||
1408
|
||||
1505
|
||||
1435
|
||||
1205
|
||||
1952
|
||||
1201
|
||||
1714
|
||||
1743
|
||||
1872
|
||||
1897
|
||||
1978
|
||||
1683
|
||||
1846
|
||||
858
|
||||
1528
|
||||
1629
|
||||
1510
|
||||
1446
|
||||
1869
|
||||
1347
|
||||
685
|
||||
1478
|
||||
1387
|
||||
687
|
||||
1964
|
||||
1968
|
||||
1429
|
||||
1460
|
||||
1777
|
||||
1417
|
||||
1768
|
||||
1672
|
||||
1767
|
||||
1400
|
||||
1914
|
||||
1715
|
||||
1425
|
||||
1700
|
||||
1756
|
||||
1835
|
||||
1926
|
||||
1889
|
||||
1568
|
||||
1393
|
||||
1960
|
||||
1540
|
||||
1810
|
||||
1401
|
||||
1685
|
||||
830
|
||||
1789
|
||||
1652
|
||||
1899
|
||||
796
|
||||
1483
|
||||
1261
|
||||
1398
|
||||
1727
|
||||
1566
|
||||
1812
|
||||
1937
|
||||
1993
|
||||
1286
|
||||
1992
|
||||
1611
|
||||
1825
|
||||
1868
|
||||
1870
|
||||
1746
|
||||
1361
|
||||
1418
|
||||
1820
|
||||
1598
|
||||
1911
|
||||
1428
|
||||
1734
|
||||
1833
|
||||
1436
|
||||
1560
|
17
solutions/1/main.py
Normal file
17
solutions/1/main.py
Normal file
@ -0,0 +1,17 @@
|
||||
from typing import List
|
||||
from itertools import product
|
||||
from os.path import join, dirname
|
||||
|
||||
target = 2020
|
||||
data = join(dirname(__file__), 'data.txt')
|
||||
with open(data) as f:
|
||||
numbers: List[int] = list(map(int, f.readlines()))
|
||||
for a, b in product(numbers, numbers):
|
||||
if a + b == target:
|
||||
print(f'The numbers: {a} and {b}.\tSolution: {a*b}')
|
||||
break
|
||||
|
||||
for a, b, c in product(numbers, numbers, numbers):
|
||||
if a + b + c == target:
|
||||
print(f'The numbers: {a}, {b} and {c}.\tSolution: {a*b*c}')
|
||||
break
|
1000
solutions/2/data.txt
Normal file
1000
solutions/2/data.txt
Normal file
File diff suppressed because it is too large
Load Diff
28
solutions/2/main.py
Normal file
28
solutions/2/main.py
Normal file
@ -0,0 +1,28 @@
|
||||
from typing import List
|
||||
from os.path import join, dirname
|
||||
|
||||
|
||||
def checkRow(row: str, alternative=False) -> bool:
|
||||
rule, password = map(lambda s: s.strip(), row.split(':'))
|
||||
amount, char = rule.split(' ')
|
||||
minimum, maximum = map(int, amount.split('-'))
|
||||
if alternative:
|
||||
return (password[minimum - 1] == char) ^ (password[maximum - 1] != char)
|
||||
else:
|
||||
occurrences = password.count(char)
|
||||
return minimum <= occurrences <= maximum
|
||||
|
||||
|
||||
data = join(dirname(__file__), 'data.txt')
|
||||
with open(data) as f:
|
||||
valid = 0
|
||||
valid_alt = 0
|
||||
rows = list(f.read().strip().split('\n'))
|
||||
for row in rows:
|
||||
if(checkRow(row)):
|
||||
valid += 1
|
||||
if(checkRow(row, alternative=True)):
|
||||
valid_alt += 1
|
||||
print(f'Found {valid} valid passwords.')
|
||||
print('Policy changed...')
|
||||
print(f'Found {valid_alt} valid passwords.')
|
Loading…
Reference in New Issue
Block a user