Browse Source

Giving up, doing this year in Python

Initially wanted to try C++, but I have very little time, and wanted to
try going for the leaderboards once as well, so I'm settling with Python.
master
mid-kid 4 years ago
commit
e9e0b06d4f
  1. 31
      d01.py
  2. 100000
      d01_bigboy.txt
  3. 200
      d01_input.txt
  4. 2
      d01_output.txt
  5. 29
      d02.py
  6. 1000
      d02_input.txt
  7. 2
      d02_output.txt
  8. 22
      d03.py
  9. 323
      d03_input.txt
  10. 2
      d03_output.txt
  11. 55
      d04.py
  12. 1100
      d04_input.txt
  13. 2
      d04_output.txt

31
d01.py

@ -0,0 +1,31 @@
#!/usr/bin/env python3
# 99920044 instead of 2020 for bigboy
# p1: 134283487359328
# p2: 1655132197274893972
from sys import argv
i = [int(x) for x in open(argv[1])]
for x in i:
for y in i:
if x+y == 2020:
print(x*y)
break
else:
continue
break
for x in i:
for y in i:
for z in i:
if x+y+z == 2020:
print(x*y*z)
break
else:
continue
break
else:
continue
break

100000
d01_bigboy.txt

File diff suppressed because it is too large

200
d01_input.txt

@ -0,0 +1,200 @@
1765
1742
1756
1688
1973
1684
1711
1728
1603
1674
1850
1836
1719
1937
1970
1770
1954
1848
1885
1851
1474
1801
1769
1904
1906
1739
1717
1830
1985
1930
1791
1977
1713
1787
1773
1672
1750
1931
1807
1762
1835
1736
1979
1923
1782
1797
1822
1903
1729
343
1678
1753
1873
1358
1987
1821
1761
1988
1886
1669
857
1894
1404
1909
1789
1752
1882
1969
1892
1701
1956
1839
483
1897
1730
1829
1879
1810
1755
1799
1932
1715
1809
418
1896
1691
1749
1922
1631
1780
1734
1859
1695
1548
1948
1997
1921
1994
1369
1364
1764
1697
1833
1239
616
1786
1890
677
1867
1705
1993
1925
1774
1732
1686
1847
1911
1841
1962
1907
1919
1725
1687
1236
1864
1855
1928
1941
1709
1683
1676
1889
1982
1595
1735
1857
1731
1816
2003
1724
741
1655
1308
1959
1955
1768
1795
1804
1961
1693
1884
1813
1927
1845
1689
1646
1803
2008
1599
1984
1871
1814
1918
1990
1858
1908
1949
1980
1618
1718
1712
1989
1876
1947
1974
1838
1865
1842
1817
680
1986
1812
1895
1991
1644
1877
1880
1792
1800
1899
1806
1699
1685
1793
1647
1429
1751
1722
1887
1968

2
d01_output.txt

@ -0,0 +1,2 @@
864864
281473080

29
d02.py

@ -0,0 +1,29 @@
#!/usr/bin/env python3
from sys import argv
i = [x for x in open(argv[1])]
ok = 0
ok2 = 0
for l in i:
req = l.split(": ")[0]
nums = req.split(" ")[0]
s = int(nums.split("-")[0])
e = int(nums.split("-")[1])
let = req.split(" ")[1]
pwd = l.split(": ")[1]
c = 0
for i, ch in enumerate(pwd):
if ch == let:
if i + 1 == s or i + 1 == e:
p2 += 1
c += 1
if c >= s and c <= e:
ok += 1
if (pwd[s-1] == let) ^ (pwd[e-1] == let):
ok2 += 1
print(ok)
print(ok2)

1000
d02_input.txt

File diff suppressed because it is too large

2
d02_output.txt

@ -0,0 +1,2 @@
454
649

22
d03.py

@ -0,0 +1,22 @@
#!/usr/bin/env python3
from sys import argv
i = [x.strip() for x in open(argv[1])]
h = len(i)
w = len(i[0])
def check(dx, dy):
x = 0
y = 0
ok = 0
while y < h:
if i[y][x%w] == "#":
ok += 1
x += dx
y += dy
return ok
print(check(3,1))
print(check(1,1)*check(3,1)*check(5,1)*check(7,1)*check(1,2))

323
d03_input.txt

@ -0,0 +1,323 @@
...........#..............##...
...#....................#......
.....####...........#.#..#.#...
....##.#.......................
.......#.##......#.###.........
.#.....#.......##.......#.....#
...........##....##.#....#.....
......#.........#....#.........
..###....#.........#....#.#....
....#....#.#..#..#.........#.#.
..........................#...#
.##...........#...#.#.......#..
#....##...#.#....#.............
....#..##......##..#.#....#....
#..........#.............#..#.#
...#.####.....#..#.#.#..#...#..
..........#......#........#..#.
............#.....#..#..#....#.
.................#...#.........
..#...#...................#....
..............##...#...........
..........................#..#.
#...#...#............#...#.....
.................#..##.......#.
............#....#.............
.#......#.#...#....#...#.......
.....#.....##..##.....#.......#
.#..#..##...............#..#...
#...#...##............#........
.......#....#.......#..........
...............................
#................#...#.........
...#...#..#..#.............##.#
......#........#..............#
...#.....##.#...#...#..........
.........#..#........##.#...##.
#.........##..#.......#........
........##.#.#.................
.#....#............###....#....
...#.##....#.....##..#..#....#.
....#..#........##..#...#..##..
..........#............#.......
.........#........##....#..##..
#....#.........#.#.......#..#..
...#....#......##.#............
........#..#...............#...
..............#.....#........#.
......#..#.#........#..#..#.##.
..#........###....#.#..........
...#..#...#.#....##..#........#
........#..#..............#....
#.####.................#....##.
.#................#............
....#....#....#................
#......#........##....#...#....
......#..##..#..###...#.#.#....
.#..........##.................
...#...#....#...#.....#.....#..
............#......##.........#
..............##...............
##....#....#...#...#....#..###.
...................#.......##..
#.....##........#....#.........
...#.......#...........#.......
...............##..............
##.......#......#.....#........
#....#..#..##..#.......#..#..#.
.....#.............#.......#...
......#..#........#.......#.#..
..#...#...........#.##.........
..#................####.#..#...
......##....#.........#........
..#..#.......#...##....#......#
#.#..........#..............#.#
.#.#..............#.##...#.....
................#.....#.#......
##.........#.........#.....#...
....#.#.....................#..
..#..#..#........#.......#.....
.....#..#.#....#....#.....#....
..####....#.#.........#........
#..##...##..#.#............#..#
.#........#..##.#.....#......##
.##.##.....##....#.#...........
....#..#.#..##............#.#..
........#.#...#....#.........#.
.....#.#.#.....#....#.....##...
#...#..#....##..#..............
..#...#....#...##..#.......#...
.#....##.......................
.........#............##.#..#..
....#................#...#.#...
...................#..#...#....
#..#...................#.......
..##..............#..........##
...#.##......#.............#...
.........#.#.........#.........
...###......#.................#
..........#....##..............
.##..#....#.........#.#........
.........#.......#.......#.#...
#........#............#......#.
....................#..........
.......#...##..........#...#...
....#.#.......#.#...##..#.#....
...#..........#..............#.
........##..............#......
......#...##......#....##......
....#.....#.#.##..............#
...#...........#.#.............
...........#......#.#..........
...#.#......#......#...#...#...
..#.......................#....
...#...#..#..................#.
##.....#.....#..#..#.....#...#.
.#..#.......##.#.#.............
......##.......##............#.
.......#..#..#.......#....#.#..
......#.....##..##...#........#
.....#........#.##..........#..
#....##............#........#..
.....#..#...#............#...#.
##.#....#........#.............
.##...............##......#.#..
###..#..#.......#.#..........#.
.....#...........#...##........
..#.#.#.........#.....#....#...
.....#....##.......#..#.#......
......#.....#...#..#...##..#...
.....#....#................#...
......#....#.#...##......##.#.#
.....###.............#.........
.................#......#####..
.#.......#..........#.#....##..
..#..#.......#.....#..#......##
..........#.#.##.......##....#.
##...#...##.##......#..###.....
..#..#..#......#....#..........
..#...#....#......#....#....#.#
.#...#........#.....#......#..#
#.........#......#.##.##.......
#.##..#.............#.....#....
....#.......#..#..##...##......
...#.............#.#......#....
#.....#..........##...##.....#.
...............#........#....#.
#.....#...#..#.............##..
.#....##.#.......#.#..........#
....#....#.#.....#....#......#.
......#......#.................
.#.#..#.#.#...#...#..#.##.#..##
.............#.....#...........
............#...#..#..#.....#..
.#..........#.......#....#.....
......#..###.#...#.............
......#..........#.............
....#.................#..#.#.#.
...##.##.#....##.##............
####......#........###......#..
..#.......#.#..#.##............
.....#.....#.#.......#.....#...
.....#..........#.#............
#.....#.............#......##..
......##..........##....#......
.#..............#..........#...
......#..#...#........#..#....#
.#......#.......#..#...........
..#..#....#.#.......#....##..#.
........#.#................#...
#.......#.##.#......#...#.....#
..#...#.#.....##...............
..........#.....##.............
.......#............#........#.
...#............#......#......#
.#..#.......#...#...#..#..#....
#....#.#...#......#...#......#.
.#.......#..#.#...........#....
...##.#...#.......#..........#.
.....#..............#..#...#...
...........................#...
.............#.....#...........
....#.#..#..#...#..#...........
.....#.#.#..#.#....#.#.#.......
.......#..............#.....##.
........#..#..#.#..#...#.#.....
.....#.#...#.#.#.....#..#...#..
.....#....#.......#......#.#...
.#.#...........#........#......
.##..##......#......#......#.#.
.....#.###.#.......##.#..#.....
#.......##..#.........#....#...
.#.............#.........#.#.#.
..........#..#..#....#....#....
#....#...........##..#.....#..#
......#....#...###..#...#......
.....#....#........#....#..#...
...##..............#.##...#....
.#............#........##......
..##........#.#...........#...#
..#.#...##...#..#..........##..
.................#.......#.....
......#.....#............#.....
.#.....#.........#.#..#.#......
.............#.#.#..#.......#.#
#......#.....#..##...#.......#.
.......#.#..#...#.........#....
...#..##...#.........#.#....#..
........................#..#...
....##..##................#....
.......#..#.......#........##..
.....#....#.##....#............
.#....#............#.....#...#.
..##.....#......#......#.#....#
...#...........#...##....#.....
......#.##.#..##...##.#.#..##..
.......##....#......#....#.#...
.....####..#............#..##..
......##..##..##.........#...#.
.#.#...............#.........#.
......#......#...........#.....
.....#.......##.....#..#.......
.....##..#..#....#.#.......#...
...........###.###.##..#.#..#..
.#...............##.........#..
......##..........#..#.....##.#
.............#....#....#..##...
.#..............#........#.....
.#..#.........................#
.##..............#..........#..
..#..#.#.#.#......#............
....#...#.#.#....#........#..#.
.....#........#....#.....#.....
.#...#.#......#..#........#.##.
.......#.....#................#
.#.#........................#..
............#..#.......#.......
....##.#........#...#.#.#.#.#..
.....#.......##................
...##...#....#.....#.#.........
#...#..............#.......#...
...#.#.#.#..##....##...........
.....##...#....#.....#.........
#......#.....#....#............
....#..###....#.##.......#...#.
..................##.#......#..
.....##..............##.#....#.
.........#...#........#..#....#
.##..#.........#....#..##...#..
#.#.##................#.##.....
..#.#....#.#.......#....#......
..#.#.##.#.......#.............
..#....#.#..##.#..........#.#..
#.....#.....#.....#.........#..
#.......##.....#....##.....#...
..#...#.........##.#..##.......
..#.#.........#.......#........
#.....#.....##.#.#..#...#..#.##
.........................#.##..
..#.#..#..#..#........#......#.
..#..............#.............
.....#.......##.##.....#.......
....#...#...............#..#...
....#......#.#........##.#..#.#
....................#..#.......
.....#.......#......#.##.......
#.......##..........#.....#....
.#.......#....#.#......#.......
......#...#...............#.##.
....##.#.....#.............#.##
#..#................##...#.....
....###......#.#.........#..#..
...#...#......#...##....#...#.#
..#...#.#.##.#.................
.....##......#..#.#....#.......
##.......#......#.#..#.#.......
.#.#.#.........#...#.#..#......
#...#.#........#....#.#.....#..
....#.......##....#......##....
.....#..........#......#....#..
#...#....#...#.....#.#.........
...#..##.....##....#.....#.#...
..................#.....##.....
.....#............#............
...#.....#..#........#.#..##...
.......#.#.....................
......#...#.......#..#...#..#..
.#..#...#.....##.....#.#.#....#
....##...#.#............#..#..#
...........#............#..#...
.......#.....#................#
..#......#.#.......#.#.........
.....#..#.#.##.................
.....#..#......................
...#....#...#..#.#..#....#.....
.#............#.....#..........
#.##..#..#.......#......#.....#
.#.........#....#....#.........
...#.#.#........#.#....#...#...
#........#..#..#..........#..#.
.....#..#.....##......##..##.#.
..............#.......#..#..#..
....#........#.##.#...#........
..#.#..#....#........##.....##.
...##.....#...#.......#.#....#.
#.....#..##.##.#...##.......#..
.....#........#.#.#....#.......
.#................#####..#.#...
..........##..#..###....#......
.....#.......#..........#..#...
..#....#....................#..
#.....#..#.....#...##.#.....#.#
...#..##............#.....#....
##.#..#.......##...............
........##...#.#.....#......#..
........#...#..................
#......#................#.#....
...........#...#..#.........#..
...#.##..#.##..................
.....#......###......#..#......
..#.#.....#...#..#.##........#.
....#..........#.#.....#.......
..#..........#..........#.#....
..#.##.......#......#..........

2
d03_output.txt

@ -0,0 +1,2 @@
225
1115775000

55
d04.py

@ -0,0 +1,55 @@
#!/usr/bin/env python3
from sys import argv
p = [{e.split(":")[0]: e.split(":")[1] for e in l.replace("\n", " ").split()} for l in open(argv[1]).read().split("\n\n")]
fi = ["byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid"]
ok = 0
ok2 = 0
for cp in p:
for cf in fi:
if cf not in cp:
break
else:
ok += 1
hgt_u = cp["hgt"][-2:]
try:
byr = int(cp["byr"])
iyr = int(cp["iyr"])
eyr = int(cp["eyr"])
hgt = int(cp["hgt"][:-2])
pid = int(cp["pid"])
except:
continue
if byr < 1920 or byr > 2002:
continue
if iyr < 2010 or iyr > 2020:
continue
if eyr < 2020 or eyr > 2030:
continue
if hgt_u == "cm":
if hgt < 150 or hgt > 193:
continue
elif hgt_u == "in":
if hgt < 59 or hgt > 76:
continue
else:
continue
if len(cp["hcl"]) != 7 or cp["hcl"][0] != '#':
continue
for c in cp["hcl"][1:]:
if c not in "0123456789abcdef":
continue
if cp["ecl"] not in ["amb","blu","brn","gry","grn","hzl","oth"]:
continue
if len(cp["pid"]) != 9:
continue
ok2 += 1
print(ok)
print(ok2)

1100
d04_input.txt

File diff suppressed because it is too large

2
d04_output.txt

@ -0,0 +1,2 @@
226
160
Loading…
Cancel
Save