first commit
This commit is contained in:
commit
6a4482d038
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.ropeproject
|
23
01/part1.py
Normal file
23
01/part1.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
|
||||||
|
def read_file(filename, chunk=1024):
|
||||||
|
file = open(filename, 'r')
|
||||||
|
while True:
|
||||||
|
line = file.read(chunk)
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
yield line
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
floor = 0
|
||||||
|
for line in read_file('input'):
|
||||||
|
up = line.count('(')
|
||||||
|
down = line.count(')')
|
||||||
|
floor = floor + up - down
|
||||||
|
|
||||||
|
print floor
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
27
01/part2.py
Normal file
27
01/part2.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
|
||||||
|
def read_file(filename, chunk=1024):
|
||||||
|
file = open(filename, 'r')
|
||||||
|
while True:
|
||||||
|
line = file.read(chunk)
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
yield line
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
floor = 0
|
||||||
|
pos = 1
|
||||||
|
for line in read_file('input', 1):
|
||||||
|
up = line.count('(')
|
||||||
|
down = line.count(')')
|
||||||
|
floor = floor + up - down
|
||||||
|
if floor == -1:
|
||||||
|
break
|
||||||
|
pos = pos + 1
|
||||||
|
|
||||||
|
print pos
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
30
02/part1.py
Normal file
30
02/part1.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
def read_file(filename):
|
||||||
|
file = open(filename, 'r')
|
||||||
|
while True:
|
||||||
|
line = file.readline()
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
yield line
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
|
||||||
|
size = 0
|
||||||
|
for line in read_file('input'):
|
||||||
|
match = re.match(r'(\d+)x(\d+)x(\d+)', line)
|
||||||
|
s1 = int(match.group(1))*int(match.group(2))
|
||||||
|
s2 = int(match.group(1))*int(match.group(3))
|
||||||
|
s3 = int(match.group(2))*int(match.group(3))
|
||||||
|
|
||||||
|
size = size + 2*s1 + 2*s2 + 2*s3 + min(s1, s2, s3)
|
||||||
|
|
||||||
|
print size
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
30
02/part2.py
Normal file
30
02/part2.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
def read_file(filename):
|
||||||
|
file = open(filename, 'r')
|
||||||
|
while True:
|
||||||
|
line = file.readline()
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
yield line
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
|
||||||
|
length = 0
|
||||||
|
for line in read_file('input'):
|
||||||
|
match = re.match(r'(\d+)x(\d+)x(\d+)', line)
|
||||||
|
l1 = int(match.group(1))
|
||||||
|
l2 = int(match.group(2))
|
||||||
|
l3 = int(match.group(3))
|
||||||
|
|
||||||
|
length= length + 2*min(l1+l2, l1+l3, l2+l3) + l1*l2*l3
|
||||||
|
|
||||||
|
print length
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
47
03/part1.py
Normal file
47
03/part1.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
|
||||||
|
def read_file(filename, chunk=1024):
|
||||||
|
file = open(filename, 'r')
|
||||||
|
while True:
|
||||||
|
line = file.read(chunk)
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
yield line
|
||||||
|
|
||||||
|
|
||||||
|
def getFloorPlanKey(posX, posY):
|
||||||
|
return "%dx%d" % (posX, posY)
|
||||||
|
|
||||||
|
|
||||||
|
def moveSanta(posX, posY, direction):
|
||||||
|
if direction == '>':
|
||||||
|
posX = posX + 1
|
||||||
|
if direction == '<':
|
||||||
|
posX = posX - 1
|
||||||
|
if direction == '^':
|
||||||
|
posY = posY + 1
|
||||||
|
if direction == 'v':
|
||||||
|
posY = posY - 1
|
||||||
|
return (posX, posY)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
posX = 0
|
||||||
|
posY = 0
|
||||||
|
houses = 1
|
||||||
|
floorPlan = dict()
|
||||||
|
floorPlan[getFloorPlanKey(0, 0)] = 1
|
||||||
|
|
||||||
|
for line in read_file('input', 1):
|
||||||
|
(posX, posY) = moveSanta(posX, posY, line[0])
|
||||||
|
key = getFloorPlanKey(posX, posY)
|
||||||
|
|
||||||
|
if key not in floorPlan:
|
||||||
|
houses = houses + 1
|
||||||
|
floorPlan[key] = 0
|
||||||
|
floorPlan[key] = floorPlan[key] + 1
|
||||||
|
print houses
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
61
03/part2.py
Normal file
61
03/part2.py
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
|
||||||
|
def read_file(filename, chunk=1024):
|
||||||
|
file = open(filename, 'r')
|
||||||
|
while True:
|
||||||
|
line = file.read(chunk)
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
yield line
|
||||||
|
|
||||||
|
|
||||||
|
def getFloorPlanKey(posX, posY):
|
||||||
|
return "%dx%d" % (posX, posY)
|
||||||
|
|
||||||
|
|
||||||
|
def moveSanta(posX, posY, direction):
|
||||||
|
if direction == '>':
|
||||||
|
posX = posX + 1
|
||||||
|
if direction == '<':
|
||||||
|
posX = posX - 1
|
||||||
|
if direction == '^':
|
||||||
|
posY = posY + 1
|
||||||
|
if direction == 'v':
|
||||||
|
posY = posY - 1
|
||||||
|
return (posX, posY)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
posX1 = 0
|
||||||
|
posY1 = 0
|
||||||
|
posX2 = 0
|
||||||
|
posY2 = 0
|
||||||
|
houses = 1
|
||||||
|
floorPlan = dict()
|
||||||
|
floorPlan[getFloorPlanKey(0, 0)] = 1
|
||||||
|
|
||||||
|
for line in read_file('input', 2):
|
||||||
|
|
||||||
|
(posX1, posY1) = moveSanta(posX1, posY1, line[0])
|
||||||
|
key1 = getFloorPlanKey(posX1, posY1)
|
||||||
|
if key1 not in floorPlan:
|
||||||
|
houses = houses + 1
|
||||||
|
floorPlan[key1] = 0
|
||||||
|
floorPlan[key1] = floorPlan[key1] + 1
|
||||||
|
|
||||||
|
if len(line) < 2:
|
||||||
|
break
|
||||||
|
|
||||||
|
(posX2, posY2) = moveSanta(posX2, posY2, line[1])
|
||||||
|
key2 = getFloorPlanKey(posX2, posY2)
|
||||||
|
|
||||||
|
if key2 not in floorPlan:
|
||||||
|
houses = houses + 1
|
||||||
|
floorPlan[key2] = 0
|
||||||
|
floorPlan[key2] = floorPlan[key2] + 1
|
||||||
|
|
||||||
|
print houses
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
23
04/part01.py
Normal file
23
04/part01.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import hashlib
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
number = 0
|
||||||
|
input = "yzbqklnj"
|
||||||
|
|
||||||
|
while True:
|
||||||
|
s = "%s%d" % (input, number)
|
||||||
|
m = hashlib.md5()
|
||||||
|
m.update(s)
|
||||||
|
h = m.hexdigest()
|
||||||
|
if re.match(r'^(0){5}', h):
|
||||||
|
print number
|
||||||
|
print h
|
||||||
|
break
|
||||||
|
number = number + 1
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
23
04/part02.py
Normal file
23
04/part02.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import hashlib
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
number = 0
|
||||||
|
input = "yzbqklnj"
|
||||||
|
|
||||||
|
while True:
|
||||||
|
s = "%s%d" % (input, number)
|
||||||
|
m = hashlib.md5()
|
||||||
|
m.update(s)
|
||||||
|
h = m.hexdigest()
|
||||||
|
if re.match(r'^(0){6}', h):
|
||||||
|
print number
|
||||||
|
print h
|
||||||
|
break
|
||||||
|
number = number + 1
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
5
05/input2
Normal file
5
05/input2
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
ugknbfddgicrmopn
|
||||||
|
aaa
|
||||||
|
jchzalrnumimnmhp
|
||||||
|
haegwjzuvuyypxyu
|
||||||
|
dvszwmarrgswjxmb
|
4
05/input3
Normal file
4
05/input3
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
qjhvhtzxzqqjkmpb
|
||||||
|
xxyxx
|
||||||
|
uurcxstgmygtbstg
|
||||||
|
ieodomkazucvgmuy
|
49
05/part1.py
Normal file
49
05/part1.py
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
def read_file(filename):
|
||||||
|
file = open(filename, 'r')
|
||||||
|
while True:
|
||||||
|
line = file.readline()
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
yield line
|
||||||
|
|
||||||
|
|
||||||
|
def count_vovels(line):
|
||||||
|
count = 0
|
||||||
|
for vovel in ['a', 'e', 'i', 'o', 'u']:
|
||||||
|
count = count + line.count(vovel)
|
||||||
|
return count
|
||||||
|
|
||||||
|
|
||||||
|
def count_bad(line):
|
||||||
|
count = 0
|
||||||
|
for vovel in ['ab', 'cd', 'pq', 'xy']:
|
||||||
|
count = count + line.count(vovel)
|
||||||
|
return count
|
||||||
|
|
||||||
|
def count_double(line):
|
||||||
|
regexp = re.compile(r"(.)\1")
|
||||||
|
match = re.search(regexp, line)
|
||||||
|
if match:
|
||||||
|
return 1
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def main():
|
||||||
|
nice = 0
|
||||||
|
for line in read_file('input'):
|
||||||
|
if count_vovels(line) < 3:
|
||||||
|
continue
|
||||||
|
if count_double(line) < 1:
|
||||||
|
continue
|
||||||
|
if count_bad(line) > 0:
|
||||||
|
continue
|
||||||
|
nice = nice + 1
|
||||||
|
|
||||||
|
print nice
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
43
05/part2.py
Normal file
43
05/part2.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
def read_file(filename):
|
||||||
|
file = open(filename, 'r')
|
||||||
|
while True:
|
||||||
|
line = file.readline()
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
yield line
|
||||||
|
|
||||||
|
|
||||||
|
def count_twice(line):
|
||||||
|
regexp = re.compile(r"(..).*\1")
|
||||||
|
match = re.search(regexp, line)
|
||||||
|
if match:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def count_repeat(line):
|
||||||
|
regexp = re.compile(r"(.).\1")
|
||||||
|
match = re.search(regexp, line)
|
||||||
|
if match:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
nice = 0
|
||||||
|
for line in read_file('input'):
|
||||||
|
if not count_twice(line):
|
||||||
|
continue
|
||||||
|
if not count_repeat(line):
|
||||||
|
continue
|
||||||
|
nice = nice + 1
|
||||||
|
|
||||||
|
print nice
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
300
06/input
Normal file
300
06/input
Normal file
@ -0,0 +1,300 @@
|
|||||||
|
turn on 887,9 through 959,629
|
||||||
|
turn on 454,398 through 844,448
|
||||||
|
turn off 539,243 through 559,965
|
||||||
|
turn off 370,819 through 676,868
|
||||||
|
turn off 145,40 through 370,997
|
||||||
|
turn off 301,3 through 808,453
|
||||||
|
turn on 351,678 through 951,908
|
||||||
|
toggle 720,196 through 897,994
|
||||||
|
toggle 831,394 through 904,860
|
||||||
|
toggle 753,664 through 970,926
|
||||||
|
turn off 150,300 through 213,740
|
||||||
|
turn on 141,242 through 932,871
|
||||||
|
toggle 294,259 through 474,326
|
||||||
|
toggle 678,333 through 752,957
|
||||||
|
toggle 393,804 through 510,976
|
||||||
|
turn off 6,964 through 411,976
|
||||||
|
turn off 33,572 through 978,590
|
||||||
|
turn on 579,693 through 650,978
|
||||||
|
turn on 150,20 through 652,719
|
||||||
|
turn off 782,143 through 808,802
|
||||||
|
turn off 240,377 through 761,468
|
||||||
|
turn off 899,828 through 958,967
|
||||||
|
turn on 613,565 through 952,659
|
||||||
|
turn on 295,36 through 964,978
|
||||||
|
toggle 846,296 through 969,528
|
||||||
|
turn off 211,254 through 529,491
|
||||||
|
turn off 231,594 through 406,794
|
||||||
|
turn off 169,791 through 758,942
|
||||||
|
turn on 955,440 through 980,477
|
||||||
|
toggle 944,498 through 995,928
|
||||||
|
turn on 519,391 through 605,718
|
||||||
|
toggle 521,303 through 617,366
|
||||||
|
turn off 524,349 through 694,791
|
||||||
|
toggle 391,87 through 499,792
|
||||||
|
toggle 562,527 through 668,935
|
||||||
|
turn off 68,358 through 857,453
|
||||||
|
toggle 815,811 through 889,828
|
||||||
|
turn off 666,61 through 768,87
|
||||||
|
turn on 27,501 through 921,952
|
||||||
|
turn on 953,102 through 983,471
|
||||||
|
turn on 277,552 through 451,723
|
||||||
|
turn off 64,253 through 655,960
|
||||||
|
turn on 47,485 through 734,977
|
||||||
|
turn off 59,119 through 699,734
|
||||||
|
toggle 407,898 through 493,955
|
||||||
|
toggle 912,966 through 949,991
|
||||||
|
turn on 479,990 through 895,990
|
||||||
|
toggle 390,589 through 869,766
|
||||||
|
toggle 593,903 through 926,943
|
||||||
|
toggle 358,439 through 870,528
|
||||||
|
turn off 649,410 through 652,875
|
||||||
|
turn on 629,834 through 712,895
|
||||||
|
toggle 254,555 through 770,901
|
||||||
|
toggle 641,832 through 947,850
|
||||||
|
turn on 268,448 through 743,777
|
||||||
|
turn off 512,123 through 625,874
|
||||||
|
turn off 498,262 through 930,811
|
||||||
|
turn off 835,158 through 886,242
|
||||||
|
toggle 546,310 through 607,773
|
||||||
|
turn on 501,505 through 896,909
|
||||||
|
turn off 666,796 through 817,924
|
||||||
|
toggle 987,789 through 993,809
|
||||||
|
toggle 745,8 through 860,693
|
||||||
|
toggle 181,983 through 731,988
|
||||||
|
turn on 826,174 through 924,883
|
||||||
|
turn on 239,228 through 843,993
|
||||||
|
turn on 205,613 through 891,667
|
||||||
|
toggle 867,873 through 984,896
|
||||||
|
turn on 628,251 through 677,681
|
||||||
|
toggle 276,956 through 631,964
|
||||||
|
turn on 78,358 through 974,713
|
||||||
|
turn on 521,360 through 773,597
|
||||||
|
turn off 963,52 through 979,502
|
||||||
|
turn on 117,151 through 934,622
|
||||||
|
toggle 237,91 through 528,164
|
||||||
|
turn on 944,269 through 975,453
|
||||||
|
toggle 979,460 through 988,964
|
||||||
|
turn off 440,254 through 681,507
|
||||||
|
toggle 347,100 through 896,785
|
||||||
|
turn off 329,592 through 369,985
|
||||||
|
turn on 931,960 through 979,985
|
||||||
|
toggle 703,3 through 776,36
|
||||||
|
toggle 798,120 through 908,550
|
||||||
|
turn off 186,605 through 914,709
|
||||||
|
turn off 921,725 through 979,956
|
||||||
|
toggle 167,34 through 735,249
|
||||||
|
turn on 726,781 through 987,936
|
||||||
|
toggle 720,336 through 847,756
|
||||||
|
turn on 171,630 through 656,769
|
||||||
|
turn off 417,276 through 751,500
|
||||||
|
toggle 559,485 through 584,534
|
||||||
|
turn on 568,629 through 690,873
|
||||||
|
toggle 248,712 through 277,988
|
||||||
|
toggle 345,594 through 812,723
|
||||||
|
turn off 800,108 through 834,618
|
||||||
|
turn off 967,439 through 986,869
|
||||||
|
turn on 842,209 through 955,529
|
||||||
|
turn on 132,653 through 357,696
|
||||||
|
turn on 817,38 through 973,662
|
||||||
|
turn off 569,816 through 721,861
|
||||||
|
turn on 568,429 through 945,724
|
||||||
|
turn on 77,458 through 844,685
|
||||||
|
turn off 138,78 through 498,851
|
||||||
|
turn on 136,21 through 252,986
|
||||||
|
turn off 2,460 through 863,472
|
||||||
|
turn on 172,81 through 839,332
|
||||||
|
turn on 123,216 through 703,384
|
||||||
|
turn off 879,644 through 944,887
|
||||||
|
toggle 227,491 through 504,793
|
||||||
|
toggle 580,418 through 741,479
|
||||||
|
toggle 65,276 through 414,299
|
||||||
|
toggle 482,486 through 838,931
|
||||||
|
turn off 557,768 through 950,927
|
||||||
|
turn off 615,617 through 955,864
|
||||||
|
turn on 859,886 through 923,919
|
||||||
|
turn on 391,330 through 499,971
|
||||||
|
toggle 521,835 through 613,847
|
||||||
|
turn on 822,787 through 989,847
|
||||||
|
turn on 192,142 through 357,846
|
||||||
|
turn off 564,945 through 985,945
|
||||||
|
turn off 479,361 through 703,799
|
||||||
|
toggle 56,481 through 489,978
|
||||||
|
turn off 632,991 through 774,998
|
||||||
|
toggle 723,526 through 945,792
|
||||||
|
turn on 344,149 through 441,640
|
||||||
|
toggle 568,927 through 624,952
|
||||||
|
turn on 621,784 through 970,788
|
||||||
|
toggle 665,783 through 795,981
|
||||||
|
toggle 386,610 through 817,730
|
||||||
|
toggle 440,399 through 734,417
|
||||||
|
toggle 939,201 through 978,803
|
||||||
|
turn off 395,883 through 554,929
|
||||||
|
turn on 340,309 through 637,561
|
||||||
|
turn off 875,147 through 946,481
|
||||||
|
turn off 945,837 through 957,922
|
||||||
|
turn off 429,982 through 691,991
|
||||||
|
toggle 227,137 through 439,822
|
||||||
|
toggle 4,848 through 7,932
|
||||||
|
turn off 545,146 through 756,943
|
||||||
|
turn on 763,863 through 937,994
|
||||||
|
turn on 232,94 through 404,502
|
||||||
|
turn off 742,254 through 930,512
|
||||||
|
turn on 91,931 through 101,942
|
||||||
|
toggle 585,106 through 651,425
|
||||||
|
turn on 506,700 through 567,960
|
||||||
|
turn off 548,44 through 718,352
|
||||||
|
turn off 194,827 through 673,859
|
||||||
|
turn off 6,645 through 509,764
|
||||||
|
turn off 13,230 through 821,361
|
||||||
|
turn on 734,629 through 919,631
|
||||||
|
toggle 788,552 through 957,972
|
||||||
|
toggle 244,747 through 849,773
|
||||||
|
turn off 162,553 through 276,887
|
||||||
|
turn off 569,577 through 587,604
|
||||||
|
turn off 799,482 through 854,956
|
||||||
|
turn on 744,535 through 909,802
|
||||||
|
toggle 330,641 through 396,986
|
||||||
|
turn off 927,458 through 966,564
|
||||||
|
toggle 984,486 through 986,913
|
||||||
|
toggle 519,682 through 632,708
|
||||||
|
turn on 984,977 through 989,986
|
||||||
|
toggle 766,423 through 934,495
|
||||||
|
turn on 17,509 through 947,718
|
||||||
|
turn on 413,783 through 631,903
|
||||||
|
turn on 482,370 through 493,688
|
||||||
|
turn on 433,859 through 628,938
|
||||||
|
turn off 769,549 through 945,810
|
||||||
|
turn on 178,853 through 539,941
|
||||||
|
turn off 203,251 through 692,433
|
||||||
|
turn off 525,638 through 955,794
|
||||||
|
turn on 169,70 through 764,939
|
||||||
|
toggle 59,352 through 896,404
|
||||||
|
toggle 143,245 through 707,320
|
||||||
|
turn off 103,35 through 160,949
|
||||||
|
toggle 496,24 through 669,507
|
||||||
|
turn off 581,847 through 847,903
|
||||||
|
turn on 689,153 through 733,562
|
||||||
|
turn on 821,487 through 839,699
|
||||||
|
turn on 837,627 through 978,723
|
||||||
|
toggle 96,748 through 973,753
|
||||||
|
toggle 99,818 through 609,995
|
||||||
|
turn on 731,193 through 756,509
|
||||||
|
turn off 622,55 through 813,365
|
||||||
|
turn on 456,490 through 576,548
|
||||||
|
turn on 48,421 through 163,674
|
||||||
|
turn off 853,861 through 924,964
|
||||||
|
turn off 59,963 through 556,987
|
||||||
|
turn on 458,710 through 688,847
|
||||||
|
toggle 12,484 through 878,562
|
||||||
|
turn off 241,964 through 799,983
|
||||||
|
turn off 434,299 through 845,772
|
||||||
|
toggle 896,725 through 956,847
|
||||||
|
turn on 740,289 through 784,345
|
||||||
|
turn off 395,840 through 822,845
|
||||||
|
turn on 955,224 through 996,953
|
||||||
|
turn off 710,186 through 957,722
|
||||||
|
turn off 485,949 through 869,985
|
||||||
|
turn on 848,209 through 975,376
|
||||||
|
toggle 221,241 through 906,384
|
||||||
|
turn on 588,49 through 927,496
|
||||||
|
turn on 273,332 through 735,725
|
||||||
|
turn on 505,962 through 895,962
|
||||||
|
toggle 820,112 through 923,143
|
||||||
|
turn on 919,792 through 978,982
|
||||||
|
toggle 489,461 through 910,737
|
||||||
|
turn off 202,642 through 638,940
|
||||||
|
turn off 708,953 through 970,960
|
||||||
|
toggle 437,291 through 546,381
|
||||||
|
turn on 409,358 through 837,479
|
||||||
|
turn off 756,279 through 870,943
|
||||||
|
turn off 154,657 through 375,703
|
||||||
|
turn off 524,622 through 995,779
|
||||||
|
toggle 514,221 through 651,850
|
||||||
|
toggle 808,464 through 886,646
|
||||||
|
toggle 483,537 through 739,840
|
||||||
|
toggle 654,769 through 831,825
|
||||||
|
turn off 326,37 through 631,69
|
||||||
|
turn off 590,570 through 926,656
|
||||||
|
turn off 881,913 through 911,998
|
||||||
|
turn on 996,102 through 998,616
|
||||||
|
turn off 677,503 through 828,563
|
||||||
|
turn on 860,251 through 877,441
|
||||||
|
turn off 964,100 through 982,377
|
||||||
|
toggle 888,403 through 961,597
|
||||||
|
turn off 632,240 through 938,968
|
||||||
|
toggle 731,176 through 932,413
|
||||||
|
turn on 5,498 through 203,835
|
||||||
|
turn on 819,352 through 929,855
|
||||||
|
toggle 393,813 through 832,816
|
||||||
|
toggle 725,689 through 967,888
|
||||||
|
turn on 968,950 through 969,983
|
||||||
|
turn off 152,628 through 582,896
|
||||||
|
turn off 165,844 through 459,935
|
||||||
|
turn off 882,741 through 974,786
|
||||||
|
turn off 283,179 through 731,899
|
||||||
|
toggle 197,366 through 682,445
|
||||||
|
turn on 106,309 through 120,813
|
||||||
|
toggle 950,387 through 967,782
|
||||||
|
turn off 274,603 through 383,759
|
||||||
|
turn off 155,665 through 284,787
|
||||||
|
toggle 551,871 through 860,962
|
||||||
|
turn off 30,826 through 598,892
|
||||||
|
toggle 76,552 through 977,888
|
||||||
|
turn on 938,180 through 994,997
|
||||||
|
toggle 62,381 through 993,656
|
||||||
|
toggle 625,861 through 921,941
|
||||||
|
turn on 685,311 through 872,521
|
||||||
|
turn on 124,934 through 530,962
|
||||||
|
turn on 606,379 through 961,867
|
||||||
|
turn off 792,735 through 946,783
|
||||||
|
turn on 417,480 through 860,598
|
||||||
|
toggle 178,91 through 481,887
|
||||||
|
turn off 23,935 through 833,962
|
||||||
|
toggle 317,14 through 793,425
|
||||||
|
turn on 986,89 through 999,613
|
||||||
|
turn off 359,201 through 560,554
|
||||||
|
turn off 729,494 through 942,626
|
||||||
|
turn on 204,143 through 876,610
|
||||||
|
toggle 474,97 through 636,542
|
||||||
|
turn off 902,924 through 976,973
|
||||||
|
turn off 389,442 through 824,638
|
||||||
|
turn off 622,863 through 798,863
|
||||||
|
turn on 840,622 through 978,920
|
||||||
|
toggle 567,374 through 925,439
|
||||||
|
turn off 643,319 through 935,662
|
||||||
|
toggle 185,42 through 294,810
|
||||||
|
turn on 47,124 through 598,880
|
||||||
|
toggle 828,303 through 979,770
|
||||||
|
turn off 174,272 through 280,311
|
||||||
|
turn off 540,50 through 880,212
|
||||||
|
turn on 141,994 through 221,998
|
||||||
|
turn on 476,695 through 483,901
|
||||||
|
turn on 960,216 through 972,502
|
||||||
|
toggle 752,335 through 957,733
|
||||||
|
turn off 419,713 through 537,998
|
||||||
|
toggle 772,846 through 994,888
|
||||||
|
turn on 881,159 through 902,312
|
||||||
|
turn off 537,651 through 641,816
|
||||||
|
toggle 561,947 through 638,965
|
||||||
|
turn on 368,458 through 437,612
|
||||||
|
turn on 290,149 through 705,919
|
||||||
|
turn on 711,918 through 974,945
|
||||||
|
toggle 916,242 through 926,786
|
||||||
|
toggle 522,272 through 773,314
|
||||||
|
turn on 432,897 through 440,954
|
||||||
|
turn off 132,169 through 775,380
|
||||||
|
toggle 52,205 through 693,747
|
||||||
|
toggle 926,309 through 976,669
|
||||||
|
turn off 838,342 through 938,444
|
||||||
|
turn on 144,431 through 260,951
|
||||||
|
toggle 780,318 through 975,495
|
||||||
|
turn off 185,412 through 796,541
|
||||||
|
turn on 879,548 through 892,860
|
||||||
|
turn on 294,132 through 460,338
|
||||||
|
turn on 823,500 through 899,529
|
||||||
|
turn off 225,603 through 483,920
|
||||||
|
toggle 717,493 through 930,875
|
||||||
|
toggle 534,948 through 599,968
|
||||||
|
turn on 522,730 through 968,950
|
||||||
|
turn off 102,229 through 674,529
|
88
06/part1.py
Normal file
88
06/part1.py
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
def read_file(filename):
|
||||||
|
file = open(filename, 'r')
|
||||||
|
while True:
|
||||||
|
line = file.readline()
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
yield line
|
||||||
|
|
||||||
|
|
||||||
|
def getPosKey(posX, posY):
|
||||||
|
return "%03d%03d" % (posX, posY)
|
||||||
|
|
||||||
|
|
||||||
|
def action_turn_on(data, posX1, posY1, posX2, posY2):
|
||||||
|
changed = 0
|
||||||
|
for posX in range(posX1, posX2+1):
|
||||||
|
for posY in range(posY1, posY2+1):
|
||||||
|
key = getPosKey(posX, posY)
|
||||||
|
if key not in data:
|
||||||
|
data[key] = False
|
||||||
|
if not data[key]:
|
||||||
|
data[key] = True
|
||||||
|
changed = changed + 1
|
||||||
|
return (data, changed, 0)
|
||||||
|
|
||||||
|
|
||||||
|
def action_turn_off(data, posX1, posY1, posX2, posY2):
|
||||||
|
changed = 0
|
||||||
|
for posX in range(posX1, posX2+1):
|
||||||
|
for posY in range(posY1, posY2+1):
|
||||||
|
key = getPosKey(posX, posY)
|
||||||
|
if key not in data:
|
||||||
|
data[key] = False
|
||||||
|
if data[key]:
|
||||||
|
data[key] = False
|
||||||
|
changed = changed + 1
|
||||||
|
return (data, 0, changed)
|
||||||
|
|
||||||
|
|
||||||
|
def action_toggle(data, posX1, posY1, posX2, posY2):
|
||||||
|
changedOn = 0
|
||||||
|
changedOff = 0
|
||||||
|
|
||||||
|
for posX in range(posX1, posX2+1):
|
||||||
|
for posY in range(posY1, posY2+1):
|
||||||
|
key = getPosKey(posX, posY)
|
||||||
|
if key not in data:
|
||||||
|
data[key] = False
|
||||||
|
if not data[key]:
|
||||||
|
data[key] = True
|
||||||
|
changedOn = changedOn + 1
|
||||||
|
else:
|
||||||
|
data[key] = False
|
||||||
|
changedOff = changedOff + 1
|
||||||
|
|
||||||
|
return (data, changedOn, changedOff)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
RE_COORD = re.compile(r" (\d+),(\d+) through (\d+),(\d+)$")
|
||||||
|
lOn = 0
|
||||||
|
grid = dict()
|
||||||
|
for line in read_file('input'):
|
||||||
|
match = re.search(RE_COORD, line)
|
||||||
|
posX1 = (int)(match.group(1))
|
||||||
|
posY1 = (int)(match.group(2))
|
||||||
|
posX2 = (int)(match.group(3))
|
||||||
|
posY2 = (int)(match.group(4))
|
||||||
|
changedOn = 0
|
||||||
|
changedOff = 0
|
||||||
|
if line.startswith("turn on "):
|
||||||
|
(grid, changedOn, changedOff) = action_turn_on(grid, posX1, posY1, posX2, posY2)
|
||||||
|
if line.startswith("turn off "):
|
||||||
|
(grid, changedOn, changedOff) = action_turn_off(grid, posX1, posY1, posX2, posY2)
|
||||||
|
if line.startswith("toggle "):
|
||||||
|
(grid, changedOn, changedOff) = action_toggle(grid, posX1, posY1, posX2, posY2)
|
||||||
|
lOn = lOn + changedOn - changedOff
|
||||||
|
|
||||||
|
print lOn
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
69
06/part2.py
Normal file
69
06/part2.py
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
def read_file(filename):
|
||||||
|
file = open(filename, 'r')
|
||||||
|
while True:
|
||||||
|
line = file.readline()
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
yield line
|
||||||
|
|
||||||
|
|
||||||
|
def getPosKey(posX, posY):
|
||||||
|
return "%03d%03d" % (posX, posY)
|
||||||
|
|
||||||
|
|
||||||
|
def action_turn_on(data, posX1, posY1, posX2, posY2):
|
||||||
|
changed = 0
|
||||||
|
for posX in range(posX1, posX2+1):
|
||||||
|
for posY in range(posY1, posY2+1):
|
||||||
|
key = getPosKey(posX, posY)
|
||||||
|
if key not in data:
|
||||||
|
data[key] = 0
|
||||||
|
data[key] = data[key] + 1
|
||||||
|
changed = changed + 1
|
||||||
|
return (data, changed, 0)
|
||||||
|
|
||||||
|
|
||||||
|
def action_turn_off(data, posX1, posY1, posX2, posY2):
|
||||||
|
changed = 0
|
||||||
|
for posX in range(posX1, posX2+1):
|
||||||
|
for posY in range(posY1, posY2+1):
|
||||||
|
key = getPosKey(posX, posY)
|
||||||
|
if key not in data:
|
||||||
|
data[key] = 0
|
||||||
|
if data[key] > 0:
|
||||||
|
data[key] = data[key] - 1
|
||||||
|
changed = changed + 1
|
||||||
|
return (data, 0, changed)
|
||||||
|
|
||||||
|
def main():
|
||||||
|
RE_COORD = re.compile(r" (\d+),(\d+) through (\d+),(\d+)$")
|
||||||
|
lOn = 0
|
||||||
|
grid = dict()
|
||||||
|
for line in read_file('input'):
|
||||||
|
match = re.search(RE_COORD, line)
|
||||||
|
posX1 = (int)(match.group(1))
|
||||||
|
posY1 = (int)(match.group(2))
|
||||||
|
posX2 = (int)(match.group(3))
|
||||||
|
posY2 = (int)(match.group(4))
|
||||||
|
changedOn = 0
|
||||||
|
changedOff = 0
|
||||||
|
if line.startswith("turn on "):
|
||||||
|
(grid, changedOn, changedOff) = action_turn_on(grid, posX1, posY1, posX2, posY2)
|
||||||
|
if line.startswith("turn off "):
|
||||||
|
(grid, changedOn, changedOff) = action_turn_off(grid, posX1, posY1, posX2, posY2)
|
||||||
|
if line.startswith("toggle "):
|
||||||
|
(grid, changedOn, changedOff) = action_turn_on(grid, posX1, posY1, posX2, posY2)
|
||||||
|
(grid, changedOn, changedOff) = action_turn_on(grid, posX1, posY1, posX2, posY2)
|
||||||
|
changedOn = changedOn * 2
|
||||||
|
changedOff = changedOff * 2
|
||||||
|
lOn = lOn + changedOn - changedOff
|
||||||
|
|
||||||
|
print lOn
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
339
07/input
Normal file
339
07/input
Normal file
@ -0,0 +1,339 @@
|
|||||||
|
NOT dq -> dr
|
||||||
|
kg OR kf -> kh
|
||||||
|
ep OR eo -> eq
|
||||||
|
44430 -> b
|
||||||
|
NOT gs -> gt
|
||||||
|
dd OR do -> dp
|
||||||
|
eg AND ei -> ej
|
||||||
|
y AND ae -> ag
|
||||||
|
jx AND jz -> ka
|
||||||
|
lf RSHIFT 2 -> lg
|
||||||
|
z AND aa -> ac
|
||||||
|
dy AND ej -> el
|
||||||
|
bj OR bi -> bk
|
||||||
|
kk RSHIFT 3 -> km
|
||||||
|
NOT cn -> co
|
||||||
|
gn AND gp -> gq
|
||||||
|
cq AND cs -> ct
|
||||||
|
eo LSHIFT 15 -> es
|
||||||
|
lg OR lm -> ln
|
||||||
|
dy OR ej -> ek
|
||||||
|
NOT di -> dj
|
||||||
|
1 AND fi -> fj
|
||||||
|
kf LSHIFT 15 -> kj
|
||||||
|
NOT jy -> jz
|
||||||
|
NOT ft -> fu
|
||||||
|
fs AND fu -> fv
|
||||||
|
NOT hr -> hs
|
||||||
|
ck OR cl -> cm
|
||||||
|
jp RSHIFT 5 -> js
|
||||||
|
iv OR jb -> jc
|
||||||
|
is OR it -> iu
|
||||||
|
ld OR le -> lf
|
||||||
|
NOT fc -> fd
|
||||||
|
NOT dm -> dn
|
||||||
|
bn OR by -> bz
|
||||||
|
aj AND al -> am
|
||||||
|
cd LSHIFT 15 -> ch
|
||||||
|
jp AND ka -> kc
|
||||||
|
ci OR ct -> cu
|
||||||
|
gv AND gx -> gy
|
||||||
|
de AND dk -> dm
|
||||||
|
x RSHIFT 5 -> aa
|
||||||
|
et RSHIFT 2 -> eu
|
||||||
|
x RSHIFT 1 -> aq
|
||||||
|
ia OR ig -> ih
|
||||||
|
bk LSHIFT 1 -> ce
|
||||||
|
y OR ae -> af
|
||||||
|
NOT ca -> cb
|
||||||
|
e AND f -> h
|
||||||
|
ia AND ig -> ii
|
||||||
|
ck AND cl -> cn
|
||||||
|
NOT jh -> ji
|
||||||
|
z OR aa -> ab
|
||||||
|
1 AND en -> eo
|
||||||
|
ib AND ic -> ie
|
||||||
|
NOT eh -> ei
|
||||||
|
iy AND ja -> jb
|
||||||
|
NOT bb -> bc
|
||||||
|
ha OR gz -> hb
|
||||||
|
1 AND cx -> cy
|
||||||
|
NOT ax -> ay
|
||||||
|
ev OR ew -> ex
|
||||||
|
bn RSHIFT 2 -> bo
|
||||||
|
er OR es -> et
|
||||||
|
eu OR fa -> fb
|
||||||
|
jp OR ka -> kb
|
||||||
|
ea AND eb -> ed
|
||||||
|
k AND m -> n
|
||||||
|
et RSHIFT 3 -> ev
|
||||||
|
et RSHIFT 5 -> ew
|
||||||
|
hz RSHIFT 1 -> is
|
||||||
|
ki OR kj -> kk
|
||||||
|
NOT h -> i
|
||||||
|
lv LSHIFT 15 -> lz
|
||||||
|
as RSHIFT 1 -> bl
|
||||||
|
hu LSHIFT 15 -> hy
|
||||||
|
iw AND ix -> iz
|
||||||
|
lf RSHIFT 1 -> ly
|
||||||
|
fp OR fv -> fw
|
||||||
|
1 AND am -> an
|
||||||
|
ap LSHIFT 1 -> bj
|
||||||
|
u LSHIFT 1 -> ao
|
||||||
|
b RSHIFT 5 -> f
|
||||||
|
jq AND jw -> jy
|
||||||
|
iu RSHIFT 3 -> iw
|
||||||
|
ih AND ij -> ik
|
||||||
|
NOT iz -> ja
|
||||||
|
de OR dk -> dl
|
||||||
|
iu OR jf -> jg
|
||||||
|
as AND bd -> bf
|
||||||
|
b RSHIFT 3 -> e
|
||||||
|
jq OR jw -> jx
|
||||||
|
iv AND jb -> jd
|
||||||
|
cg OR ch -> ci
|
||||||
|
iu AND jf -> jh
|
||||||
|
lx -> a
|
||||||
|
1 AND cc -> cd
|
||||||
|
ly OR lz -> ma
|
||||||
|
NOT el -> em
|
||||||
|
1 AND bh -> bi
|
||||||
|
fb AND fd -> fe
|
||||||
|
lf OR lq -> lr
|
||||||
|
bn RSHIFT 3 -> bp
|
||||||
|
bn AND by -> ca
|
||||||
|
af AND ah -> ai
|
||||||
|
cf LSHIFT 1 -> cz
|
||||||
|
dw OR dx -> dy
|
||||||
|
gj AND gu -> gw
|
||||||
|
jg AND ji -> jj
|
||||||
|
jr OR js -> jt
|
||||||
|
bl OR bm -> bn
|
||||||
|
gj RSHIFT 2 -> gk
|
||||||
|
cj OR cp -> cq
|
||||||
|
gj OR gu -> gv
|
||||||
|
b OR n -> o
|
||||||
|
o AND q -> r
|
||||||
|
bi LSHIFT 15 -> bm
|
||||||
|
dy RSHIFT 1 -> er
|
||||||
|
cu AND cw -> cx
|
||||||
|
iw OR ix -> iy
|
||||||
|
hc OR hd -> he
|
||||||
|
0 -> c
|
||||||
|
db OR dc -> dd
|
||||||
|
kk RSHIFT 2 -> kl
|
||||||
|
eq LSHIFT 1 -> fk
|
||||||
|
dz OR ef -> eg
|
||||||
|
NOT ed -> ee
|
||||||
|
lw OR lv -> lx
|
||||||
|
fw AND fy -> fz
|
||||||
|
dz AND ef -> eh
|
||||||
|
jp RSHIFT 3 -> jr
|
||||||
|
lg AND lm -> lo
|
||||||
|
ci RSHIFT 2 -> cj
|
||||||
|
be AND bg -> bh
|
||||||
|
lc LSHIFT 1 -> lw
|
||||||
|
hm AND ho -> hp
|
||||||
|
jr AND js -> ju
|
||||||
|
1 AND io -> ip
|
||||||
|
cm AND co -> cp
|
||||||
|
ib OR ic -> id
|
||||||
|
NOT bf -> bg
|
||||||
|
fo RSHIFT 5 -> fr
|
||||||
|
ip LSHIFT 15 -> it
|
||||||
|
jt AND jv -> jw
|
||||||
|
jc AND je -> jf
|
||||||
|
du OR dt -> dv
|
||||||
|
NOT fx -> fy
|
||||||
|
aw AND ay -> az
|
||||||
|
ge LSHIFT 15 -> gi
|
||||||
|
NOT ak -> al
|
||||||
|
fm OR fn -> fo
|
||||||
|
ff AND fh -> fi
|
||||||
|
ci RSHIFT 5 -> cl
|
||||||
|
cz OR cy -> da
|
||||||
|
NOT ey -> ez
|
||||||
|
NOT ju -> jv
|
||||||
|
NOT ls -> lt
|
||||||
|
kk AND kv -> kx
|
||||||
|
NOT ii -> ij
|
||||||
|
kl AND kr -> kt
|
||||||
|
jk LSHIFT 15 -> jo
|
||||||
|
e OR f -> g
|
||||||
|
NOT bs -> bt
|
||||||
|
hi AND hk -> hl
|
||||||
|
hz OR ik -> il
|
||||||
|
ek AND em -> en
|
||||||
|
ao OR an -> ap
|
||||||
|
dv LSHIFT 1 -> ep
|
||||||
|
an LSHIFT 15 -> ar
|
||||||
|
fo RSHIFT 1 -> gh
|
||||||
|
NOT im -> in
|
||||||
|
kk RSHIFT 1 -> ld
|
||||||
|
hw LSHIFT 1 -> iq
|
||||||
|
ec AND ee -> ef
|
||||||
|
hb LSHIFT 1 -> hv
|
||||||
|
kb AND kd -> ke
|
||||||
|
x AND ai -> ak
|
||||||
|
dd AND do -> dq
|
||||||
|
aq OR ar -> as
|
||||||
|
iq OR ip -> ir
|
||||||
|
dl AND dn -> do
|
||||||
|
iu RSHIFT 5 -> ix
|
||||||
|
as OR bd -> be
|
||||||
|
NOT go -> gp
|
||||||
|
fk OR fj -> fl
|
||||||
|
jm LSHIFT 1 -> kg
|
||||||
|
NOT cv -> cw
|
||||||
|
dp AND dr -> ds
|
||||||
|
dt LSHIFT 15 -> dx
|
||||||
|
et RSHIFT 1 -> fm
|
||||||
|
dy RSHIFT 3 -> ea
|
||||||
|
fp AND fv -> fx
|
||||||
|
NOT p -> q
|
||||||
|
dd RSHIFT 2 -> de
|
||||||
|
eu AND fa -> fc
|
||||||
|
ba AND bc -> bd
|
||||||
|
dh AND dj -> dk
|
||||||
|
lr AND lt -> lu
|
||||||
|
he RSHIFT 1 -> hx
|
||||||
|
ex AND ez -> fa
|
||||||
|
df OR dg -> dh
|
||||||
|
fj LSHIFT 15 -> fn
|
||||||
|
NOT kx -> ky
|
||||||
|
gk OR gq -> gr
|
||||||
|
dy RSHIFT 2 -> dz
|
||||||
|
gh OR gi -> gj
|
||||||
|
lj AND ll -> lm
|
||||||
|
x OR ai -> aj
|
||||||
|
bz AND cb -> cc
|
||||||
|
1 AND lu -> lv
|
||||||
|
as RSHIFT 3 -> au
|
||||||
|
ce OR cd -> cf
|
||||||
|
il AND in -> io
|
||||||
|
dd RSHIFT 1 -> dw
|
||||||
|
NOT lo -> lp
|
||||||
|
c LSHIFT 1 -> t
|
||||||
|
dd RSHIFT 3 -> df
|
||||||
|
dd RSHIFT 5 -> dg
|
||||||
|
lh AND li -> lk
|
||||||
|
lf RSHIFT 5 -> li
|
||||||
|
dy RSHIFT 5 -> eb
|
||||||
|
NOT kt -> ku
|
||||||
|
at OR az -> ba
|
||||||
|
x RSHIFT 3 -> z
|
||||||
|
NOT lk -> ll
|
||||||
|
lb OR la -> lc
|
||||||
|
1 AND r -> s
|
||||||
|
lh OR li -> lj
|
||||||
|
ln AND lp -> lq
|
||||||
|
kk RSHIFT 5 -> kn
|
||||||
|
ea OR eb -> ec
|
||||||
|
ci AND ct -> cv
|
||||||
|
b RSHIFT 2 -> d
|
||||||
|
jp RSHIFT 1 -> ki
|
||||||
|
NOT cr -> cs
|
||||||
|
NOT jd -> je
|
||||||
|
jp RSHIFT 2 -> jq
|
||||||
|
jn OR jo -> jp
|
||||||
|
lf RSHIFT 3 -> lh
|
||||||
|
1 AND ds -> dt
|
||||||
|
lf AND lq -> ls
|
||||||
|
la LSHIFT 15 -> le
|
||||||
|
NOT fg -> fh
|
||||||
|
at AND az -> bb
|
||||||
|
au AND av -> ax
|
||||||
|
kw AND ky -> kz
|
||||||
|
v OR w -> x
|
||||||
|
kk OR kv -> kw
|
||||||
|
ks AND ku -> kv
|
||||||
|
kh LSHIFT 1 -> lb
|
||||||
|
1 AND kz -> la
|
||||||
|
NOT kc -> kd
|
||||||
|
x RSHIFT 2 -> y
|
||||||
|
et OR fe -> ff
|
||||||
|
et AND fe -> fg
|
||||||
|
NOT ac -> ad
|
||||||
|
jl OR jk -> jm
|
||||||
|
1 AND jj -> jk
|
||||||
|
bn RSHIFT 1 -> cg
|
||||||
|
NOT kp -> kq
|
||||||
|
ci RSHIFT 3 -> ck
|
||||||
|
ev AND ew -> ey
|
||||||
|
1 AND ke -> kf
|
||||||
|
cj AND cp -> cr
|
||||||
|
ir LSHIFT 1 -> jl
|
||||||
|
NOT gw -> gx
|
||||||
|
as RSHIFT 2 -> at
|
||||||
|
iu RSHIFT 1 -> jn
|
||||||
|
cy LSHIFT 15 -> dc
|
||||||
|
hg OR hh -> hi
|
||||||
|
ci RSHIFT 1 -> db
|
||||||
|
au OR av -> aw
|
||||||
|
km AND kn -> kp
|
||||||
|
gj RSHIFT 1 -> hc
|
||||||
|
iu RSHIFT 2 -> iv
|
||||||
|
ab AND ad -> ae
|
||||||
|
da LSHIFT 1 -> du
|
||||||
|
NOT bw -> bx
|
||||||
|
km OR kn -> ko
|
||||||
|
ko AND kq -> kr
|
||||||
|
bv AND bx -> by
|
||||||
|
kl OR kr -> ks
|
||||||
|
1 AND ht -> hu
|
||||||
|
df AND dg -> di
|
||||||
|
NOT ag -> ah
|
||||||
|
d OR j -> k
|
||||||
|
d AND j -> l
|
||||||
|
b AND n -> p
|
||||||
|
gf OR ge -> gg
|
||||||
|
gg LSHIFT 1 -> ha
|
||||||
|
bn RSHIFT 5 -> bq
|
||||||
|
bo OR bu -> bv
|
||||||
|
1 AND gy -> gz
|
||||||
|
s LSHIFT 15 -> w
|
||||||
|
NOT ie -> if
|
||||||
|
as RSHIFT 5 -> av
|
||||||
|
bo AND bu -> bw
|
||||||
|
hz AND ik -> im
|
||||||
|
bp AND bq -> bs
|
||||||
|
b RSHIFT 1 -> v
|
||||||
|
NOT l -> m
|
||||||
|
bp OR bq -> br
|
||||||
|
g AND i -> j
|
||||||
|
br AND bt -> bu
|
||||||
|
t OR s -> u
|
||||||
|
hz RSHIFT 5 -> ic
|
||||||
|
gk AND gq -> gs
|
||||||
|
fl LSHIFT 1 -> gf
|
||||||
|
he RSHIFT 3 -> hg
|
||||||
|
gz LSHIFT 15 -> hd
|
||||||
|
hf OR hl -> hm
|
||||||
|
1 AND gd -> ge
|
||||||
|
fo OR fz -> ga
|
||||||
|
id AND if -> ig
|
||||||
|
fo AND fz -> gb
|
||||||
|
gr AND gt -> gu
|
||||||
|
he OR hp -> hq
|
||||||
|
fq AND fr -> ft
|
||||||
|
ga AND gc -> gd
|
||||||
|
fo RSHIFT 2 -> fp
|
||||||
|
gl OR gm -> gn
|
||||||
|
hg AND hh -> hj
|
||||||
|
NOT hn -> ho
|
||||||
|
gl AND gm -> go
|
||||||
|
he RSHIFT 5 -> hh
|
||||||
|
NOT gb -> gc
|
||||||
|
hq AND hs -> ht
|
||||||
|
hz RSHIFT 3 -> ib
|
||||||
|
hz RSHIFT 2 -> ia
|
||||||
|
fq OR fr -> fs
|
||||||
|
hx OR hy -> hz
|
||||||
|
he AND hp -> hr
|
||||||
|
gj RSHIFT 5 -> gm
|
||||||
|
hf AND hl -> hn
|
||||||
|
hv OR hu -> hw
|
||||||
|
NOT hj -> hk
|
||||||
|
gj RSHIFT 3 -> gl
|
||||||
|
fo RSHIFT 3 -> fq
|
||||||
|
he RSHIFT 2 -> hf
|
95
07/part1.py
Normal file
95
07/part1.py
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
RE_WIRE = re.compile(r'^(.*) -> (.*)$')
|
||||||
|
RE_OPER_NOT = re.compile(r'^NOT (.*)$')
|
||||||
|
RE_OPER_AND = re.compile(r'^(.*) AND (.*)$')
|
||||||
|
RE_OPER_OR = re.compile(r'^(.*) OR (.*)$')
|
||||||
|
RE_OPER_LSHIFT = re.compile(r'^(.*) LSHIFT (.*)$')
|
||||||
|
RE_OPER_RSHIFT = re.compile(r'^(.*) RSHIFT (.*)$')
|
||||||
|
RE_OPER_VALUE = re.compile(r'^(\d+)$')
|
||||||
|
RE_OPER_COPY = re.compile(r'^([a-z]+)$')
|
||||||
|
|
||||||
|
|
||||||
|
class Wire:
|
||||||
|
|
||||||
|
def __init__(self, name, source):
|
||||||
|
self.name = name
|
||||||
|
self.source = source
|
||||||
|
self.value = None
|
||||||
|
|
||||||
|
|
||||||
|
def getWireVaule(name, wires):
|
||||||
|
|
||||||
|
if re.search(RE_OPER_VALUE, name):
|
||||||
|
return int(name)
|
||||||
|
|
||||||
|
if wires[name].value:
|
||||||
|
return wires[name].value
|
||||||
|
|
||||||
|
print "*%s -> %s" % (wires[name].source, wires[name].name)
|
||||||
|
# test on value
|
||||||
|
match = re.search(RE_OPER_VALUE, wires[name].source)
|
||||||
|
if match:
|
||||||
|
wires[name].value = int(match.group(1))
|
||||||
|
|
||||||
|
match = re.search(RE_OPER_COPY, wires[name].source)
|
||||||
|
if match:
|
||||||
|
value = getWireVaule(match.group(1), wires)
|
||||||
|
wires[name].value = value
|
||||||
|
|
||||||
|
match = re.search(RE_OPER_NOT, wires[name].source)
|
||||||
|
if match:
|
||||||
|
value = getWireVaule(match.group(1), wires)
|
||||||
|
wires[name].value = ~value & 0xFFFF
|
||||||
|
|
||||||
|
match = re.search(RE_OPER_AND, wires[name].source)
|
||||||
|
if match:
|
||||||
|
value1 = getWireVaule(match.group(1), wires)
|
||||||
|
value2 = getWireVaule(match.group(2), wires)
|
||||||
|
wires[name].value = value1 & value2
|
||||||
|
|
||||||
|
match = re.search(RE_OPER_OR, wires[name].source)
|
||||||
|
if match:
|
||||||
|
value1 = getWireVaule(match.group(1), wires)
|
||||||
|
value2 = getWireVaule(match.group(2), wires)
|
||||||
|
wires[name].value = value1 | value2
|
||||||
|
|
||||||
|
match = re.search(RE_OPER_LSHIFT, wires[name].source)
|
||||||
|
if match:
|
||||||
|
value1 = getWireVaule(match.group(1), wires)
|
||||||
|
value2 = int(match.group(2))
|
||||||
|
wires[name].value = (value1 << value2) & 0xFFFF
|
||||||
|
|
||||||
|
match = re.search(RE_OPER_RSHIFT, wires[name].source)
|
||||||
|
if match:
|
||||||
|
value1 = getWireVaule(match.group(1), wires)
|
||||||
|
value2 = int(match.group(2))
|
||||||
|
wires[name].value = (value1 >> value2) & 0xFFFF
|
||||||
|
|
||||||
|
return wires[name].value
|
||||||
|
|
||||||
|
|
||||||
|
def read_file(filename):
|
||||||
|
file = open(filename, 'r')
|
||||||
|
while True:
|
||||||
|
line = file.readline()
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
yield line
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
wire = dict()
|
||||||
|
for line in read_file('input'):
|
||||||
|
match = re.search(RE_WIRE, line)
|
||||||
|
if not match:
|
||||||
|
print "wrong operation syntax"
|
||||||
|
wire[match.group(2)] = Wire(match.group(2), match.group(1))
|
||||||
|
|
||||||
|
print wire
|
||||||
|
print getWireVaule("a", wire)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
98
07/part2.py
Normal file
98
07/part2.py
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
RE_WIRE = re.compile(r'^(.*) -> (.*)$')
|
||||||
|
RE_OPER_NOT = re.compile(r'^NOT (.*)$')
|
||||||
|
RE_OPER_AND = re.compile(r'^(.*) AND (.*)$')
|
||||||
|
RE_OPER_OR = re.compile(r'^(.*) OR (.*)$')
|
||||||
|
RE_OPER_LSHIFT = re.compile(r'^(.*) LSHIFT (.*)$')
|
||||||
|
RE_OPER_RSHIFT = re.compile(r'^(.*) RSHIFT (.*)$')
|
||||||
|
RE_OPER_VALUE = re.compile(r'^(\d+)$')
|
||||||
|
RE_OPER_COPY = re.compile(r'^([a-z]+)$')
|
||||||
|
|
||||||
|
|
||||||
|
class Wire:
|
||||||
|
|
||||||
|
def __init__(self, name, source):
|
||||||
|
self.name = name
|
||||||
|
self.source = source
|
||||||
|
self.value = None
|
||||||
|
|
||||||
|
|
||||||
|
def getWireVaule(name, wires):
|
||||||
|
|
||||||
|
if re.search(RE_OPER_VALUE, name):
|
||||||
|
return int(name)
|
||||||
|
|
||||||
|
if wires[name].value:
|
||||||
|
return wires[name].value
|
||||||
|
|
||||||
|
print "*%s -> %s" % (wires[name].source, wires[name].name)
|
||||||
|
# test on value
|
||||||
|
match = re.search(RE_OPER_VALUE, wires[name].source)
|
||||||
|
if match:
|
||||||
|
wires[name].value = int(match.group(1))
|
||||||
|
|
||||||
|
match = re.search(RE_OPER_COPY, wires[name].source)
|
||||||
|
if match:
|
||||||
|
value = getWireVaule(match.group(1), wires)
|
||||||
|
wires[name].value = value
|
||||||
|
|
||||||
|
match = re.search(RE_OPER_NOT, wires[name].source)
|
||||||
|
if match:
|
||||||
|
value = getWireVaule(match.group(1), wires)
|
||||||
|
wires[name].value = ~value & 0xFFFF
|
||||||
|
|
||||||
|
match = re.search(RE_OPER_AND, wires[name].source)
|
||||||
|
if match:
|
||||||
|
value1 = getWireVaule(match.group(1), wires)
|
||||||
|
value2 = getWireVaule(match.group(2), wires)
|
||||||
|
wires[name].value = value1 & value2
|
||||||
|
|
||||||
|
match = re.search(RE_OPER_OR, wires[name].source)
|
||||||
|
if match:
|
||||||
|
value1 = getWireVaule(match.group(1), wires)
|
||||||
|
value2 = getWireVaule(match.group(2), wires)
|
||||||
|
wires[name].value = value1 | value2
|
||||||
|
|
||||||
|
match = re.search(RE_OPER_LSHIFT, wires[name].source)
|
||||||
|
if match:
|
||||||
|
value1 = getWireVaule(match.group(1), wires)
|
||||||
|
value2 = int(match.group(2))
|
||||||
|
wires[name].value = (value1 << value2) & 0xFFFF
|
||||||
|
|
||||||
|
match = re.search(RE_OPER_RSHIFT, wires[name].source)
|
||||||
|
if match:
|
||||||
|
value1 = getWireVaule(match.group(1), wires)
|
||||||
|
value2 = int(match.group(2))
|
||||||
|
wires[name].value = (value1 >> value2) & 0xFFFF
|
||||||
|
|
||||||
|
return wires[name].value
|
||||||
|
|
||||||
|
|
||||||
|
def read_file(filename):
|
||||||
|
file = open(filename, 'r')
|
||||||
|
while True:
|
||||||
|
line = file.readline()
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
yield line
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
wire = dict()
|
||||||
|
for line in read_file('input'):
|
||||||
|
match = re.search(RE_WIRE, line)
|
||||||
|
if not match:
|
||||||
|
print "wrong operation syntax"
|
||||||
|
wire[match.group(2)] = Wire(match.group(2), match.group(1))
|
||||||
|
|
||||||
|
value_a = getWireVaule("a", wire)
|
||||||
|
for key in wire.keys():
|
||||||
|
wire[key].value = None
|
||||||
|
wire["b"].value = value_a
|
||||||
|
print getWireVaule("a", wire)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
300
08/input
Normal file
300
08/input
Normal file
@ -0,0 +1,300 @@
|
|||||||
|
"qxfcsmh"
|
||||||
|
"ffsfyxbyuhqkpwatkjgudo"
|
||||||
|
"byc\x9dyxuafof\\\xa6uf\\axfozomj\\olh\x6a"
|
||||||
|
"jtqvz"
|
||||||
|
"uzezxa\"jgbmojtwyfbfguz"
|
||||||
|
"vqsremfk\x8fxiknektafj"
|
||||||
|
"wzntebpxnnt\"vqndz\"i\x47vvjqo\""
|
||||||
|
"higvez\"k\"riewqk"
|
||||||
|
"dlkrbhbrlfrp\\damiauyucwhty"
|
||||||
|
"d\""
|
||||||
|
"qlz"
|
||||||
|
"ku"
|
||||||
|
"yy\"\"uoao\"uripabop"
|
||||||
|
"saduyrntuswlnlkuppdro\\sicxosted"
|
||||||
|
"tj"
|
||||||
|
"zzphopswlwdhebwkxeurvizdv"
|
||||||
|
"xfoheirjoakrpofles\"nfu"
|
||||||
|
"q\xb7oh\"p\xce\"n"
|
||||||
|
"qeendp\"ercwgywdjeylxcv"
|
||||||
|
"dcmem"
|
||||||
|
"\"i\x13r\"l"
|
||||||
|
"ikso\xdcbvqnbrjduh\"uqudzki\xderwk"
|
||||||
|
"wfdsn"
|
||||||
|
"pwynglklryhtsqbno"
|
||||||
|
"hcoj\x63iccz\"v\"ttr"
|
||||||
|
"zf\x23\\hlj\\kkce\\d\\asy\"yyfestwcdxyfj"
|
||||||
|
"xs"
|
||||||
|
"m\"tvltapxdvtrxiy"
|
||||||
|
"bmud"
|
||||||
|
"k\"a"
|
||||||
|
"b\"oas"
|
||||||
|
"\"yexnjjupoqsxyqnquy\"uzfdvetqrc"
|
||||||
|
"vdw\xe3olxfgujaj"
|
||||||
|
"qomcxdnd\"\\cfoe\""
|
||||||
|
"fpul"
|
||||||
|
"m\"avamefphkpv"
|
||||||
|
"vvdnb\\x\\uhnxfw\"dpubfkxfmeuhnxisd"
|
||||||
|
"hey\\"
|
||||||
|
"ldaeigghlfey"
|
||||||
|
"eure\"hoy\xa5iezjp\\tm"
|
||||||
|
"yygb\"twbj\\r\"\x10gmxuhmp\""
|
||||||
|
"weirebp\x39mqonbtmfmd"
|
||||||
|
"ltuz\\hs\"e"
|
||||||
|
"ysvmpc"
|
||||||
|
"g\x8amjtt\"megl\"omsaihifwa"
|
||||||
|
"yimmm"
|
||||||
|
"iiyqfalh"
|
||||||
|
"cwknlaaf"
|
||||||
|
"q\x37feg\xc6s\"xx"
|
||||||
|
"uayrgeurgyp\\oi"
|
||||||
|
"xhug\"pt\"axugllbdiggzhvy"
|
||||||
|
"kdaarqmsjfx\xc3d"
|
||||||
|
"\"vkwla"
|
||||||
|
"d\""
|
||||||
|
"tmroz\"bvfinxoe\\mum\"wmm"
|
||||||
|
"\"n\"bbswxne\\p\\yr\"qhwpdd"
|
||||||
|
"skzlkietklkqovjhvj\xfe"
|
||||||
|
"pbg\\pab\"bubqaf\"obzcwxwywbs\\dhtq"
|
||||||
|
"xxjidvqh\"lx\\wu\"ij"
|
||||||
|
"daef\x5fe\x5b\\kbeeb\x13qnydtboof"
|
||||||
|
"ogvazaqy\"j\x73"
|
||||||
|
"y"
|
||||||
|
"n\"tibetedldy\\gsamm\"nwu"
|
||||||
|
"wldkvgdtqulwkad"
|
||||||
|
"dpmxnj"
|
||||||
|
"twybw\"cdvf\"mjdajurokbce"
|
||||||
|
"ru\"\\lasij\"i"
|
||||||
|
"roc\\vra\\lhrm"
|
||||||
|
"pbkt\x60booz\"fjlkc"
|
||||||
|
"j\x4dytvjwrzt"
|
||||||
|
"\\uiwjkniumxcs"
|
||||||
|
"cbhm\"nexccior\"v\"j\"nazxilmfp\x47"
|
||||||
|
"qdxngevzrlgoq"
|
||||||
|
"\"lrzxftytpobsdfyrtdqpjbpuwmm\x9e"
|
||||||
|
"mdag\x0asnck\xc2ggj\"slb\"fjy"
|
||||||
|
"wyqkhjuazdtcgkcxvjkpnjdae"
|
||||||
|
"aixfk\xc0iom\x21vueob"
|
||||||
|
"dkiiakyjpkffqlluhaetires"
|
||||||
|
"ysspv\"lysgkvnmwbbsy"
|
||||||
|
"gy\"ryexcjjxdm\"xswssgtr"
|
||||||
|
"s"
|
||||||
|
"ddxv"
|
||||||
|
"qwt\"\x27puilb\"pslmbrsxhrz"
|
||||||
|
"qdg\xc9e\\qwtknlvkol\x54oqvmchn\\"
|
||||||
|
"lvo"
|
||||||
|
"b"
|
||||||
|
"fk\"aa\"\"yenwch\\\\on"
|
||||||
|
"srig\x63hpwaavs\\\x80qzk\"xa\"\xe6u\\wr"
|
||||||
|
"yxjxuj\"ghyhhxfj\"\xa6qvatre"
|
||||||
|
"yoktqxjxkzrklkoeroil"
|
||||||
|
"\"jfmik\""
|
||||||
|
"smgseztzdwldikbqrh\""
|
||||||
|
"jftahgctf\"hoqy"
|
||||||
|
"tcnhicr\"znpgckt\"ble"
|
||||||
|
"vqktnkodh\"lo\"a\\bkmdjqqnsqr"
|
||||||
|
"ztnirfzqq"
|
||||||
|
"s"
|
||||||
|
"xx"
|
||||||
|
"iqj\"y\\hqgzflwrdsusasekyrxbp\\ad"
|
||||||
|
"\\xzjhlaiynkioz\"\"bxepzimvgwt"
|
||||||
|
"s\x36rbw"
|
||||||
|
"mniieztwrisvdx"
|
||||||
|
"atyfxioy\x2b\\"
|
||||||
|
"irde\x85\x5cvbah\\jekw\"ia"
|
||||||
|
"bdmftlhkwrprmpat\"prfaocvp"
|
||||||
|
"w\\k"
|
||||||
|
"umbpausy"
|
||||||
|
"zfauhpsangy"
|
||||||
|
"p\"zqyw"
|
||||||
|
"wtztypyqvnnxzvlvipnq\"zu"
|
||||||
|
"deicgwq\\oqvajpbov\\or\"kgplwu"
|
||||||
|
"mbzlfgpi\\\\zqcidjpzqdzxityxa"
|
||||||
|
"lfkxvhma"
|
||||||
|
"\xf2yduqzqr\"\\fak\"p\"n"
|
||||||
|
"mpajacfuxotonpadvng"
|
||||||
|
"anb\\telzvcdu\\a\xf2flfq"
|
||||||
|
"lrs\"ebethwpmuuc\"\x86ygr"
|
||||||
|
"qmvdbhtumzc\"ci"
|
||||||
|
"meet"
|
||||||
|
"yopg\x0fdxdq\"h\\ugsu\xffmolxjv"
|
||||||
|
"uhy"
|
||||||
|
"fzgidrtzycsireghazscvmwcfmw\\t"
|
||||||
|
"cqohkhpgvpru"
|
||||||
|
"bihyigtnvmevx\"xx"
|
||||||
|
"xz"
|
||||||
|
"zofomwotzuxsjk\"q\"mc\"js\"dnmalhxd"
|
||||||
|
"\\ktnddux\\fqvt\"ibnjntjcbn"
|
||||||
|
"ia"
|
||||||
|
"htjadnefwetyp\xd5kbrwfycbyy"
|
||||||
|
"\"\\hkuxqddnao"
|
||||||
|
"meqqsz\x83luecpgaem"
|
||||||
|
"cvks\x87frvxo\"svqivqsdpgwhukmju"
|
||||||
|
"sgmxiai\\o\"riufxwjfigr\xdf"
|
||||||
|
"fgywdfecqufccpcdn"
|
||||||
|
"faghjoq\x28abxnpxj"
|
||||||
|
"zuppgzcfb\"dctvp\"elup\"zxkopx"
|
||||||
|
"xqs\x45xxdqcihbwghmzoa"
|
||||||
|
"anbnlp\\cgcvm\"hc"
|
||||||
|
"xf\"fgrngwzys"
|
||||||
|
"nrxsjduedcy\x24"
|
||||||
|
"\x71sxl\"gj\"sds\"ulcruguz\\t\\ssvjcwhi"
|
||||||
|
"jhj\"msch"
|
||||||
|
"qpovolktfwyiuyicbfeeju\x01"
|
||||||
|
"nkyxmb\"qyqultgt\"nmvzvvnxnb"
|
||||||
|
"ycsrkbstgzqb\"uv\\cisn"
|
||||||
|
"s"
|
||||||
|
"ueptjnn\"\"sh"
|
||||||
|
"lp\"z\"d\"mxtxiy"
|
||||||
|
"yzjtvockdnvbubqabjourf\"k\"uoxwle"
|
||||||
|
"\x82\"wqm\""
|
||||||
|
"\xb5cwtuks\x5fpgh"
|
||||||
|
"wd"
|
||||||
|
"tbvf"
|
||||||
|
"ttbmzdgn"
|
||||||
|
"vfpiyfdejyrlbgcdtwzbnm"
|
||||||
|
"uc"
|
||||||
|
"otdcmhpjagqix"
|
||||||
|
"\\\xb1qso\"s"
|
||||||
|
"scowax"
|
||||||
|
"behpstjdh\xccqlgnqjyz\"eesn"
|
||||||
|
"r\xe1cbnjwzveoomkzlo\\kxlfouhm"
|
||||||
|
"jgrl"
|
||||||
|
"kzqs\\r"
|
||||||
|
"ctscb\x7fthwkdyko\"\x62pkf\"d\xe6knmhurg"
|
||||||
|
"tc\"kw\x3ftt"
|
||||||
|
"bxb\x5ccl"
|
||||||
|
"jyrmfbphsldwpq"
|
||||||
|
"jylpvysl\"\"juducjg"
|
||||||
|
"en\\m\"kxpq\"wpb\\\""
|
||||||
|
"madouht\"bmdwvnyqvpnawiphgac\""
|
||||||
|
"vuxpk\"ltucrw"
|
||||||
|
"aae\x60arr"
|
||||||
|
"ttitnne\"kilkrgssnr\xfdurzh"
|
||||||
|
"oalw"
|
||||||
|
"pc\"\"gktkdykzbdpkwigucqni\"nxiqx"
|
||||||
|
"dbrsaj"
|
||||||
|
"bgzsowyxcbrvhtvekhsh\"qgd"
|
||||||
|
"kudfemvk\"\"\"hkbrbil\"chkqoa"
|
||||||
|
"zjzgj\\ekbhyfzufy"
|
||||||
|
"\\acos\"fqekuxqzxbmkbnn\x1ejzwrm"
|
||||||
|
"elxahvudn\"txtmomotgw"
|
||||||
|
"\x2eoxmwdhelpr\"cgi\xf7pzvb"
|
||||||
|
"eapheklx"
|
||||||
|
"hfvma\"mietvc\"tszbbm\"czex"
|
||||||
|
"h\"iiockj\\\xc1et"
|
||||||
|
"d\"rmjjftm"
|
||||||
|
"qlvhdcbqtyrhlc\\"
|
||||||
|
"yy\"rsucjtulm\"coryri\"eqjlbmk"
|
||||||
|
"tv"
|
||||||
|
"r\"bfuht\\jjgujp\""
|
||||||
|
"kukxvuauamtdosngdjlkauylttaokaj"
|
||||||
|
"srgost\"\"rbkcqtlccu\x65ohjptstrjkzy"
|
||||||
|
"yxwxl\\yjilwwxffrjjuazmzjs"
|
||||||
|
"dxlw\\fkstu\"hjrtiafhyuoh\"sewabne"
|
||||||
|
"\x88sj\"v"
|
||||||
|
"rfzprz\xec\"oxqclu\"krzefp\\q"
|
||||||
|
"cfmhdbjuhrcymgxpylllyvpni"
|
||||||
|
"ucrmjvmimmcq\x88\xd9\"lz"
|
||||||
|
"lujtt\""
|
||||||
|
"gvbqoixn\"pmledpjmo\"flydnwkfxllf"
|
||||||
|
"dvxqlbshhmelsk\x8big\"l"
|
||||||
|
"mx\x54lma\x8bbguxejg"
|
||||||
|
"\x66jdati\xeceieo"
|
||||||
|
"\"iyyupixei\x54ff"
|
||||||
|
"xohzf\"rbxsoksxamiu"
|
||||||
|
"vlhthspeshzbppa\x4drhqnohjop\"\"mfjd"
|
||||||
|
"f\"tvxxla\"vurian\"\"idjq\x3aptm\xc3olep"
|
||||||
|
"gzqz"
|
||||||
|
"kbq\\wogye\\altvi\\hbvmodny"
|
||||||
|
"j\xd8"
|
||||||
|
"ofjozdhkblvndl"
|
||||||
|
"hbitoupimbawimxlxqze"
|
||||||
|
"ypeleimnme"
|
||||||
|
"xfwdrzsc\\oxqamawyizvi\\y"
|
||||||
|
"enoikppx\xa1ixe\"yo\"gumye"
|
||||||
|
"fb"
|
||||||
|
"vzf"
|
||||||
|
"zxidr"
|
||||||
|
"cu\x31beirsywtskq"
|
||||||
|
"lxpjbvqzztafwezd"
|
||||||
|
"\\jyxeuo\x18bv"
|
||||||
|
"b\"vawc\"p\\\\giern\"b"
|
||||||
|
"odizunx\"\"t\\yicdn\"x\"sdiz"
|
||||||
|
"\"\"tebrtsi"
|
||||||
|
"ctyzsxv\xa6pegfkwsi\"tgyltaakytccb"
|
||||||
|
"htxwbofchvmzbppycccliyik\xe5a"
|
||||||
|
"ggsslefamsklezqkrd"
|
||||||
|
"rcep\"fnimwvvdx\"l"
|
||||||
|
"zyrzlqmd\x12egvqs\\llqyie"
|
||||||
|
"\x07gsqyrr\\rcyhyspsvn"
|
||||||
|
"butg\""
|
||||||
|
"gb"
|
||||||
|
"gywkoxf\"jsg\\wtopxvumirqxlwz"
|
||||||
|
"rj\"ir\"wldwveair\x2es\"dhjrdehbqnzl"
|
||||||
|
"ru\"elktnsbxufk\\ejufjfjlevt\\lrzd"
|
||||||
|
"\"widsvok"
|
||||||
|
"oy\"\x81nuesvw"
|
||||||
|
"ay"
|
||||||
|
"syticfac\x1cfjsivwlmy\"pumsqlqqzx"
|
||||||
|
"m"
|
||||||
|
"rjjkfh\x78cf\x2brgceg\"jmdyas\"\\xlv\xb6p"
|
||||||
|
"tmuvo\"\x3ffdqdovjmdmkgpstotojkv\"as"
|
||||||
|
"jd\\ojvynhxllfzzxvbn\"wrpphcvx"
|
||||||
|
"pz"
|
||||||
|
"\"twr"
|
||||||
|
"n\\hdzmxe\"mzjjeadlz"
|
||||||
|
"fb\"rprxuagvahjnri"
|
||||||
|
"rfmexmjjgh\\xrnmyvnatrvfruflaqjnd"
|
||||||
|
"obbbde\"co\"qr\"qpiwjgqahqm\\jjp\""
|
||||||
|
"vpbq\"\"y\"czk\\b\x52ed\"lnzepobp"
|
||||||
|
"syzeajzfarplydipny\"y\"\xe8ad"
|
||||||
|
"mpyodwb"
|
||||||
|
"\x47rakphlqqptd"
|
||||||
|
"wa\"oj\"aiy"
|
||||||
|
"a"
|
||||||
|
"ropozx"
|
||||||
|
"q\x51nbtlwa"
|
||||||
|
"etukvgx\\jqxlkq"
|
||||||
|
"\"tp\"rah\"pg\"s\"bpdtes\\tkasdhqd"
|
||||||
|
"dn\"qqpkikadowssb\xcah\"dzpsf\\ect\"jdh"
|
||||||
|
"pxunovbbrrn\\vullyn\"bno\"\"\"myfxlp\""
|
||||||
|
"qaixyazuryvkmoulhcqaotegfj\\mpzm"
|
||||||
|
"bvfrbicutzbjwn\\oml\"cf\"d\"ezcpv\"j"
|
||||||
|
"rmbrdtneudemigdhelmb"
|
||||||
|
"aq\\aurmbhy"
|
||||||
|
"wujqvzw"
|
||||||
|
"gf\"tssmvm\"gm\"hu\x9a\xb7yjawsa"
|
||||||
|
"hrhqqxow\xe2gsydtdspcfqy\"zw\\ou"
|
||||||
|
"ianwwf\\yko\\tdujhhqdi"
|
||||||
|
"xylz\"zpvpab"
|
||||||
|
"lwuopbeeegp"
|
||||||
|
"aoop\x49jhhcexdmdtun"
|
||||||
|
"\\\\mouqqcsgmz"
|
||||||
|
"tltuvwhveau\x43b\"ymxjlcgiymcynwt"
|
||||||
|
"gsugerumpyuhtjljbhrdyoj"
|
||||||
|
"lnjm\xb8wg\"ajh"
|
||||||
|
"zmspue\"nfttdon\\b\"eww"
|
||||||
|
"\"w\x67jwaq\x7ernmyvs\\rmdsuwydsd\"th"
|
||||||
|
"ogtgvtlmcvgllyv"
|
||||||
|
"z\"fqi\"rvddoehrciyl"
|
||||||
|
"yustxxtot\"muec\"xvfdbzunzvveq"
|
||||||
|
"mqslw"
|
||||||
|
"txqnyvzmibqgjs\xb6xy\x86nfalfyx"
|
||||||
|
"kzhehlmkholov"
|
||||||
|
"plpmywcnirrjutjguosh\\"
|
||||||
|
"pydbnqofv\"dn\\m"
|
||||||
|
"aegqof"
|
||||||
|
"eambmxt\\dxagoogl\\zapfwwlmk"
|
||||||
|
"afbmqitxxqhddlozuxcpjxgh"
|
||||||
|
"vgts"
|
||||||
|
"bfdpqtoxzzhmzcilehnflna"
|
||||||
|
"s\"idpz"
|
||||||
|
"\xcfhgly\"nlmztwybx\"ecezmsxaqw"
|
||||||
|
"aackfgndqcqiy"
|
||||||
|
"\x22unqdlsrvgzfaohoffgxzfpir\"s"
|
||||||
|
"abh\"ydv\"kbpdhrerl"
|
||||||
|
"bdzpg"
|
||||||
|
"ekwgkywtmzp"
|
||||||
|
"wtoodejqmrrgslhvnk\"pi\"ldnogpth"
|
||||||
|
"njro\x68qgbx\xe4af\"\\suan"
|
48
08/part1.py
Normal file
48
08/part1.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
|
||||||
|
def read_file(filename):
|
||||||
|
file = open(filename, 'r')
|
||||||
|
while True:
|
||||||
|
line = file.readline()
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
yield line.rstrip()
|
||||||
|
|
||||||
|
|
||||||
|
def getMemorySize(line):
|
||||||
|
count = 0
|
||||||
|
pos = 0
|
||||||
|
while pos < len(line):
|
||||||
|
if line[pos] != '\\':
|
||||||
|
pos += 1
|
||||||
|
count += 1
|
||||||
|
elif line[pos+1] == '\\':
|
||||||
|
pos += 2
|
||||||
|
count += 1
|
||||||
|
elif line[pos+1] == '"':
|
||||||
|
pos += 2
|
||||||
|
count += 1
|
||||||
|
elif line[pos+1] == 'x':
|
||||||
|
pos += 4
|
||||||
|
count += 1
|
||||||
|
else:
|
||||||
|
print "chyba"
|
||||||
|
return count
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
|
||||||
|
numCode = 0
|
||||||
|
numMem = 0
|
||||||
|
for line in read_file('input'):
|
||||||
|
numCode = numCode + len(line)
|
||||||
|
numMem = numMem + getMemorySize(line) - 2
|
||||||
|
print line
|
||||||
|
|
||||||
|
print numCode
|
||||||
|
print numMem
|
||||||
|
print numCode - numMem
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
48
08/part2.py
Normal file
48
08/part2.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
|
||||||
|
def read_file(filename):
|
||||||
|
file = open(filename, 'r')
|
||||||
|
while True:
|
||||||
|
line = file.readline()
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
yield line.rstrip()
|
||||||
|
|
||||||
|
|
||||||
|
def getMemorySize(line):
|
||||||
|
count = 0
|
||||||
|
pos = 0
|
||||||
|
while pos < len(line):
|
||||||
|
if line[pos] != '\\':
|
||||||
|
pos += 1
|
||||||
|
count += 1
|
||||||
|
elif line[pos+1] == '\\':
|
||||||
|
pos += 2
|
||||||
|
count += 4
|
||||||
|
elif line[pos+1] == '"':
|
||||||
|
pos += 2
|
||||||
|
count += 4
|
||||||
|
elif line[pos+1] == 'x':
|
||||||
|
pos += 4
|
||||||
|
count += 5
|
||||||
|
else:
|
||||||
|
print "chyba"
|
||||||
|
return count
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
|
||||||
|
numCode = 0
|
||||||
|
numMem = 0
|
||||||
|
for line in read_file('input'):
|
||||||
|
numCode = numCode + len(line)
|
||||||
|
numMem = numMem + getMemorySize(line) + 4
|
||||||
|
print line
|
||||||
|
|
||||||
|
print numCode
|
||||||
|
print numMem
|
||||||
|
print numMem - numCode
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
28
09/input
Normal file
28
09/input
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
Faerun to Norrath = 129
|
||||||
|
Faerun to Tristram = 58
|
||||||
|
Faerun to AlphaCentauri = 13
|
||||||
|
Faerun to Arbre = 24
|
||||||
|
Faerun to Snowdin = 60
|
||||||
|
Faerun to Tambi = 71
|
||||||
|
Faerun to Straylight = 67
|
||||||
|
Norrath to Tristram = 142
|
||||||
|
Norrath to AlphaCentauri = 15
|
||||||
|
Norrath to Arbre = 135
|
||||||
|
Norrath to Snowdin = 75
|
||||||
|
Norrath to Tambi = 82
|
||||||
|
Norrath to Straylight = 54
|
||||||
|
Tristram to AlphaCentauri = 118
|
||||||
|
Tristram to Arbre = 122
|
||||||
|
Tristram to Snowdin = 103
|
||||||
|
Tristram to Tambi = 49
|
||||||
|
Tristram to Straylight = 97
|
||||||
|
AlphaCentauri to Arbre = 116
|
||||||
|
AlphaCentauri to Snowdin = 12
|
||||||
|
AlphaCentauri to Tambi = 18
|
||||||
|
AlphaCentauri to Straylight = 91
|
||||||
|
Arbre to Snowdin = 129
|
||||||
|
Arbre to Tambi = 53
|
||||||
|
Arbre to Straylight = 40
|
||||||
|
Snowdin to Tambi = 15
|
||||||
|
Snowdin to Straylight = 99
|
||||||
|
Tambi to Straylight = 70
|
3
09/input1
Normal file
3
09/input1
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
London to Dublin = 464
|
||||||
|
London to Belfast = 518
|
||||||
|
Dublin to Belfast = 141
|
61
09/part1.py
Normal file
61
09/part1.py
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
RE_DISTANCE = re.compile(r'^(.*) to (.*) = (\d+)$')
|
||||||
|
|
||||||
|
|
||||||
|
class Town:
|
||||||
|
|
||||||
|
def __init__(self, name):
|
||||||
|
self.name = name
|
||||||
|
self.distance = dict()
|
||||||
|
|
||||||
|
def addDistance(self, town, distance):
|
||||||
|
self.distance[town] = distance
|
||||||
|
|
||||||
|
|
||||||
|
def read_file(filename):
|
||||||
|
file = open(filename, 'r')
|
||||||
|
while True:
|
||||||
|
line = file.readline()
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
yield line
|
||||||
|
|
||||||
|
|
||||||
|
def computePossiblePaths(town, neighbours, maxTowns, visited, journey):
|
||||||
|
visited.append(town)
|
||||||
|
if len(visited) == maxTowns:
|
||||||
|
print "%010d %s" % (journey, ",".join(visited))
|
||||||
|
visited.pop()
|
||||||
|
return
|
||||||
|
for nei in neighbours[town].distance.keys():
|
||||||
|
if nei in visited:
|
||||||
|
continue
|
||||||
|
distance = neighbours[town].distance[nei]
|
||||||
|
journey += distance
|
||||||
|
computePossiblePaths(nei, neighbours, maxTowns, visited, journey)
|
||||||
|
journey -= distance
|
||||||
|
visited.pop()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
towns = dict()
|
||||||
|
for line in read_file('input'):
|
||||||
|
match = re.search(RE_DISTANCE, line)
|
||||||
|
if not match:
|
||||||
|
print "wrong operation syntax"
|
||||||
|
if match.group(1) not in towns:
|
||||||
|
towns[match.group(1)] = Town(match.group(1))
|
||||||
|
if match.group(2) not in towns:
|
||||||
|
towns[match.group(2)] = Town(match.group(2))
|
||||||
|
towns[match.group(1)].addDistance(match.group(2), int(match.group(3)))
|
||||||
|
towns[match.group(2)].addDistance(match.group(1), int(match.group(3)))
|
||||||
|
|
||||||
|
for town in towns.keys():
|
||||||
|
print "Starting point: %s" % (town)
|
||||||
|
computePossiblePaths(town, towns, len(towns.keys()), [], 0)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
61
09/part2.py
Normal file
61
09/part2.py
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
RE_DISTANCE = re.compile(r'^(.*) to (.*) = (\d+)$')
|
||||||
|
|
||||||
|
|
||||||
|
class Town:
|
||||||
|
|
||||||
|
def __init__(self, name):
|
||||||
|
self.name = name
|
||||||
|
self.distance = dict()
|
||||||
|
|
||||||
|
def addDistance(self, town, distance):
|
||||||
|
self.distance[town] = distance
|
||||||
|
|
||||||
|
|
||||||
|
def read_file(filename):
|
||||||
|
file = open(filename, 'r')
|
||||||
|
while True:
|
||||||
|
line = file.readline()
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
yield line
|
||||||
|
|
||||||
|
|
||||||
|
def computePossiblePaths(town, neighbours, maxTowns, visited, journey):
|
||||||
|
visited.append(town)
|
||||||
|
if len(visited) == maxTowns:
|
||||||
|
print "%010d %s" % (journey, ",".join(visited))
|
||||||
|
visited.pop()
|
||||||
|
return
|
||||||
|
for nei in neighbours[town].distance.keys():
|
||||||
|
if nei in visited:
|
||||||
|
continue
|
||||||
|
distance = neighbours[town].distance[nei]
|
||||||
|
journey += distance
|
||||||
|
computePossiblePaths(nei, neighbours, maxTowns, visited, journey)
|
||||||
|
journey -= distance
|
||||||
|
visited.pop()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
towns = dict()
|
||||||
|
for line in read_file('input'):
|
||||||
|
match = re.search(RE_DISTANCE, line)
|
||||||
|
if not match:
|
||||||
|
print "wrong operation syntax"
|
||||||
|
if match.group(1) not in towns:
|
||||||
|
towns[match.group(1)] = Town(match.group(1))
|
||||||
|
if match.group(2) not in towns:
|
||||||
|
towns[match.group(2)] = Town(match.group(2))
|
||||||
|
towns[match.group(1)].addDistance(match.group(2), int(match.group(3)))
|
||||||
|
towns[match.group(2)].addDistance(match.group(1), int(match.group(3)))
|
||||||
|
|
||||||
|
for town in towns.keys():
|
||||||
|
print "Starting point: %s" % (town)
|
||||||
|
computePossiblePaths(town, towns, len(towns.keys()), [], 0)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
26
10/part1.py
Normal file
26
10/part1.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
RE_MATCH_LONGEST = re.compile(r'(.)(\1*)')
|
||||||
|
|
||||||
|
|
||||||
|
def lookAndSay(sequence):
|
||||||
|
pos = 0
|
||||||
|
result = ""
|
||||||
|
while pos < len(sequence):
|
||||||
|
match = re.match(RE_MATCH_LONGEST, sequence[pos:])
|
||||||
|
pos += len(match.group(2)) + 1
|
||||||
|
result = "%s%d%s" % (result, len(match.group(2))+1, match.group(1))
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
input = "1113222113"
|
||||||
|
for x in range(0, 40):
|
||||||
|
input = lookAndSay(input)
|
||||||
|
|
||||||
|
print len(input)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
26
10/part2.py
Normal file
26
10/part2.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
RE_MATCH_LONGEST = re.compile(r'(.)(\1*)')
|
||||||
|
|
||||||
|
|
||||||
|
def lookAndSay(sequence):
|
||||||
|
pos = 0
|
||||||
|
result = ""
|
||||||
|
while pos < len(sequence):
|
||||||
|
match = re.match(RE_MATCH_LONGEST, sequence[pos:])
|
||||||
|
pos += len(match.group(2)) + 1
|
||||||
|
result = "%s%d%s" % (result, len(match.group(2))+1, match.group(1))
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
input = "1113222113"
|
||||||
|
for x in range(0, 50):
|
||||||
|
input = lookAndSay(input)
|
||||||
|
|
||||||
|
print len(input)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
x
Reference in New Issue
Block a user