Import from Nextcloud
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
from itertools import combinations
|
||||
|
||||
with open('01-input') as f:
|
||||
numbers = {int(row.strip()) for row in f}
|
||||
|
||||
for n in numbers:
|
||||
if 2020-n in numbers:
|
||||
print(n*(2020-n))
|
||||
|
||||
|
||||
for a,b,c in combinations(numbers, 3):
|
||||
if a+b+c==2020:
|
||||
print(a*b*c)
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
1757
|
||||
1890
|
||||
1750
|
||||
1440
|
||||
1822
|
||||
1957
|
||||
2005
|
||||
1979
|
||||
1405
|
||||
2003
|
||||
1997
|
||||
1741
|
||||
1494
|
||||
1780
|
||||
1774
|
||||
1813
|
||||
447
|
||||
1429
|
||||
1990
|
||||
1767
|
||||
1969
|
||||
1787
|
||||
1944
|
||||
1863
|
||||
1778
|
||||
2004
|
||||
1991
|
||||
1754
|
||||
1748
|
||||
1756
|
||||
1977
|
||||
611
|
||||
1934
|
||||
1818
|
||||
1924
|
||||
528
|
||||
1753
|
||||
1867
|
||||
1865
|
||||
1799
|
||||
1743
|
||||
1955
|
||||
1993
|
||||
1972
|
||||
1987
|
||||
1960
|
||||
1817
|
||||
1837
|
||||
1900
|
||||
1839
|
||||
1946
|
||||
1786
|
||||
1857
|
||||
1840
|
||||
1985
|
||||
1850
|
||||
1801
|
||||
1926
|
||||
1523
|
||||
1886
|
||||
1492
|
||||
1737
|
||||
1909
|
||||
1766
|
||||
1986
|
||||
1773
|
||||
1749
|
||||
1781
|
||||
1760
|
||||
1849
|
||||
1833
|
||||
1854
|
||||
1814
|
||||
1820
|
||||
2000
|
||||
1834
|
||||
1851
|
||||
1779
|
||||
1825
|
||||
1885
|
||||
1882
|
||||
1912
|
||||
962
|
||||
1988
|
||||
302
|
||||
1965
|
||||
1751
|
||||
1764
|
||||
1844
|
||||
1949
|
||||
1984
|
||||
1933
|
||||
958
|
||||
1746
|
||||
1999
|
||||
1914
|
||||
1989
|
||||
1879
|
||||
1954
|
||||
1827
|
||||
1816
|
||||
1918
|
||||
633
|
||||
1797
|
||||
1811
|
||||
1936
|
||||
1961
|
||||
1937
|
||||
1829
|
||||
1788
|
||||
1772
|
||||
1505
|
||||
1905
|
||||
1304
|
||||
1404
|
||||
1868
|
||||
1978
|
||||
1872
|
||||
2006
|
||||
1256
|
||||
1883
|
||||
1966
|
||||
1931
|
||||
1796
|
||||
1793
|
||||
714
|
||||
1904
|
||||
1841
|
||||
1824
|
||||
1962
|
||||
1739
|
||||
1897
|
||||
1906
|
||||
1735
|
||||
1876
|
||||
873
|
||||
1959
|
||||
1963
|
||||
1917
|
||||
1804
|
||||
1789
|
||||
1782
|
||||
1848
|
||||
1828
|
||||
1826
|
||||
1929
|
||||
1525
|
||||
1862
|
||||
1952
|
||||
1878
|
||||
1775
|
||||
1776
|
||||
1430
|
||||
1943
|
||||
1938
|
||||
1941
|
||||
1594
|
||||
1928
|
||||
1856
|
||||
1903
|
||||
1871
|
||||
1836
|
||||
1847
|
||||
1956
|
||||
1915
|
||||
1870
|
||||
1875
|
||||
1892
|
||||
276
|
||||
1896
|
||||
1945
|
||||
1821
|
||||
1947
|
||||
1898
|
||||
1802
|
||||
1853
|
||||
1895
|
||||
1790
|
||||
1819
|
||||
1980
|
||||
1832
|
||||
1673
|
||||
1964
|
||||
1800
|
||||
1971
|
||||
1842
|
||||
2002
|
||||
1921
|
||||
1940
|
||||
1845
|
||||
1527
|
||||
1428
|
||||
1932
|
||||
1893
|
||||
1908
|
||||
1889
|
||||
1974
|
||||
1981
|
||||
1791
|
||||
1975
|
||||
@@ -0,0 +1,25 @@
|
||||
import re
|
||||
|
||||
with open('02-input') as f:
|
||||
passwords = [row.strip() for row in f]
|
||||
|
||||
pattern = re.compile(r'(\d*)-(\d*) (\w): (.*)')
|
||||
count = 0
|
||||
for p in passwords:
|
||||
if m := pattern.match(p):
|
||||
n1, n2, l, p = m.groups()
|
||||
c = p.count(l)
|
||||
if int(n1)<=c<=int(n2):
|
||||
count += 1
|
||||
|
||||
print(count)
|
||||
|
||||
count = 0
|
||||
for p in passwords:
|
||||
if m := pattern.match(p):
|
||||
n1, n2, l, p = m.groups()
|
||||
n1, n2 = int(n1)-1, int(n2)-1
|
||||
if p[n1]==l and p[n2]!=l or p[n1]!=l and p[n2]==l:
|
||||
count += 1
|
||||
|
||||
print(count)
|
||||
@@ -0,0 +1,29 @@
|
||||
import re
|
||||
|
||||
with open('03-input') as f:
|
||||
landscape = [row.strip() for row in f]
|
||||
|
||||
count = 0
|
||||
i, j = 0, 0
|
||||
l = len(landscape[0])
|
||||
while i<len(landscape):
|
||||
if landscape[i][j]=='#':
|
||||
count += 1
|
||||
i += 1
|
||||
j = (j+3)%l
|
||||
print(count)
|
||||
|
||||
counts = []
|
||||
for dx, dy in [(1,1), (3,1), (5,1), (7,1), (1, 2)]:
|
||||
count = 0
|
||||
i, j = 0, 0
|
||||
l = len(landscape[0])
|
||||
while i<len(landscape):
|
||||
if landscape[i][j]=='#':
|
||||
count += 1
|
||||
i += dy
|
||||
j = (j+dx)%l
|
||||
counts.append(count)
|
||||
|
||||
from math import prod
|
||||
print(prod(counts))
|
||||
@@ -0,0 +1,323 @@
|
||||
.........#.#.#.........#.#.....
|
||||
...#......#...#.....#.....#....
|
||||
#.....#.....#.....#.#........#.
|
||||
......#..#......#.......#......
|
||||
.#..........#.............#...#
|
||||
............#..##.......##...##
|
||||
....#.....#..#....#............
|
||||
.#..#.........#....#.#....#....
|
||||
#.#...#...##..##.#..##..#....#.
|
||||
.#.......#.#...#..........#....
|
||||
...#...#........##...#..#.....#
|
||||
..................#..........#.
|
||||
.....#.##..............#.......
|
||||
........#....##..##....#.......
|
||||
...#.....#.##..........#...##..
|
||||
.......#.#....#............#...
|
||||
..............#......#......#..
|
||||
#.......#...........#........##
|
||||
.......#.......##......#.......
|
||||
................#....##...#.#.#
|
||||
#.......#....................#.
|
||||
.##.#..##..#..#.#.....#.....#..
|
||||
#...#............#......##....#
|
||||
.#....##.#......#.#......#..#..
|
||||
..........#........#.#.#.......
|
||||
...#...#..........#..#....#....
|
||||
..#.#...#...#...##...##......#.
|
||||
......#...#........#.......###.
|
||||
....#...............#.###...#.#
|
||||
..................#.....#..#.#.
|
||||
.#...#..#..........#........#..
|
||||
#..........##................##
|
||||
...#.....#...#......#.#......#.
|
||||
......#..........#.#......#..#.
|
||||
..#......#.....................
|
||||
............#.........##.......
|
||||
......#.......#........#.......
|
||||
#.#...#...........#.......#....
|
||||
.#.#........#.#.#....#........#
|
||||
#.....##........#.#.....#.#....
|
||||
.#...#..........##...#.....#..#
|
||||
.........#....###............#.
|
||||
..#...#..............#.#.#.....
|
||||
.....#.#.#..#.#.#.###......#.#.
|
||||
.#.##...#.......###..#.........
|
||||
.....##....#.##..#.##..#.......
|
||||
..#...........##......#..#.....
|
||||
................##...#.........
|
||||
##.....................#..#.###
|
||||
...#..#....#...........#.......
|
||||
.#.............##.#.....#.#....
|
||||
.......#.#.#....##..#....#...#.
|
||||
...##..#..........#....#.......
|
||||
....##......#.........#........
|
||||
.##....#...........#.#.......#.
|
||||
...#...#.##.......#.#..........
|
||||
..#.........#.##...........#...
|
||||
....#.##........#.......#...##.
|
||||
...................#..#..#...##
|
||||
#...#......###..##.#..###......
|
||||
#.............#.#........#...#.
|
||||
...#...#..#..#..............#..
|
||||
#.....#..#...#...#......#.#..#.
|
||||
...##.............#........##.#
|
||||
......#.#.........#.#....#...#.
|
||||
........##............#...#....
|
||||
............#.#...#......#.....
|
||||
...#...........#...#...........
|
||||
.........#.#......#............
|
||||
....#.............#..#.....#..#
|
||||
#.....#...........#.....#.#.#.#
|
||||
.............#.....##......#...
|
||||
...................###.#......#
|
||||
#.##.....#...#..#..#...#....#..
|
||||
............#.....#....#.#.....
|
||||
#....#..#..........#....#..#...
|
||||
..........##..................#
|
||||
....#.......###..#......###....
|
||||
.......#...#.##.##..#....##....
|
||||
...##...............#.....#...#
|
||||
#...........#...#......#..#..#.
|
||||
..##....#.......#...#.....#....
|
||||
.......##..............#.##..#.
|
||||
.#......#..........#.......#...
|
||||
....##...................#.#..#
|
||||
......#....###................#
|
||||
.#........#...........#........
|
||||
.#.....##....#..##...........#.
|
||||
##..............##...#.......#.
|
||||
......#..........#..........##.
|
||||
..#.....#.#.........####....#..
|
||||
.............#......#......#...
|
||||
..#.............#...........##.
|
||||
#.#...#........#..........##...
|
||||
...#....#.....#.....#.....##...
|
||||
......#........................
|
||||
......#..#...#......#.....#....
|
||||
......#....##.....#....#.......
|
||||
#.#......#.##..#...............
|
||||
..........#.#.##..##..#........
|
||||
......#.#..#....###.#..........
|
||||
........................#....#.
|
||||
#.#.............#....#.....##.#
|
||||
.#.#..........#.......#..#....#
|
||||
..#...#......#..#..#...#.#...#.
|
||||
...#.##...###..................
|
||||
........#.#...........#...#....
|
||||
........#..........#....#......
|
||||
#....#........#.......##.....#.
|
||||
......###...##...#......#......
|
||||
............#.......#.....##..#
|
||||
....#..#.......##......#.......
|
||||
#............##................
|
||||
...............#..#......#...#.
|
||||
.#....##...#......#............
|
||||
#...#................#.........
|
||||
..#....#..#........##......#...
|
||||
....#....###......##.#.......#.
|
||||
......#.#..#.#..#....#..#......
|
||||
....#..........#..#..#.........
|
||||
.#..#.......#......#........#..
|
||||
.......#..#..#............#....
|
||||
.............#...#....#..#.....
|
||||
..............#.#.#.........#..
|
||||
#.....##.......#....#..........
|
||||
...#.....#......#..............
|
||||
...##.#..#.#........#..##....#.
|
||||
.......#.#.....##..#...........
|
||||
.....#.#....#..................
|
||||
.#......#.###..............##..
|
||||
..#....#...#..#...##...##....#.
|
||||
..........##..#...#..#.........
|
||||
..#............#........#.#...#
|
||||
.........................#.#.#.
|
||||
......#........#.#..#......##.#
|
||||
#.#......#..#.........#........
|
||||
.....#........#......#...#.#...
|
||||
........##....##....#.#........
|
||||
....#....#.#...#...##....#..#..
|
||||
#.............#.....#..........
|
||||
#............##..#............#
|
||||
..#.#......#........#..........
|
||||
.#......#......#.#.##.##.......
|
||||
..#.....#..........#......##...
|
||||
...#......#...#.##....#.....##.
|
||||
......#......#...........#.#...
|
||||
....#........#..#..#........#.#
|
||||
....#.........#.....#...#.#.#..
|
||||
....#.....###........#.........
|
||||
.............##........#.#.....
|
||||
...#............#........#.#.#.
|
||||
......#....#.......#.#.........
|
||||
.....#................#........
|
||||
.#....#..#.#.............#...#.
|
||||
#..##...#............#......#..
|
||||
...#..#........................
|
||||
.#.#...........#.......#.......
|
||||
#....###............##.........
|
||||
...##....#.#............##.....
|
||||
.........####......#........#..
|
||||
.....#.......#.#...............
|
||||
.......#...#.###..#....#...#..#
|
||||
...#.....##..#....#..#.#...###.
|
||||
.............#........#.#.#..#.
|
||||
................#..........##..
|
||||
.......####..##..##........##.#
|
||||
..#......#..#..#.#.##..........
|
||||
#....#........#....#...###.#.#.
|
||||
........##........##.....#.....
|
||||
...........#.#...........#....#
|
||||
#.............#...........#....
|
||||
...#.........#...#....#.....#..
|
||||
..##......#...#...............#
|
||||
.............#.........#....#..
|
||||
..#...........#..#........#.##.
|
||||
.#.#......#.............##...#.
|
||||
.#......#.....##.#..#..#.......
|
||||
....##......#..................
|
||||
.#.#..##............#....#....#
|
||||
........#...##.............#..#
|
||||
........#....##.....#......###.
|
||||
.........#....#.#..............
|
||||
#.....#........................
|
||||
.#..#....#.....#......#.###..#.
|
||||
..........#...#....##....#..#..
|
||||
...#.#.#...##..#..#......#..#.#
|
||||
#............#.....#....#......
|
||||
#.###...#.#......###..#....#..#
|
||||
...#.###........#......#....#..
|
||||
..#.##...#.........#.#.........
|
||||
............##.................
|
||||
....#..........#.#.#.#.#....#..
|
||||
...##.#...#.......#.......##..#
|
||||
....##.#........#....#...#.....
|
||||
.............#.#....#...#.....#
|
||||
...#......................##...
|
||||
..#...#.....#.....#........#..#
|
||||
..#..#.......#....#..##.....#..
|
||||
..#..#.#.......................
|
||||
.......##..#....#....#..#......
|
||||
....#......##....#............#
|
||||
.#...#..#..#.##...#.#...#......
|
||||
.....#......#....#.........#...
|
||||
.##......##.........#....#.....
|
||||
#...........#...##.....#......#
|
||||
.....#.#.......#.........#.....
|
||||
.........#..........#..####.##.
|
||||
............#..#......#.#......
|
||||
.#.............#........#.#....
|
||||
......#......#...#..#....#####.
|
||||
.........##.#..##...###..#....#
|
||||
....#.#....#.#..#.........#....
|
||||
..#.............#...##...##....
|
||||
........#..........#.##..#....#
|
||||
.....#...#..##........#.#..#...
|
||||
##..#.#.....#............#.....
|
||||
.............#........##...##..
|
||||
#......####.....##.............
|
||||
..##.....##....###..#.#....#...
|
||||
......##.##.#...#..#.#..##.....
|
||||
......#.................#......
|
||||
#.....#.#...#......#.#....#....
|
||||
....#.#........#..............#
|
||||
##........#.......##.#...##...#
|
||||
..#..................#.#....#..
|
||||
...........#..........#.#.....#
|
||||
........##.#.....#......#..#..#
|
||||
.....#....#..#.....#.........##
|
||||
#.#..#..#...#......#..........#
|
||||
#...##.....#..#.#.......#.##...
|
||||
..#....##...............#......
|
||||
#..........#.#.........#.#....#
|
||||
..............#......#....#....
|
||||
.....#...........#...#...#...#.
|
||||
...#......#....#....#..........
|
||||
.#..........#.#....##..##....#.
|
||||
..............#.........#.#....
|
||||
.......#.....#.....#...##....#.
|
||||
##.#.........#....#.....#.#....
|
||||
....#..#......#................
|
||||
......##.....#.......##........
|
||||
.....##...#........#...#...#...
|
||||
..#...#...#..#..#.#......#..#..
|
||||
....#...#.......#..............
|
||||
....#..#.........###........#..
|
||||
....#.............##..#........
|
||||
..........##.#.......##..##....
|
||||
#.##..................#.....#..
|
||||
#........#........#.....#......
|
||||
.#...#......#..................
|
||||
#....##.##......#...#.........#
|
||||
......#.##..##................#
|
||||
............#.........##.......
|
||||
..........####.#........#.....#
|
||||
.##...#...#....#..#............
|
||||
.#.##...#..#...#......#......##
|
||||
.....#.#....#..###......#.#.#..
|
||||
...#.......................##..
|
||||
......................#.......#
|
||||
..#....#.........#..#.#.....#..
|
||||
.#....#..#....#...#............
|
||||
..........#...##.....#.#..#....
|
||||
........#..#..#....#...#...#...
|
||||
.....#......#.#................
|
||||
.....#...........#...#.........
|
||||
.....#...##..#.#....#..#.....#.
|
||||
#.......#.............##.......
|
||||
................#....#.#..#....
|
||||
.#..##...#.#........#......#.#.
|
||||
.#.##..........#...............
|
||||
....##......#....#........#....
|
||||
....#..#....#.##.#.............
|
||||
.......#..#......##.#.....#....
|
||||
.......#.....#.............#...
|
||||
.....#....#.......#............
|
||||
........#.#...##..##..##.......
|
||||
#.........##....##...##........
|
||||
........#..#.#..........###.#..
|
||||
..........................#.#..
|
||||
#.....#.......#..#........#....
|
||||
...##.....#.......#......#.....
|
||||
.#.#..#...........#...........#
|
||||
.....##..#........#...####.....
|
||||
.#.#...##.#.#..#..#.#..#.......
|
||||
..#.##.#...#.#.#...#..#........
|
||||
............#..........#..#....
|
||||
...............#..##.#.........
|
||||
.............#.....#....#......
|
||||
...##..##......##..........#...
|
||||
..#.......#....#..........#...#
|
||||
.##................#.#.#.......
|
||||
.....##.....#..#.....#.........
|
||||
......#.#.......#......#..#....
|
||||
.....#.....#........#.......##.
|
||||
......#.......##......#...#...#
|
||||
....#...........###.........#..
|
||||
...#.....#.........##........#.
|
||||
..#.....#..............#.......
|
||||
....#.......#...#....#....#..##
|
||||
......#...........#...........#
|
||||
.##......#......#.#.....#.##...
|
||||
....#..##......#...#..#.#.###..
|
||||
.......#.#....#......#..#......
|
||||
..........#........#...........
|
||||
#.##.........#.#.#...#...#.#...
|
||||
.#......###.....#....#.#....#..
|
||||
...................##..#.......
|
||||
....#..#..............#.#.....#
|
||||
#..................#.....#.....
|
||||
...........##.##.......#..#.#..
|
||||
........#.#......#...........#.
|
||||
#..#.......#...#...........#.#.
|
||||
......##...........#...........
|
||||
.........#.#........#........#.
|
||||
#......#....#.#.....#..#.......
|
||||
............#..#.....##...#....
|
||||
.#......#..#......#.........#..
|
||||
.......#...#.........#.##.....#
|
||||
........................#..#...
|
||||
.###..............#.#..#.......
|
||||
.....#.........#.......#......#
|
||||
..##..##....#.....#.......#.#..
|
||||
...###.#..#.##............#....
|
||||
@@ -0,0 +1,23 @@
|
||||
import re
|
||||
|
||||
with open('04-input') as f:
|
||||
text = f.read()
|
||||
|
||||
while '\n\n\n' in text:
|
||||
text = text.replace('\n\n\n', '\n\n')
|
||||
passports = text.split('\n\n')
|
||||
passports = [dict(kv.split(':') for kv in p.replace('\n\n', ' ').split()) for p in passports]
|
||||
valid = { 'byr', 'iyr', 'eyr', 'hgt', 'hcl', 'ecl', 'pid', }
|
||||
print(sum(1 for p in passports if valid.issubset(p.keys())))
|
||||
|
||||
from functools import partial
|
||||
def int_val(least, most, n):
|
||||
return least<=n<=most
|
||||
v_byr = partial(int_val, 1920, 2002)
|
||||
v_iyr = partial(int_val, 2010, 2020)
|
||||
v_eyr = partial(int_val, 2020, 2030)
|
||||
v_cm = partial(int_val, 150, 193)
|
||||
v_in = partial(int_val, 59, 76)
|
||||
|
||||
def is_valid(passport):
|
||||
valid.issubset(p.keys())
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 Fedor Lyanguzov
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
Reference in New Issue
Block a user