├── 1 ├── 1.py ├── 1.fsx ├── 2.py └── 1.in ├── 5 ├── 1.fs ├── test.in └── 1.py ├── 6 ├── test.in ├── 1.in ├── 2.py └── 1.py ├── 7 ├── test.in ├── 1.py ├── 2.py └── 1.in ├── 8 ├── test.in ├── 1.py └── 2.py ├── 9 ├── test.in ├── 1.in └── 1.py ├── 10 ├── test.in ├── 1.py └── 1.in ├── 11 ├── 1.py └── 2.py ├── 12 ├── test.in ├── 1.in ├── 1.py └── 2.py ├── 13 ├── test2.in ├── test.in ├── 1.py ├── 2.py └── 1.in ├── 14 ├── 1.py └── 2.py ├── 15 ├── test2.in ├── test.in ├── 1.in ├── 1.py └── 2.py ├── 16 ├── test.in ├── 1.py ├── 2.py └── 2.in ├── 17 ├── test.in ├── 2.py └── 1.py ├── 18 ├── test.in ├── 1.py ├── 2.py └── 1.in ├── 19 ├── test.in ├── 2_helper.py ├── 1.in ├── 1.py └── 2.py ├── 20 ├── test.in ├── 1.py └── 1.in ├── 21 ├── 1.txt ├── 1.in └── 2.py ├── 22 ├── 1.in ├── test.in ├── 1.py └── 2.py ├── 23 ├── test2.in ├── test.in ├── 1.py └── 2.py ├── 24 ├── test.in ├── 1.in ├── 1.py └── 2.py ├── 25 ├── test.in ├── 1.py └── 1.in ├── Readme.md ├── LICENSE └── .gitignore /5/1.fs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /5/test.in: -------------------------------------------------------------------------------- 1 | dabAcCaCBAcCcaDA -------------------------------------------------------------------------------- /22/1.in: -------------------------------------------------------------------------------- 1 | depth: 4848 2 | target: 15,700 -------------------------------------------------------------------------------- /22/test.in: -------------------------------------------------------------------------------- 1 | depth: 510 2 | target: 10,10 -------------------------------------------------------------------------------- /8/test.in: -------------------------------------------------------------------------------- 1 | 2 3 0 3 10 11 12 1 1 0 1 99 2 1 1 2 -------------------------------------------------------------------------------- /9/test.in: -------------------------------------------------------------------------------- 1 | 21 players; last marble is worth 6111 points -------------------------------------------------------------------------------- /6/test.in: -------------------------------------------------------------------------------- 1 | 1, 1 2 | 1, 6 3 | 8, 3 4 | 3, 4 5 | 5, 5 6 | 8, 9 -------------------------------------------------------------------------------- /9/1.in: -------------------------------------------------------------------------------- 1 | 452 players; last marble is worth 7125000 points -------------------------------------------------------------------------------- /20/test.in: -------------------------------------------------------------------------------- 1 | ^WSSEESWWWNW(S|NENNEEEENN(ESSSSW(NWSW|SSEN)|WSWWN(E|WWS(E|SS))))$ 2 | -------------------------------------------------------------------------------- /15/test2.in: -------------------------------------------------------------------------------- 1 | ####### 2 | #E..EG# 3 | #.#G.E# 4 | #E.##E# 5 | #G..#.# 6 | #..E#.# 7 | ####### -------------------------------------------------------------------------------- /13/test2.in: -------------------------------------------------------------------------------- 1 | />-<\ 2 | | | 3 | | /<+-\ 4 | | | | v 5 | \>+/ 8 | -------------------------------------------------------------------------------- /15/test.in: -------------------------------------------------------------------------------- 1 | ####### 2 | #E.G#.# 3 | #.#G..# 4 | #G.#.G# 5 | #G..#.# 6 | #...E.# 7 | ####### 8 | -------------------------------------------------------------------------------- /13/test.in: -------------------------------------------------------------------------------- 1 | /->-\ 2 | | | /----\ 3 | | /-+--+-\ | 4 | | | | | v | 5 | \-+-/ \-+--/ 6 | \------/ 7 | -------------------------------------------------------------------------------- /19/test.in: -------------------------------------------------------------------------------- 1 | #ip 0 2 | seti 5 0 1 3 | seti 6 0 2 4 | addi 0 1 0 5 | addr 1 2 3 6 | setr 1 0 0 7 | seti 8 0 4 8 | seti 9 0 5 9 | -------------------------------------------------------------------------------- /16/test.in: -------------------------------------------------------------------------------- 1 | Before: [1, 0, 1, 3] 2 | 9 2 1 0 3 | After: [2, 0, 1, 3] 4 | 5 | Before: [0, 1, 2, 3] 6 | 13 0 0 1 7 | After: [0, 1, 2, 3] -------------------------------------------------------------------------------- /21/1.txt: -------------------------------------------------------------------------------- 1 | # Read the assembly and observe that only "eqrr 3 0 4" instruction checks for 0. 2 | # Run a simulation using 19.py and print the memory for 3 -------------------------------------------------------------------------------- /23/test2.in: -------------------------------------------------------------------------------- 1 | pos=<10,12,12>, r=2 2 | pos=<12,14,12>, r=2 3 | pos=<16,12,12>, r=4 4 | pos=<14,14,14>, r=6 5 | pos=<50,50,50>, r=200 6 | pos=<10,10,10>, r=5 -------------------------------------------------------------------------------- /25/test.in: -------------------------------------------------------------------------------- 1 | 1,-1,-1,-2 2 | -2,-2,0,1 3 | 0,2,1,3 4 | -2,3,-2,1 5 | 0,2,3,-2 6 | -1,-1,1,-2 7 | 0,-2,-1,0 8 | -2,2,3,-1 9 | 1,2,2,0 10 | -1,-2,0,-2 -------------------------------------------------------------------------------- /17/test.in: -------------------------------------------------------------------------------- 1 | x=495, y=2..7 2 | y=7, x=495..501 3 | x=501, y=3..7 4 | x=498, y=2..4 5 | x=506, y=1..2 6 | x=498, y=10..13 7 | x=504, y=10..13 8 | y=13, x=498..504 -------------------------------------------------------------------------------- /18/test.in: -------------------------------------------------------------------------------- 1 | .#.#...|#. 2 | .....#|##| 3 | .|..|...#. 4 | ..|#.....# 5 | #.#|||#|#| 6 | ...#.||... 7 | .|....|... 8 | ||...#|.#| 9 | |.||||..|. 10 | ...#.|..|. 11 | -------------------------------------------------------------------------------- /23/test.in: -------------------------------------------------------------------------------- 1 | pos=<0,0,0>, r=4 2 | pos=<1,0,0>, r=1 3 | pos=<4,0,0>, r=3 4 | pos=<0,2,0>, r=1 5 | pos=<0,5,0>, r=3 6 | pos=<0,0,3>, r=1 7 | pos=<1,1,1>, r=1 8 | pos=<1,1,2>, r=1 9 | pos=<1,3,1>, r=1 -------------------------------------------------------------------------------- /1/1.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | input_path = "1.in" 3 | freq_shift = 0 4 | with open(input_path, 'r') as f: 5 | for line in f: 6 | freq_shift += int(line) 7 | print(freq_shift) -------------------------------------------------------------------------------- /1/1.fsx: -------------------------------------------------------------------------------- 1 | open System 2 | 3 | let echo message = 4 | printfn "%s %d" message 5 | 6 | [] 7 | let main argv = 8 | let echo = echo "Foo" 9 | echo 4 10 | 0 // return an integer exit code 11 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | Simple and comprehensive algorithmic solutions for [AdventofCode2018](https://adventofcode.com/2018 "AdventOfCode2018"). [2017](https://github.com/antonydeepak/AdventofCode2017 "AdventOfCode2017") solutions are here as well. -------------------------------------------------------------------------------- /12/test.in: -------------------------------------------------------------------------------- 1 | initial state: #..#.#..##......###...### 2 | 3 | ...## => # 4 | ..#.. => # 5 | .#... => # 6 | .#.#. => # 7 | .#.## => # 8 | .##.. => # 9 | .#### => # 10 | #.#.# => # 11 | #.### => # 12 | ##.#. => # 13 | ##.## => # 14 | ###.. => # 15 | ###.# => # 16 | ####. => # 17 | -------------------------------------------------------------------------------- /19/2_helper.py: -------------------------------------------------------------------------------- 1 | total = 10551275 #1 is going all the way to this value 2 | # during the time of this journey how is reg 0 changed w.r.t eqrr *5,10551275 3 | # *5 = *1 x *3 4 | 5 | _0value = 0 6 | for _1value in range(1, total): 7 | _5value = total // _1value 8 | if _5value*_1value == total: 9 | _0value += _1value 10 | print(_0value) -------------------------------------------------------------------------------- /7/test.in: -------------------------------------------------------------------------------- 1 | Step C must be finished before step A can begin. 2 | Step C must be finished before step F can begin. 3 | Step A must be finished before step B can begin. 4 | Step A must be finished before step D can begin. 5 | Step B must be finished before step E can begin. 6 | Step D must be finished before step E can begin. 7 | Step F must be finished before step E can begin. -------------------------------------------------------------------------------- /5/1.py: -------------------------------------------------------------------------------- 1 | def does_react(a, b): 2 | return (ord(a) + 32 == ord(b)) or (ord(a) - 32 == ord(b)) 3 | 4 | if __name__ == '__main__': 5 | input_path = "1.in" 6 | line = open(input_path, 'r').readline().rstrip('\n') 7 | stack = [] 8 | for c in line: 9 | if len(stack)>0 and does_react(stack[-1], c): 10 | stack.pop() 11 | else: 12 | stack.append(c) 13 | print(len(stack)) -------------------------------------------------------------------------------- /21/1.in: -------------------------------------------------------------------------------- 1 | #ip 5 2 | seti 123 0 3 3 | bani 3 456 3 4 | eqri 3 72 3 5 | addr 3 5 5 6 | seti 0 0 5 7 | seti 0 9 3 8 | bori 3 65536 1 9 | seti 9450265 6 3 10 | bani 1 255 4 11 | addr 3 4 3 12 | bani 3 16777215 3 13 | muli 3 65899 3 14 | bani 3 16777215 3 15 | gtir 256 1 4 16 | addr 4 5 5 17 | addi 5 1 5 18 | seti 27 1 5 19 | seti 0 9 4 20 | addi 4 1 2 21 | muli 2 256 2 22 | gtrr 2 1 2 23 | addr 2 5 5 24 | addi 5 1 5 25 | seti 25 7 5 26 | addi 4 1 4 27 | seti 17 5 5 28 | setr 4 6 1 29 | seti 7 8 5 30 | eqrr 3 0 4 31 | addr 4 5 5 32 | seti 5 8 5 -------------------------------------------------------------------------------- /1/2.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | if __name__ == '__main__': 4 | input_path = "1.in" 5 | with open(input_path, 'r') as f: 6 | freq_shift = 0 7 | all_frequencies = set([freq_shift]) 8 | 9 | while True: 10 | f.seek(0) 11 | for line in f: 12 | freq_shift += int(line) 13 | if freq_shift in all_frequencies: 14 | print(freq_shift) 15 | sys.exit(0) 16 | break 17 | all_frequencies.add(freq_shift) -------------------------------------------------------------------------------- /8/1.py: -------------------------------------------------------------------------------- 1 | def metadata(tree): 2 | meta = 0 3 | children,meta_count = head(tree),head(tree) 4 | for _ in range(children): 5 | meta += metadata(tree) 6 | for _ in range(meta_count): 7 | meta += head(tree) 8 | return meta 9 | 10 | def head(tree): 11 | return next(tree) 12 | 13 | if __name__ == '__main__': #file_name = "test.in" 14 | # file_name = "test.in" 15 | file_name = "1.in" 16 | line = open(file_name, 'r').readline().rstrip() 17 | tree = map(int, line.split()) 18 | print(metadata(tree)) -------------------------------------------------------------------------------- /24/test.in: -------------------------------------------------------------------------------- 1 | Immune System: 2 | 17 units each with 5390 hit points (weak to radiation, bludgeoning) with an attack that does 4507 fire damage at initiative 2 3 | 989 units each with 1274 hit points (immune to fire; weak to bludgeoning, slashing) with an attack that does 25 slashing damage at initiative 3 4 | Infection: 5 | 801 units each with 4706 hit points (weak to radiation) with an attack that does 116 bludgeoning damage at initiative 1 6 | 4485 units each with 2961 hit points (immune to radiation; weak to fire, cold) with an attack that does 12 slashing damage at initiative 4 -------------------------------------------------------------------------------- /19/1.in: -------------------------------------------------------------------------------- 1 | #ip 2 2 | addi 2 16 2 3 | seti 1 1 1 4 | seti 1 4 3 5 | mulr 1 3 5 6 | eqrr 5 4 5 7 | addr 5 2 2 8 | addi 2 1 2 9 | addr 1 0 0 10 | addi 3 1 3 11 | gtrr 3 4 5 12 | addr 2 5 2 13 | seti 2 4 2 14 | addi 1 1 1 15 | gtrr 1 4 5 16 | addr 5 2 2 17 | seti 1 0 2 18 | mulr 2 2 2 19 | addi 4 2 4 20 | mulr 4 4 4 21 | mulr 2 4 4 22 | muli 4 11 4 23 | addi 5 1 5 24 | mulr 5 2 5 25 | addi 5 17 5 26 | addr 4 5 4 27 | addr 2 0 2 28 | seti 0 9 2 29 | setr 2 3 5 30 | mulr 5 2 5 31 | addr 2 5 5 32 | mulr 2 5 5 33 | muli 5 14 5 34 | mulr 5 2 5 35 | addr 4 5 4 36 | seti 0 9 0 37 | seti 0 6 2 38 | -------------------------------------------------------------------------------- /14/1.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | until = 990941 3 | recipes = [3, 7] 4 | e1 = 0 5 | e2 = 1 6 | n = len(recipes) 7 | while n<(until+10): 8 | # sum 9 | total = recipes[e1] + recipes[e2] 10 | 11 | # break down and append 12 | first,second = total//10,total%10 13 | if first>0: 14 | recipes.append(first) 15 | recipes.append(second) 16 | 17 | # move 18 | n = len(recipes) 19 | e1 = (e1+recipes[e1]+1)%n 20 | e2 = (e2+recipes[e2]+1)%n 21 | print(recipes[(len(recipes)-10):]) -------------------------------------------------------------------------------- /12/1.in: -------------------------------------------------------------------------------- 1 | initial state: ##.#....#..#......#..######..#.####.....#......##.##.##...#..#....#.#.##..##.##.#.#..#.#....#.#..#.# 2 | 3 | #.#.. => . 4 | ..##. => . 5 | ...#. => . 6 | ..#.. => . 7 | ##### => # 8 | .#.#. => . 9 | ####. => . 10 | ###.. => . 11 | .#..# => # 12 | #..#. => # 13 | #.#.# => . 14 | #...# => # 15 | ..### => . 16 | ...## => # 17 | ##..# => # 18 | #.... => . 19 | .#.## => # 20 | #.### => # 21 | .##.# => # 22 | #..## => . 23 | .#... => # 24 | .###. => . 25 | ##... => # 26 | ##.## => # 27 | ##.#. => # 28 | #.##. => # 29 | .##.. => . 30 | ..#.# => . 31 | ....# => . 32 | ###.# => . 33 | ..... => . 34 | .#### => . 35 | -------------------------------------------------------------------------------- /6/1.in: -------------------------------------------------------------------------------- 1 | 66, 204 2 | 55, 226 3 | 231, 196 4 | 69, 211 5 | 69, 335 6 | 133, 146 7 | 321, 136 8 | 220, 229 9 | 148, 138 10 | 42, 319 11 | 304, 181 12 | 101, 329 13 | 72, 244 14 | 242, 117 15 | 83, 237 16 | 169, 225 17 | 311, 212 18 | 348, 330 19 | 233, 268 20 | 99, 301 21 | 142, 293 22 | 239, 288 23 | 200, 216 24 | 44, 215 25 | 353, 289 26 | 54, 73 27 | 73, 317 28 | 55, 216 29 | 305, 134 30 | 343, 233 31 | 227, 75 32 | 139, 285 33 | 264, 179 34 | 349, 263 35 | 48, 116 36 | 223, 60 37 | 247, 148 38 | 320, 232 39 | 60, 230 40 | 292, 78 41 | 247, 342 42 | 59, 326 43 | 333, 210 44 | 186, 291 45 | 218, 146 46 | 205, 246 47 | 124, 204 48 | 76, 121 49 | 333, 137 50 | 117, 68 -------------------------------------------------------------------------------- /8/2.py: -------------------------------------------------------------------------------- 1 | def metadata(tree): 2 | children,meta_count = head(tree),head(tree) 3 | 4 | meta_children = [] 5 | for _ in range(children): 6 | meta_children.append(metadata(tree)) 7 | 8 | meta = [] 9 | for _ in range(meta_count): 10 | meta.append(head(tree)) 11 | 12 | value = 0 13 | if children>0: 14 | for i in meta: 15 | if i>0 and i<=len(meta_children): 16 | value += meta_children[i-1] 17 | else: 18 | value = sum(meta) 19 | 20 | return value 21 | 22 | def head(tree): 23 | return next(tree) 24 | 25 | if __name__ == '__main__': #file_name = "test.in" 26 | # file_name = "test.in" 27 | file_name = "1.in" 28 | line = open(file_name, 'r').readline().rstrip() 29 | tree = map(int, line.split()) 30 | print(metadata(tree)) -------------------------------------------------------------------------------- /9/1.py: -------------------------------------------------------------------------------- 1 | import re 2 | from collections import deque 3 | 4 | def parse(line): 5 | matches = re.search("(\d+) players; last marble is worth (\d+) points", line) 6 | return (int(matches[1]),int(matches[2])) 7 | 8 | if __name__ == '__main__': 9 | # file_name = "test.in" 10 | file_name = "1.in" 11 | line = open(file_name, 'r').readline().rstrip() 12 | n_players,n_marbles = parse(line) 13 | 14 | players = {} 15 | for p in range(n_players): 16 | players[p] = 0 17 | 18 | circle = deque([0]) 19 | p = 0 20 | for i in range(1, n_marbles+1): 21 | if i%23 == 0: 22 | players[p] += i 23 | circle.rotate(7) # counter-clockwise 7 rotations 24 | players[p] += circle.popleft() 25 | else: 26 | circle.rotate(-2) #clockwise rotation 27 | circle.appendleft(i) 28 | # print(f'player:{p} {circle}') 29 | p = (p+1) % n_players 30 | print(max(players.values())) -------------------------------------------------------------------------------- /23/1.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | def parse(line): 4 | matches = re.search("pos=<([-+]?\d+),([-+]?\d+),([-+]?\d+)>, r=([-+]?\d+)", line) 5 | return (int(matches[1]), int(matches[2]), int(matches[3])), int(matches[4]) 6 | 7 | def manhattan_distance(a, b): 8 | x1,y1,z1 = a 9 | x2,y2,z2 = b 10 | return abs(x1-x2)+abs(y1-y2)+abs(z1-z2) 11 | 12 | if __name__ == '__main__': 13 | # file_name = "./23/test.in" 14 | file_name = "./23/1.in" 15 | lines = open(file_name, 'r').readlines() 16 | bots = [] 17 | for line in lines: 18 | coord,signal = parse(line.rstrip()) 19 | bots.append((coord, signal)) 20 | bots = sorted(bots, key=lambda x: x[1], reverse=True) #strength 21 | best_coord = bots[0][0] 22 | best_signal = bots[0][1] 23 | count = 0 24 | for bot in bots: 25 | coord = bot[0] 26 | signal = bot[1] 27 | count += 1 if manhattan_distance(best_coord, coord) <= best_signal else 0 28 | print(count) 29 | -------------------------------------------------------------------------------- /6/2.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | def parse(line): 4 | matches = re.search("(\d+), (\d+)", line) 5 | return (int(matches[1]), int(matches[2])) 6 | 7 | def distance(p1, p2): 8 | return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1]) 9 | 10 | if __name__ == '__main__': 11 | #file_name = "test.in" 12 | file_name = "1.in" 13 | lines = open(file_name, 'r').read().splitlines() 14 | points = list(map(parse, lines)) 15 | sort_x = list(sorted(points, key=lambda x: x[0])) 16 | sort_y = list(sorted(points, key=lambda x: x[1])) 17 | min_x = sort_x[0][0] 18 | max_x = sort_x[-1][0] 19 | min_y = sort_y[0][1] 20 | max_y = sort_y[-1][1] 21 | 22 | #print(min_x, max_x, min_y, max_y) 23 | 24 | region_s = 0 25 | limit = 10000 26 | #limit = 32 27 | for i in range(max_x): 28 | for j in range(max_y): 29 | total_d = 0 30 | for point in points: 31 | total_d += distance((i,j), point) 32 | if total_dpj: 20 | parents[pi] = pj 21 | 22 | def parse(line): 23 | return tuple(map(int, re.findall(r"(-?\d+)", line))) 24 | 25 | if __name__ == "__main__": 26 | # file_name = "./25/test.in" 27 | file_name = "./25/1.in" 28 | lines = open(file_name, 'r').readlines() 29 | points = [parse(line.rstrip()) for line in lines] 30 | n = len(points) 31 | parents = list(range(n)) 32 | 33 | for i in range(n): 34 | for j in range(i+1, n): 35 | if manhattan_distance(points[i], points[j]) <= 3: 36 | union(i, j, parents) 37 | 38 | constellation = set() 39 | for i in range(n): 40 | constellation.add(parent(i, parents)) 41 | 42 | print(len(constellation)) 43 | -------------------------------------------------------------------------------- /14/2.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | recipes = [3, 7] 3 | e1 = 0 4 | e2 = 1 5 | desired = 990941 6 | to_be_matched = 100000 7 | to_be_matched_digits = 6 8 | # desired = 59414 9 | # to_be_matched = 10000 10 | # to_be_matched_digits = 5 11 | matched = to_be_matched 12 | 13 | while True: 14 | # sum 15 | total = recipes[e1] + recipes[e2] 16 | 17 | # break down and append 18 | first,second = total//10,total%10 19 | if first>0: 20 | recipes.append(first) 21 | if (desired//matched)%10 == first: 22 | matched //= 10 23 | if matched == 0: 24 | break 25 | else: 26 | matched = to_be_matched 27 | recipes.append(second) 28 | if (desired//matched)%10 == second: 29 | matched //= 10 30 | if matched == 0: 31 | break 32 | else: 33 | matched = to_be_matched 34 | 35 | # move 36 | n = len(recipes) 37 | e1 = (e1+recipes[e1]+1)%n 38 | e2 = (e2+recipes[e2]+1)%n 39 | print(len(recipes)-to_be_matched_digits) -------------------------------------------------------------------------------- /15/1.in: -------------------------------------------------------------------------------- 1 | ################################ 2 | #######################...###### 3 | ######################...####### 4 | ##############...####..G######## 5 | #############....G...G..######## 6 | ############...#.......####..### 7 | ###########G.G##..#.G...###..### 8 | ##########....###.....G.G......# 9 | #########....##....GG..G..###..# 10 | ###########..#................## 11 | ###########..#...#G...........## 12 | ##########...............G.....# 13 | #####.#####...#####E.......E...# 14 | ####..#####..#######.....G..#### 15 | ##.G..####G.#########.E...E...## 16 | #...####....#########..........# 17 | #.G.####....#########..........# 18 | ##..####....#########..##......# 19 | ###.###.....#########G.....#.### 20 | ###.##...G...#######..E.....#### 21 | ###.....G.....#####E.......##### 22 | ###.......................###### 23 | ######..............E.........## 24 | ######......###................# 25 | #####.......##.................# 26 | #####.#....##......##........E## 27 | #######....######.##E.########## 28 | #######....#########..########## 29 | ######.....#########....######## 30 | ####.....###########..E.######## 31 | ####...#.###########....######## 32 | ################################ 33 | -------------------------------------------------------------------------------- /11/1.py: -------------------------------------------------------------------------------- 1 | def power(x, y, serialId): 2 | r = x + 10 3 | p = r * y 4 | p += serialId 5 | p *= r 6 | p = (p%1000)//100 7 | return p-5 8 | 9 | if __name__ == '__main__': 10 | serialId = 1788 11 | # serialId = 42 12 | cum_sum_square = {} 13 | for i in range(0, 301): 14 | cum_sum_square[(0,i)] = 0 15 | cum_sum_square[(i,0)] = 0 16 | 17 | for i in range(1, 301):#row(y) 18 | for j in range(1, 301):#col(x) 19 | # print(j,i) 20 | value = cum_sum_square[(j-1,i-1)] 21 | for k in range(1, j): 22 | value += power(k, i, serialId) 23 | for k in range(1, i): 24 | value += power(j, k, serialId) 25 | cum_sum_square[(j,i)] = value + power(j, i, serialId) 26 | 27 | largest_v = -1000000000 28 | largest_cord = None 29 | for i in range(1, 299): 30 | for j in range(1, 299): 31 | v = cum_sum_square[(j+2,i+2)] + cum_sum_square[(j-1,i-1)] - cum_sum_square[(j+2,i-1)] - cum_sum_square[(j-1,i+2)] 32 | if v>largest_v: 33 | largest_v = v 34 | largest_cord = (j,i) 35 | print(largest_cord, largest_v) -------------------------------------------------------------------------------- /10/test.in: -------------------------------------------------------------------------------- 1 | position=< 9, 1> velocity=< 0, 2> 2 | position=< 7, 0> velocity=<-1, 0> 3 | position=< 3, -2> velocity=<-1, 1> 4 | position=< 6, 10> velocity=<-2, -1> 5 | position=< 2, -4> velocity=< 2, 2> 6 | position=<-6, 10> velocity=< 2, -2> 7 | position=< 1, 8> velocity=< 1, -1> 8 | position=< 1, 7> velocity=< 1, 0> 9 | position=<-3, 11> velocity=< 1, -2> 10 | position=< 7, 6> velocity=<-1, -1> 11 | position=<-2, 3> velocity=< 1, 0> 12 | position=<-4, 3> velocity=< 2, 0> 13 | position=<10, -3> velocity=<-1, 1> 14 | position=< 5, 11> velocity=< 1, -2> 15 | position=< 4, 7> velocity=< 0, -1> 16 | position=< 8, -2> velocity=< 0, 1> 17 | position=<15, 0> velocity=<-2, 0> 18 | position=< 1, 6> velocity=< 1, 0> 19 | position=< 8, 9> velocity=< 0, -1> 20 | position=< 3, 3> velocity=<-1, 1> 21 | position=< 0, 5> velocity=< 0, -1> 22 | position=<-2, 2> velocity=< 2, 0> 23 | position=< 5, -2> velocity=< 1, 2> 24 | position=< 1, 4> velocity=< 2, 1> 25 | position=<-2, 7> velocity=< 2, -2> 26 | position=< 3, 6> velocity=<-1, -1> 27 | position=< 5, 0> velocity=< 1, 0> 28 | position=<-6, 0> velocity=< 2, 0> 29 | position=< 5, 9> velocity=< 1, -2> 30 | position=<14, 7> velocity=<-2, 0> 31 | position=<-3, 6> velocity=< 2, -1> -------------------------------------------------------------------------------- /11/2.py: -------------------------------------------------------------------------------- 1 | def power(x, y, serialId): 2 | r = x + 10 3 | p = r * y 4 | p += serialId 5 | p *= r 6 | p = (p%1000)//100 7 | return p-5 8 | 9 | if __name__ == '__main__': 10 | serialId = 1788 11 | # serialId = 42 12 | # serialId = 18 13 | cum_sum_square = {} 14 | for i in range(0, 301): 15 | cum_sum_square[(0,i)] = 0 16 | cum_sum_square[(i,0)] = 0 17 | 18 | for i in range(1, 301):#row(y) 19 | for j in range(1, 301):#col(x) 20 | # print(j,i) 21 | value = cum_sum_square[(j-1,i-1)] 22 | for k in range(1, j): 23 | value += power(k, i, serialId) 24 | for k in range(1, i): 25 | value += power(j, k, serialId) 26 | cum_sum_square[(j,i)] = value + power(j, i, serialId) 27 | 28 | largest_v = -1000000000 29 | largest_cord = None 30 | largest_s = 0 31 | for k in range(1, 301): 32 | for i in range(1, 301-k+1): 33 | for j in range(1, 301-k+1): 34 | v = cum_sum_square[(j+k-1,i+k-1)] + cum_sum_square[(j-1,i-1)] - cum_sum_square[(j+k-1,i-1)] - cum_sum_square[(j-1,i+k-1)] 35 | if v>largest_v: 36 | largest_v = v 37 | largest_cord = (j,i) 38 | largest_s = k 39 | print(largest_cord, largest_v, largest_s) -------------------------------------------------------------------------------- /22/1.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | class RegionType(object): 4 | Rock,Wet,Narrow = 0,1,2 5 | 6 | def get_type(position, erosion_level): 7 | return erosion_level[position] % 3 8 | 9 | def parse_depth(line): 10 | matches = re.search("depth: (\d+)", line) 11 | return matches[1] 12 | 13 | def parse_target(line): 14 | matches = re.search("target: (\d+),(\d+)", line) 15 | return (matches[1],matches[2]) 16 | 17 | if __name__ == '__main__': 18 | # file_name = "test.in" 19 | file_name = "1.in" 20 | lines = open(file_name, 'r').readlines() 21 | depth = int(parse_depth(lines[0])) 22 | target = tuple(map(int, parse_target(lines[1]))) 23 | start = (0,0) 24 | 25 | geo_index = {} 26 | erosion_level = {} 27 | for i in range(start[1], target[1]+1):#y 28 | for j in range(start[0], target[0]+1): #X 29 | if (i==0 and j==0) or (i==target[1] and j==target[0]): 30 | geo_index[(j,i)] = 0 31 | elif (i == 0): 32 | geo_index[(j,i)] = j*16807 33 | elif (j == 0): 34 | geo_index[(j,i)] = i*48271 35 | else: 36 | geo_index[(j,i)] = erosion_level[(j-1,i)] * erosion_level[(j,i-1)] 37 | erosion_level[(j,i)] = (geo_index[(j,i)] + depth) % 20183 38 | 39 | # risk 40 | print(sum((get_type(key, erosion_level) for key in erosion_level))) -------------------------------------------------------------------------------- /23/2.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | def parse(line): 4 | matches = re.search("pos=<([-+]?\d+),([-+]?\d+),([-+]?\d+)>, r=([-+]?\d+)", line) 5 | return (int(matches[1]), int(matches[2]), int(matches[3])), int(matches[4]) 6 | 7 | def manhattan_distance(a, b): 8 | x1,y1,z1 = a 9 | x2,y2,z2 = b 10 | return abs(x1-x2)+abs(y1-y2)+abs(z1-z2) 11 | 12 | if __name__ == '__main__': 13 | # file_name = "./23/test2.in" 14 | file_name = "./23/1.in" 15 | lines = open(file_name, 'r').readlines() 16 | 17 | # This is some crazy ass approximation. We are projecting all the points into a single dimensional 18 | # distance line and then checking which of those points is covered by the maximum number of bots 19 | 20 | # project all the points into a single dimentional distance line 21 | distance_line_points = [] 22 | for line in lines: 23 | coord,signal = parse(line.rstrip()) 24 | distance = manhattan_distance(coord, (0,0,0)) 25 | distance_line_points.append((max(0,distance-signal),distance+signal)) 26 | 27 | distances = {} 28 | for x,y in distance_line_points: 29 | distances[x] = 0 30 | distances[y] = 0 31 | 32 | for x in distances: 33 | for point in distance_line_points: 34 | if x<=point[1] and x>=point[0]: 35 | distances[x] += 1 36 | # it is highely likely that this answer won't be the correct one in that case, I would encourage to 37 | # try the next best point and so on.. 38 | print(sorted(distances, key=lambda x: (-distances[x],x))[0]) -------------------------------------------------------------------------------- /7/1.py: -------------------------------------------------------------------------------- 1 | import re 2 | from collections import deque 3 | from heapq import heapify 4 | from heapq import heappush 5 | from heapq import heappop 6 | 7 | def parse(line): 8 | matches = re.search("Step (\w) must be finished before step (\w) can begin.", line) 9 | return (matches[1], matches[2]) 10 | 11 | if __name__ == '__main__': 12 | #file_name = "test.in" 13 | file_name = "1.in" 14 | lines = open(file_name, 'r').read().splitlines() 15 | G = {} 16 | for line in lines: 17 | u,v = parse(line) 18 | if v not in G: 19 | G[v] = [] 20 | if u not in G: 21 | G[u] = [] 22 | G[u].append(v) 23 | 24 | # Kahn's algorithm 25 | incident_edges = {} 26 | for u in G: 27 | if u not in incident_edges: 28 | incident_edges[u] = 0 29 | for v in G[u]: 30 | if v not in incident_edges: 31 | incident_edges[v] = 0 32 | incident_edges[v] += 1 33 | 34 | frontier = [] 35 | for u,count in incident_edges.items(): 36 | if count == 0: 37 | frontier.append(u) 38 | heapify(frontier) 39 | 40 | steps = [] 41 | while len(frontier) > 0: 42 | u = heappop(frontier) 43 | steps.append(u) 44 | for v in G[u]: 45 | assert(incident_edges[v] > 0) 46 | incident_edges[v] -= 1 47 | if incident_edges[v] == 0: 48 | heappush(frontier, v) 49 | for u,count in incident_edges.items(): 50 | assert(count == 0) 51 | print(''.join(steps)) -------------------------------------------------------------------------------- /21/2.py: -------------------------------------------------------------------------------- 1 | # This program is same as 19.py with minor modifications in 2 | # Run this in pypy or a faster python interpreter than cpython as it is very slow in cpython 3 | 4 | import os 5 | import sys 6 | import re 7 | 8 | base_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 9 | # sys.path.append(os.path.join(base_path, "19")) 10 | sys.path.append(base_path) 11 | 12 | from importlib import import_module 13 | mod = __import__("19.1", fromlist="*") 14 | 15 | if __name__ == '__main__': 16 | # file_name = "test.in" 17 | file_name = "1.in" 18 | lines = open(file_name, 'r').readlines() 19 | 20 | memory = mod.Memory(6) 21 | cpu = mod.Cpu() 22 | 23 | # create program 24 | program = [] 25 | for line in lines[1:]: 26 | line = line.rstrip() 27 | command, *args = line.split() 28 | program.append((command, list(map(int, args)))) 29 | 30 | # init ip 31 | matches = re.search("#ip ([012345])", lines[0].rstrip()).groups() 32 | ip = memory.registers[int(matches[0])] 33 | 34 | n = len(program) 35 | repeats = set() 36 | last_repeat = -1 37 | while ip.value>=0 and ip.valuemin_x and point[0]min_y and point[1] ([.#])", line) 8 | return matches[1],matches[2] 9 | 10 | if __name__ == '__main__': 11 | # file_name = "test.in" 12 | file_name = "1.in" 13 | lines = open(file_name, 'r').readlines() 14 | initial_state = parse_state(lines[0]) 15 | spread_patterns = {} 16 | for i in range(2, len(lines)): 17 | pattern,spread = parse_spread(lines[i]) 18 | spread_patterns[pattern] = spread 19 | 20 | pots_with_plant = set() 21 | for i in range(len(initial_state)): 22 | if initial_state[i] == '#': 23 | pots_with_plant.add(i) 24 | 25 | # generations = 20 26 | generations = 50000000000 27 | for _ in range(generations): 28 | new_pots_with_plant = set() 29 | for pot_id in pots_with_plant: 30 | # find patterns where i is the index of the pot_id 31 | for i in range(5): 32 | pattern = ['.']*5 33 | pattern[i] = '#' 34 | for j in range(0, i): 35 | pattern[j] = '#' if ((pot_id-i+j) in pots_with_plant) else '.' 36 | for j in range(i+1, 5): 37 | pattern[j] = '#' if ((pot_id-i+j) in pots_with_plant) else '.' 38 | pattern = ''.join(pattern) 39 | if (pattern in spread_patterns) and spread_patterns[pattern] == '#': 40 | new_pot_with_plant_index = pot_id-i+2 41 | if new_pot_with_plant_index not in new_pots_with_plant: 42 | new_pots_with_plant.add(new_pot_with_plant_index) 43 | pots_with_plant = new_pots_with_plant 44 | 45 | print(sum(pots_with_plant)) -------------------------------------------------------------------------------- /12/2.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | def parse_state(line): 4 | return re.search("initial state: (.*)", line)[1] 5 | 6 | def parse_spread(line): 7 | matches = re.search("([.#]{5}) => ([.#])", line) 8 | return matches[1],matches[2] 9 | 10 | if __name__ == '__main__': 11 | # file_name = "test.in" 12 | file_name = "1.in" 13 | lines = open(file_name, 'r').readlines() 14 | initial_state = parse_state(lines[0]) 15 | spread_patterns = {} 16 | for i in range(2, len(lines)): 17 | pattern,spread = parse_spread(lines[i]) 18 | spread_patterns[pattern] = spread 19 | 20 | pots_with_plant = set() 21 | for i in range(len(initial_state)): 22 | if initial_state[i] == '#': 23 | pots_with_plant.add(i) 24 | 25 | generations = 1000 26 | # generations = 50000000000 27 | for _ in range(generations): 28 | new_pots_with_plant = set() 29 | for pot_id in pots_with_plant: 30 | # find patterns where i is the index of the pot_id 31 | for i in range(5): 32 | pattern = ['.']*5 33 | pattern[i] = '#' 34 | for j in range(0, i): 35 | pattern[j] = '#' if ((pot_id-i+j) in pots_with_plant) else '.' 36 | for j in range(i+1, 5): 37 | pattern[j] = '#' if ((pot_id-i+j) in pots_with_plant) else '.' 38 | pattern = ''.join(pattern) 39 | if (pattern in spread_patterns) and spread_patterns[pattern] == '#': 40 | new_pot_with_plant_index = pot_id-i+2 41 | if new_pot_with_plant_index not in new_pots_with_plant: 42 | new_pots_with_plant.add(new_pot_with_plant_index) 43 | pots_with_plant = new_pots_with_plant 44 | print((50000000000-generations)*55 + sum(pots_with_plant)) # a common difference of 55 shows up after 1000 iterations -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | .hypothesis/ 50 | .pytest_cache/ 51 | 52 | # Translations 53 | *.mo 54 | *.pot 55 | 56 | # Django stuff: 57 | *.log 58 | local_settings.py 59 | db.sqlite3 60 | 61 | # Flask stuff: 62 | instance/ 63 | .webassets-cache 64 | 65 | # Scrapy stuff: 66 | .scrapy 67 | 68 | # Sphinx documentation 69 | docs/_build/ 70 | 71 | # PyBuilder 72 | target/ 73 | 74 | # Jupyter Notebook 75 | .ipynb_checkpoints 76 | 77 | # IPython 78 | profile_default/ 79 | ipython_config.py 80 | 81 | # pyenv 82 | .python-version 83 | 84 | # celery beat schedule file 85 | celerybeat-schedule 86 | 87 | # SageMath parsed files 88 | *.sage.py 89 | 90 | # Environments 91 | .env 92 | .venv 93 | env/ 94 | venv/ 95 | ENV/ 96 | env.bak/ 97 | venv.bak/ 98 | 99 | # Spyder project settings 100 | .spyderproject 101 | .spyproject 102 | 103 | # Rope project settings 104 | .ropeproject 105 | 106 | # mkdocs documentation 107 | /site 108 | 109 | # mypy 110 | .mypy_cache/ 111 | .dmypy.json 112 | dmypy.json 113 | 114 | # Pyre type checker 115 | .pyre/ 116 | -------------------------------------------------------------------------------- /10/1.py: -------------------------------------------------------------------------------- 1 | import re 2 | import functools 3 | import sys 4 | 5 | def parse(line): 6 | matches = re.search("position=<\s*(-?\d+),\s*(-?\d+)> velocity=<\s*(-?\d+),\s*(-?\d+)>", line) 7 | return [(int(matches[1]),int(matches[2])), (int(matches[3]),int(matches[4]))] 8 | 9 | def project(point, velocity, time): 10 | displacement = (velocity[0]*time, velocity[1]*time) 11 | return (point[0]+displacement[0], point[1]+displacement[1]) 12 | 13 | def display(points, min_x, min_y, max_x, max_y): 14 | # print(min_x, max_x, min_y, max_y) 15 | for j in range(min_y, max_y+1): 16 | for i in range(min_x, max_x+1): 17 | if (i,j) in points: 18 | print('#', end='') 19 | else: 20 | print('.', end='') 21 | print() 22 | 23 | if __name__ == '__main__': 24 | # file_name = "test.in" 25 | file_name = "1.in" 26 | lines = open(file_name, 'r').readlines() 27 | points = [] 28 | for line in lines: 29 | points.append(parse(line)) 30 | 31 | time = 0 32 | INF = 1000000000000000000 33 | prev_spread = (INF, INF) 34 | prev_projections = None 35 | while True: 36 | projections = set() 37 | for point in points: 38 | p,v = point 39 | projections.add(project(p, v, time)) 40 | # print(projections) 41 | 42 | # compute minimals 43 | min_x = min(projections, key=lambda x: x[0])[0] 44 | min_y = min(projections, key=lambda x: x[1])[1] 45 | max_x = max(projections, key=lambda x: x[0])[0] 46 | max_y = max(projections, key=lambda x: x[1])[1] 47 | 48 | #measures cohesiveness 49 | spread = (max_x-min_x, max_y-min_y) 50 | if spread>prev_spread: 51 | display(prev_projections, min_x, min_y, max_x, max_y) 52 | print(f"seconds: {time-1}") 53 | sys.exit(0) 54 | prev_spread = spread 55 | prev_projections = projections 56 | 57 | time += 1 58 | 59 | -------------------------------------------------------------------------------- /7/2.py: -------------------------------------------------------------------------------- 1 | import re 2 | from collections import deque 3 | from heapq import heapify 4 | from heapq import heappush 5 | from heapq import heappop 6 | 7 | def parse(line): 8 | matches = re.search("Step (\w) must be finished before step (\w) can begin.", line) 9 | return (matches[1], matches[2]) 10 | 11 | base = 60 12 | def cost(item): 13 | return base + ord(item) - ord('A') + 1 14 | 15 | if __name__ == '__main__': 16 | # file_name = "test.in" 17 | file_name = "1.in" 18 | lines = open(file_name, 'r').read().splitlines() 19 | G = {} 20 | for line in lines: 21 | u,v = parse(line) 22 | if v not in G: 23 | G[v] = [] 24 | if u not in G: 25 | G[u] = [] 26 | G[u].append(v) 27 | 28 | # Kahn's algorithm 29 | incident_edges = {} 30 | for u in G: 31 | if u not in incident_edges: 32 | incident_edges[u] = 0 33 | for v in G[u]: 34 | if v not in incident_edges: 35 | incident_edges[v] = 0 36 | incident_edges[v] += 1 37 | 38 | frontier = [] 39 | max_queue = 5 40 | for u,count in incident_edges.items(): 41 | if count == 0: 42 | frontier.append([cost(u),u]) 43 | frontier,reserve = frontier[0:max_queue],frontier[max_queue:] 44 | heapify(frontier) 45 | heapify(reserve) 46 | 47 | time = 0 48 | while len(frontier) > 0: 49 | # print(time, frontier) 50 | c,u = heappop(frontier) 51 | time += c 52 | for step in frontier: 53 | step[0] -= c 54 | while len(frontier)0: 55 | heappush(frontier, heappop(reserve)) 56 | 57 | for v in G[u]: 58 | assert(incident_edges[v] > 0) 59 | incident_edges[v] -= 1 60 | if incident_edges[v] == 0: 61 | if len(frontier)=0 and adj[1]=0): 11 | topography[state[adj]] += 1 12 | return topography 13 | 14 | def scan_topography(m, n, state): 15 | topography = {Acre.Ground: 0, Acre.Tree: 0, Acre.Lumberyard: 0} 16 | for i in range(n): 17 | for j in range(m): 18 | topography[state[(i,j)]] += 1 19 | return topography 20 | 21 | def next_state(i, j, m, n, state): 22 | current = state[(i,j)] 23 | adjacents = scan_adjacents(i, j, m, n, state) 24 | ground_tree = lambda : Acre.Tree if (current == Acre.Ground and adjacents[Acre.Tree] >= 3) else current 25 | tree_lumberyard = lambda : Acre.Lumberyard if (current == Acre.Tree and adjacents[Acre.Lumberyard] >= 3) else current 26 | stay_lumberyard = lambda : (Acre.Lumberyard if adjacents[Acre.Lumberyard] >= 1 and adjacents[Acre.Tree] >= 1 else Acre.Ground) if (current == Acre.Lumberyard) else current 27 | 28 | if current == Acre.Ground: 29 | return ground_tree() 30 | if current == Acre.Tree: 31 | return tree_lumberyard() 32 | if current == Acre.Lumberyard: 33 | return stay_lumberyard() 34 | 35 | raise "Invalid state" 36 | 37 | if __name__ == '__main__': 38 | # file_name = "test.in" 39 | file_name = "1.in" 40 | lines = open(file_name, 'r').readlines() 41 | 42 | n = len(lines) #rows 43 | m = len(lines[0].rstrip()) #cols 44 | 45 | state = {} 46 | for i in range(n): 47 | for j in range(m): 48 | line = lines[i].rstrip() 49 | state[(i,j)] = line[j] 50 | 51 | for _ in range(10): 52 | new_state = {} 53 | for i in range(n): 54 | for j in range(m): 55 | new_state[(i,j)] = next_state(i, j, m, n, state) 56 | state = new_state 57 | 58 | topography = scan_topography(m, n, state) 59 | print(topography[Acre.Lumberyard]*topography[Acre.Tree]) -------------------------------------------------------------------------------- /18/2.py: -------------------------------------------------------------------------------- 1 | class Acre(object): 2 | Ground,Tree,Lumberyard = '.','|','#' 3 | 4 | adjacents = [(-1,-1), (-1,0), (-1,1), (0,-1), (0,1), (1,-1), (1,0), (1,1)] 5 | def scan_adjacents(i, j, m, n, state): 6 | topography = {Acre.Ground: 0, Acre.Tree: 0, Acre.Lumberyard: 0} 7 | for v in adjacents: 8 | dx,dy = v 9 | adj = (i+dx,j+dy) 10 | if (adj[0]=0 and adj[1]=0): 11 | topography[state[adj]] += 1 12 | return topography 13 | 14 | def scan_topography(m, n, state): 15 | topography = {Acre.Ground: 0, Acre.Tree: 0, Acre.Lumberyard: 0} 16 | for i in range(n): 17 | for j in range(m): 18 | topography[state[(i,j)]] += 1 19 | return topography 20 | 21 | def next_state(i, j, m, n, state): 22 | current = state[(i,j)] 23 | adjacents = scan_adjacents(i, j, m, n, state) 24 | ground_tree = lambda : Acre.Tree if (current == Acre.Ground and adjacents[Acre.Tree] >= 3) else current 25 | tree_lumberyard = lambda : Acre.Lumberyard if (current == Acre.Tree and adjacents[Acre.Lumberyard] >= 3) else current 26 | stay_lumberyard = lambda : (Acre.Lumberyard if adjacents[Acre.Lumberyard] >= 1 and adjacents[Acre.Tree] >= 1 else Acre.Ground) if (current == Acre.Lumberyard) else current 27 | 28 | if current == Acre.Ground: 29 | return ground_tree() 30 | if current == Acre.Tree: 31 | return tree_lumberyard() 32 | if current == Acre.Lumberyard: 33 | return stay_lumberyard() 34 | 35 | raise "Invalid state" 36 | 37 | if __name__ == '__main__': 38 | # file_name = "test.in" 39 | file_name = "1.in" 40 | lines = open(file_name, 'r').readlines() 41 | 42 | n = len(lines) #rows 43 | m = len(lines[0].rstrip()) #cols 44 | 45 | state = {} 46 | for i in range(n): 47 | for j in range(m): 48 | line = lines[i].rstrip() 49 | state[(i,j)] = line[j] 50 | 51 | for _ in range(1000): 52 | new_state = {} 53 | for i in range(n): 54 | for j in range(m): 55 | new_state[(i,j)] = next_state(i, j, m, n, state) 56 | state = new_state 57 | topography = scan_topography(m, n, state) 58 | print(topography) 59 | print(topography[Acre.Lumberyard]*topography[Acre.Tree]) 60 | # {'.': 1569, '|': 613, '#': 318} pattern is at 1000 and repeats after 28 iterations -------------------------------------------------------------------------------- /20/1.py: -------------------------------------------------------------------------------- 1 | import operator 2 | 3 | class Room(object): 4 | def __init__(self, location, distance): 5 | self.location = location 6 | self.distance = distance #measures no. of doors from origin 7 | 8 | class Markers(object): 9 | NavStart,NavEnd,SplitStart,SplitEnd,BranchEnd = ('^', '$', '(', ')', '|') 10 | 11 | directions = {'N': (0,-1), 'S': (0,1), 'E': (1,0), 'W': (-1,0)} #N,S,E,W 12 | 13 | def next_position(location, direction): 14 | return tuple(map(operator.add, location, direction)) 15 | 16 | def navigate(rooms, split_room, navigation_map, navigation_point): 17 | n = len(navigation_map) 18 | cur_room = split_room 19 | 20 | while navigation_point < n: 21 | d = navigation_map[navigation_point] 22 | if d == Markers.NavStart: 23 | room = Room((0,0), 0) 24 | rooms[(0,0)] = room 25 | cur_room = room 26 | elif d == Markers.NavEnd: 27 | assert(split_room == None) #assert we see NavEnd at the first level of recursion 28 | return navigation_point 29 | elif d == Markers.SplitStart: 30 | navigation_point = navigate(rooms, cur_room, navigation_map, navigation_point+1) 31 | elif d == Markers.SplitEnd: 32 | assert(split_room != None) #assert we see SplitEnd at the second or higher levels of recursion 33 | return navigation_point 34 | elif d == Markers.BranchEnd: 35 | cur_room = split_room 36 | elif d in directions: 37 | # door; don't care 38 | position = next_position(cur_room.location, directions[d]) 39 | 40 | # room 41 | position = next_position(position, directions[d]) 42 | room = Room(position, cur_room.distance+1) 43 | if position in rooms: 44 | room.distance = min(rooms[position].distance, room.distance) #shortest distance 45 | rooms[position] = room 46 | cur_room = room 47 | else: 48 | raise "Unknown nav point" 49 | navigation_point += 1 50 | 51 | if __name__ == '__main__': 52 | # file_name = "test.in" 53 | file_name = "1.in" 54 | 55 | rooms = {} 56 | navigation_map = open(file_name, 'r').readline().rstrip() 57 | navigate(rooms, None, navigation_map, 0) 58 | # part 1 59 | print(max(rooms[room].distance for room in rooms)) 60 | # part 2 61 | print(len([room for room in rooms if (rooms[room].distance >= 1000)])) 62 | -------------------------------------------------------------------------------- /24/1.in: -------------------------------------------------------------------------------- 1 | Immune System: 2 | 4592 units each with 2061 hit points (immune to slashing, radiation; weak to cold) with an attack that does 4 fire damage at initiative 9 3 | 1383 units each with 3687 hit points with an attack that does 26 radiation damage at initiative 15 4 | 2736 units each with 6429 hit points (immune to slashing) with an attack that does 20 slashing damage at initiative 2 5 | 777 units each with 3708 hit points (immune to radiation, cold; weak to slashing, fire) with an attack that does 39 cold damage at initiative 4 6 | 6761 units each with 2792 hit points (immune to bludgeoning, fire, cold, slashing) with an attack that does 3 radiation damage at initiative 17 7 | 6028 units each with 5537 hit points (immune to slashing) with an attack that does 7 radiation damage at initiative 6 8 | 2412 units each with 2787 hit points with an attack that does 9 bludgeoning damage at initiative 20 9 | 6042 units each with 7747 hit points (immune to radiation) with an attack that does 12 slashing damage at initiative 12 10 | 1734 units each with 7697 hit points (weak to radiation, cold) with an attack that does 38 cold damage at initiative 10 11 | 4391 units each with 3250 hit points with an attack that does 7 cold damage at initiative 19 12 | Infection: 13 | 820 units each with 46229 hit points (immune to cold, bludgeoning) with an attack that does 106 slashing damage at initiative 18 14 | 723 units each with 30757 hit points (weak to bludgeoning) with an attack that does 80 fire damage at initiative 3 15 | 2907 units each with 51667 hit points (weak to slashing; immune to bludgeoning) with an attack that does 32 fire damage at initiative 1 16 | 2755 units each with 49292 hit points (weak to bludgeoning) with an attack that does 34 fire damage at initiative 5 17 | 5824 units each with 24708 hit points (immune to bludgeoning, cold, radiation, slashing) with an attack that does 7 bludgeoning damage at initiative 11 18 | 7501 units each with 6943 hit points (weak to cold; immune to slashing) with an attack that does 1 radiation damage at initiative 8 19 | 573 units each with 10367 hit points (weak to slashing, cold) with an attack that does 30 radiation damage at initiative 16 20 | 84 units each with 31020 hit points (weak to cold) with an attack that does 639 slashing damage at initiative 14 21 | 2063 units each with 31223 hit points (immune to bludgeoning; weak to radiation) with an attack that does 25 cold damage at initiative 13 22 | 214 units each with 31088 hit points (weak to fire) with an attack that does 271 slashing damage at initiative 7 -------------------------------------------------------------------------------- /18/1.in: -------------------------------------------------------------------------------- 1 | ............|#.|..|..|#.#.....#.#||.#.#...#.|#.... 2 | |...|.##...#.|..||#.##..###...|..#||#|.....|..|... 3 | #.|.#..||#..|.|..|..|.....##....#.##||..#|.|.....| 4 | .##||.|..#.......###||.#.#.|..##.#|..#...#.....#.| 5 | ....#|##|.|.|...|||..|...#.......|#..|#|.|..|#|... 6 | |....|...#.....|#||...#.....#....#|....|.....|.... 7 | .#||..|##.##|..||.#.....#...|##..|#...#.#.|.#.|##. 8 | ..#|##..|......#|..#.|#.##....|.....|..#.#...|...# 9 | #....#||.|..|..#..#.|........|.|.....||||.|..|.... 10 | |.#|.|...#..|||#.##|#.........|...#..#.|#.....||.| 11 | .#.##.........|...|.|.#..|.|##...|.|#.||....||.#.. 12 | #.#.....##|.#|..###..|........|.....|.....|#.||.#| 13 | |..||....#..###.|..#..#.#.......##.#.|.#..|.|.#|.# 14 | |...##.#..#|..|..|......#..#......|..|..#.....|.|| 15 | .......||#|.|...##.#.##..|#.|.|#|....##||...#.#.|# 16 | ..|###..|.....#|.|.|.|....|....#.#..##|...||...... 17 | |.|#|.#|||#.|#|#..|...#.|..|..#.#...#..#.#.#.#..#. 18 | ...#.###...#............#..|#...||#|..#..|###...|. 19 | .|......|...#....#.......|...##.|.|..##.#...#||||. 20 | #...|.#|.|.......|##.#...|#.|.........#.|.|##.||.. 21 | |.|#..#.||#|.|..|..|#........#..#.....#.#..#.#.|.. 22 | #..|.|...#|#..#|....|...|..|#|....|..##|#|......|| 23 | ....||...|....|...#|..|.#|.....#.|..||..|...|..... 24 | #......#.#..##.|#.|||.|#||||.|...#...|#.|#...||... 25 | .|...|...|.#..|#.|####|.......|.#||.|..|..|..#.#.. 26 | .#.|##.......|||...#..#.#....#..|..#.###........#. 27 | #.#..|.##..|...#....#.#.|...|.#.|.....|.|......|#. 28 | #.||.#......#.....##.|...|#..#.#|..#..|..#..#.#.|. 29 | |...#|#...|....#|##..|....||....#.||||.|#...|..... 30 | .|...|.|...|...|..|..#|...||||#.#...|.#....##...|. 31 | .|.#...#|...#||.#....|##.#|..#|||......|.|..||...| 32 | |#...|.|..|.#...#..||......|.|.##.....||#|#.#|..|. 33 | ..#.|.###......|.|.###|...#.#|#||....#..|....|#..| 34 | |....|.|.|#.|.#..|.|.#.#.||..##|..|.||#|..|...||.. 35 | #.|#.|....|#|#.|..#...|...|.#.#.....#...#|###.#..# 36 | ...###|.#....#..#..|.|....#|.|.###.|...|..|.##.|#. 37 | ...#....#|.#|#.|#.|#|.|...|.....#..|......|.||###. 38 | .||#|.|.#.|..|||.#.|..#.....#..|..###||#|||...#..# 39 | ###||#........#|####.|..|#....#|.|.|.|#|.|.#|.##.| 40 | |..#.#|....#....|.#.|..|...|..#..|....#.###.|.#|#. 41 | .#..##|##...#.....#||||#.#...||..|........|#...... 42 | .#.|||#.|...#.#.|.|..|......#.#....##|..|#||....## 43 | ...##..|....|#.||......##...#..||##.##.#..#.|##|.. 44 | ..#.||...|#..||#....#|.##.#|.........#...||.|#|#|# 45 | #.......|.|#...##.#..#|#.|.|.|.##|...#...|...#.#.. 46 | .....||......|...#..|......||.|#..#....##|...#...# 47 | ..#|.#....|.......#.#..##......|.#.|..|..#..#.#.|| 48 | .|.....#...#......#...#..||||#|.....||..|....#|... 49 | #...#.||..#......|.##|#.....|..|..|..|.......|.||. 50 | ..|#.|......||.|.||.|##|||.|..#.......#|||.#.|.|#| 51 | -------------------------------------------------------------------------------- /13/1.py: -------------------------------------------------------------------------------- 1 | # Objective is to simulate the ride and find crash spot 2 | # Model : Car, Track 3 | # Car -> Heading(N-Dec y & cons X (0,-1) to position,S,E,W), fork state 4 | # Track -> Kind, location 5 | 6 | # Simulation 7 | # List of cars and enumerated in order until crash 8 | # Notion of a crash 9 | # increment in direction of heading? - Add the heading to position 10 | # Loop until a crash 11 | 12 | # refer to a map for left in the context of heading. Have a heading -> left,straight,right 13 | 14 | import sys 15 | 16 | class Cart(object): 17 | def __init__(self, position, heading): 18 | self.position = position 19 | self.heading = heading 20 | self.next_fork = 0 21 | 22 | N = (0,-1) 23 | S = (0,1) 24 | E = (1,0) 25 | W = (-1,0) 26 | intersection_guide = { 27 | N: [W, N, E], # N -> L,S,R 28 | S: [E, S, W], # S -> L,S,R 29 | E: [N, E, S], # E -> L,S,R 30 | W: [S, W, N], # W -> L,S,R 31 | } 32 | track_guide = { 33 | '|': {N:N, S:S}, # N stays N & S stays S 34 | '-': {E:E, W:W}, # E stays E & W stays W 35 | '/':{W:S, N:E, E:N, S:W}, # W turns S & N turns E 36 | '\\':{E:S, N:W, W:N, S:E} # E turns S & N turns W 37 | } 38 | 39 | def crash(cart, carts): 40 | for c in carts: 41 | if c != cart and c.position == cart.position: 42 | return True 43 | return False 44 | 45 | if __name__ == '__main__': 46 | file_name = "test.in" 47 | # file_name = "1.in" 48 | lines = open(file_name, 'r').readlines() 49 | track = {} 50 | carts = [] 51 | for y in range(len(lines)): 52 | for x in range(len(lines[0])): 53 | t = lines[y][x] 54 | if t == '>' or t == '<': 55 | track[(x,y)] = '-' 56 | c = Cart((x,y), E if t=='>' else W) 57 | carts.append(c) 58 | elif t == '^' or t == 'v': 59 | track[(x,y)] = '|' 60 | c = Cart((x,y), N if t=='^' else S) 61 | carts.append(c) 62 | else: 63 | if ord(t) != '': 64 | track[(x,y)] = t 65 | while True: 66 | for cart in carts: 67 | # change position 68 | cart.position = (cart.position[0]+cart.heading[0], cart.position[1]+cart.heading[1]) 69 | 70 | #change.heading 71 | t = track[cart.position] 72 | if t in track_guide: 73 | cart.heading = track_guide[t][cart.heading] 74 | else: 75 | assert(t == '+') 76 | cart.heading = intersection_guide[cart.heading][cart.next_fork] 77 | cart.next_fork = (cart.next_fork+1)%3 78 | 79 | if crash(cart, carts): 80 | print(cart.position) 81 | sys.exit(0) -------------------------------------------------------------------------------- /17/2.py: -------------------------------------------------------------------------------- 1 | import operator 2 | import sys 3 | import re 4 | 5 | sys.setrecursionlimit(10000) 6 | 7 | class AreaType(object): 8 | Clay,Sand,StillWater,MovingWater = 0,1,2,3 9 | 10 | def parse(line): 11 | matches = re.search("(\w)=(\d+), (\w)=(\d+)..(\d+)", line) 12 | return {matches[1]: (int(matches[2]),int(matches[2])), matches[3]: (int(matches[4]),int(matches[5]))} 13 | 14 | def down(point): 15 | return tuple(map(operator.add, point, [0,1])) 16 | 17 | def left(point): 18 | return tuple(map(operator.add, point, [-1,0])) 19 | 20 | def right(point): 21 | return tuple(map(operator.add, point, [1,0])) 22 | 23 | def get_area_type(point): 24 | return region[point] if point in region else AreaType.Sand 25 | 26 | def fill_internal(point, min_y, max_y): 27 | # down 28 | d = down(point) 29 | if (min_y <= d[1] <= max_y) and get_area_type(d) == AreaType.Sand: 30 | region[d] = AreaType.MovingWater 31 | fill_internal(d, min_y, max_y) 32 | 33 | # left 34 | l = left(point) 35 | left_bound = None 36 | if (get_area_type(d) == AreaType.StillWater or get_area_type(d) == AreaType.Clay): 37 | if (get_area_type(l) == AreaType.Sand): 38 | region[l] = AreaType.MovingWater 39 | left_bound = fill_internal(l, min_y, max_y) 40 | elif (get_area_type(l) == AreaType.Clay): 41 | left_bound = l[0] 42 | 43 | # right 44 | r = right(point) 45 | right_bound = None 46 | if (get_area_type(d) == AreaType.StillWater or get_area_type(d) == AreaType.Clay): 47 | if (get_area_type(r) == AreaType.Sand): 48 | region[r] = AreaType.MovingWater 49 | right_bound = fill_internal(r, min_y, max_y) 50 | elif (get_area_type(r) == AreaType.Clay): 51 | right_bound = r[0] 52 | 53 | if left_bound and right_bound: 54 | for i in range(left_bound, right_bound): 55 | if region[(i,point[1])] == AreaType.MovingWater: 56 | region[(i,point[1])] = AreaType.StillWater 57 | return None 58 | 59 | return left_bound if left_bound else right_bound 60 | 61 | def fill(region): 62 | min_y = min(region.keys(), key=lambda p: p[1])[1] 63 | max_y = max(region.keys(), key=lambda p: p[1])[1] 64 | starting = (500,min_y) 65 | region[starting] = AreaType.MovingWater 66 | fill_internal(starting, min_y, max_y) 67 | 68 | if __name__ == '__main__': 69 | # file_name = "./17/test.in" 70 | file_name = "./17/1.in" 71 | lines = open(file_name, 'r').readlines() 72 | region = {} 73 | 74 | for line in lines: 75 | area = parse(line) 76 | for j in range(area['y'][0], area['y'][1]+1): 77 | for i in range(area['x'][0], area['x'][1]+1): 78 | region[(i,j)] = AreaType.Clay 79 | 80 | fill(region) 81 | result = list(filter(lambda x: region[x] == AreaType.StillWater, region)) 82 | print(len(result)) 83 | -------------------------------------------------------------------------------- /13/2.py: -------------------------------------------------------------------------------- 1 | # Objective is to simulate the ride and find crash spot 2 | # Model : Car, Track 3 | # Car -> Heading(N-Dec y & cons X (0,-1) to position,S,E,W), fork state 4 | # Track -> Kind, location 5 | 6 | # Simulation 7 | # List of cars and enumerated in order until crash 8 | # Notion of a crash 9 | # increment in direction of heading? - Add the heading to position 10 | # Loop until a crash 11 | 12 | # refer to a map for left in the context of heading. Have a heading -> left,straight,right 13 | 14 | import sys 15 | 16 | class Cart(object): 17 | def __init__(self, position, heading): 18 | self.position = position 19 | self.heading = heading 20 | self.next_fork = 0 21 | 22 | N = (0,-1) 23 | S = (0,1) 24 | E = (1,0) 25 | W = (-1,0) 26 | intersection_guide = { 27 | N: [W, N, E], # N -> L,S,R 28 | S: [E, S, W], # S -> L,S,R 29 | E: [N, E, S], # E -> L,S,R 30 | W: [S, W, N], # W -> L,S,R 31 | } 32 | track_guide = { 33 | '|': {N:N, S:S}, # N stays N & S stays S 34 | '-': {E:E, W:W}, # E stays E & W stays W 35 | '/':{W:S, N:E, E:N, S:W}, # W turns S & N turns E 36 | '\\':{E:S, N:W, W:N, S:E} # E turns S & N turns W 37 | } 38 | 39 | def crash(cart, carts): 40 | for c in carts: 41 | if c != cart and c.position == cart.position: 42 | return c 43 | return None 44 | 45 | if __name__ == '__main__': 46 | # file_name = "test2.in" 47 | file_name = "1.in" 48 | lines = open(file_name, 'r').readlines() 49 | track = {} 50 | carts = [] 51 | for y in range(len(lines)): 52 | for x in range(len(lines[0])): 53 | t = lines[y][x] 54 | if t == '>' or t == '<': 55 | track[(x,y)] = '-' 56 | c = Cart((x,y), E if t=='>' else W) 57 | carts.append(c) 58 | elif t == '^' or t == 'v': 59 | track[(x,y)] = '|' 60 | c = Cart((x,y), N if t=='^' else S) 61 | carts.append(c) 62 | else: 63 | if ord(t) != '': 64 | track[(x,y)] = t 65 | # print(carts) 66 | # print(track) 67 | remaining_carts = set(carts) 68 | while len(remaining_carts)>1: 69 | for cart in carts: 70 | if cart in remaining_carts: 71 | # change position 72 | cart.position = (cart.position[0]+cart.heading[0], cart.position[1]+cart.heading[1]) 73 | 74 | #change.heading 75 | t = track[cart.position] 76 | if t in track_guide: 77 | cart.heading = track_guide[t][cart.heading] 78 | else: 79 | assert(t == '+') 80 | cart.heading = intersection_guide[cart.heading][cart.next_fork] 81 | cart.next_fork = (cart.next_fork+1)%3 82 | 83 | crashed = crash(cart, remaining_carts) 84 | if crashed: 85 | # print(remaining_carts) 86 | remaining_carts.remove(cart) 87 | remaining_carts.remove(crashed) 88 | # for cart in carts: 89 | # print(cart.position, end =' ') 90 | # print() 91 | print((remaining_carts.pop()).position) -------------------------------------------------------------------------------- /17/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | After thinking for a long time, I think the best way is to do a DFS approach exploring the flow of water. 3 | Atleast the major states of the system should be captured - clay, sand & moving water. 4 | We can start from the source and explore every node 5 | Every node has three actions is has to take- go down, go left, go right. 6 | You can go down only when there is sand 7 | You can go left only if the left node has clay or still water down 8 | You can only go right if the right node has a clay or still water down 9 | When you are bounded on left or right you can mark the side you are bounded. 10 | This can get cascaded and finally the parent that has both left and right marked can mark that entire span to be bounded. This makes a still water 11 | ''' 12 | 13 | import operator 14 | import sys 15 | import re 16 | 17 | sys.setrecursionlimit(10000) 18 | 19 | class AreaType(object): 20 | Clay,Sand,StillWater,MovingWater = 0,1,2,3 21 | 22 | def parse(line): 23 | matches = re.search("(\w)=(\d+), (\w)=(\d+)..(\d+)", line) 24 | return {matches[1]: (int(matches[2]),int(matches[2])), matches[3]: (int(matches[4]),int(matches[5]))} 25 | 26 | def down(point): 27 | return tuple(map(operator.add, point, [0,1])) 28 | 29 | def left(point): 30 | return tuple(map(operator.add, point, [-1,0])) 31 | 32 | def right(point): 33 | return tuple(map(operator.add, point, [1,0])) 34 | 35 | def get_area_type(point): 36 | return region[point] if point in region else AreaType.Sand 37 | 38 | def fill_internal(point, min_y, max_y): 39 | # down 40 | d = down(point) 41 | if (min_y <= d[1] <= max_y) and get_area_type(d) == AreaType.Sand: 42 | region[d] = AreaType.MovingWater 43 | fill_internal(d, min_y, max_y) 44 | 45 | # left 46 | l = left(point) 47 | left_bound = None 48 | if (get_area_type(d) == AreaType.StillWater or get_area_type(d) == AreaType.Clay): 49 | if (get_area_type(l) == AreaType.Sand): 50 | region[l] = AreaType.MovingWater 51 | left_bound = fill_internal(l, min_y, max_y) 52 | elif (get_area_type(l) == AreaType.Clay): 53 | left_bound = l[0] 54 | 55 | # right 56 | r = right(point) 57 | right_bound = None 58 | if (get_area_type(d) == AreaType.StillWater or get_area_type(d) == AreaType.Clay): 59 | if (get_area_type(r) == AreaType.Sand): 60 | region[r] = AreaType.MovingWater 61 | right_bound = fill_internal(r, min_y, max_y) 62 | elif (get_area_type(r) == AreaType.Clay): 63 | right_bound = r[0] 64 | 65 | if left_bound and right_bound: 66 | for i in range(left_bound, right_bound): 67 | if region[(i,point[1])] == AreaType.MovingWater: 68 | region[(i,point[1])] = AreaType.StillWater 69 | return None 70 | 71 | return left_bound if left_bound else right_bound 72 | 73 | def fill(region): 74 | min_y = min(region.keys(), key=lambda p: p[1])[1] 75 | max_y = max(region.keys(), key=lambda p: p[1])[1] 76 | starting = (500,min_y) 77 | region[starting] = AreaType.MovingWater 78 | fill_internal(starting, min_y, max_y) 79 | 80 | if __name__ == '__main__': 81 | # file_name = "./17/test.in" 82 | file_name = "./17/1.in" 83 | lines = open(file_name, 'r').readlines() 84 | region = {} 85 | 86 | for line in lines: 87 | area = parse(line) 88 | for j in range(area['y'][0], area['y'][1]+1): 89 | for i in range(area['x'][0], area['x'][1]+1): 90 | region[(i,j)] = AreaType.Clay 91 | 92 | fill(region) 93 | result = list(filter(lambda x: region[x] == AreaType.StillWater or region[x] == AreaType.MovingWater, region)) 94 | print(len(result)) 95 | -------------------------------------------------------------------------------- /19/1.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | class Register(object): 4 | def __init__(self): 5 | self.value = 0 6 | 7 | class Memory(object): 8 | def __init__(self, capacity): 9 | self.registers = [] 10 | for _ in range(capacity): 11 | self.registers.append(Register()) 12 | 13 | class Cpu(object): 14 | def __init__(self): 15 | self.all_fns = [self.addr, self.addi, self.mulr, self.muli, self.banr, \ 16 | self.bani, self.borr, self.bori, self.setr, self.seti, self.gtir, self.gtri, self.gtrr, self.eqir, self.eqri, self.eqrr] 17 | 18 | def addr(self, memory, a, b, c): 19 | memory.registers[c].value = memory.registers[a].value + memory.registers[b].value 20 | 21 | def addi(self, memory, a, b, c): 22 | memory.registers[c].value = memory.registers[a].value + b 23 | 24 | def mulr(self, memory, a, b, c): 25 | memory.registers[c].value = memory.registers[a].value * memory.registers[b].value 26 | 27 | def muli(self, memory, a, b, c): 28 | memory.registers[c].value = memory.registers[a].value * b 29 | 30 | def banr(self, memory, a, b, c): 31 | memory.registers[c].value = memory.registers[a].value & memory.registers[b].value 32 | 33 | def bani(self, memory, a, b, c): 34 | memory.registers[c].value = memory.registers[a].value & b 35 | 36 | def borr(self, memory, a, b, c): 37 | memory.registers[c].value = memory.registers[a].value | memory.registers[b].value 38 | 39 | def bori(self, memory, a, b, c): 40 | memory.registers[c].value = memory.registers[a].value | b 41 | 42 | def setr(self, memory, a, b, c): 43 | memory.registers[c].value = memory.registers[a].value 44 | 45 | def seti(self, memory, a, b, c): 46 | memory.registers[c].value = a 47 | 48 | def gtir(self, memory, a, b, c): 49 | memory.registers[c].value = 1 if a>memory.registers[b].value else 0 50 | 51 | def gtri(self, memory, a, b, c): 52 | memory.registers[c].value = 1 if memory.registers[a].value>b else 0 53 | 54 | def gtrr(self, memory, a, b, c): 55 | memory.registers[c].value = 1 if memory.registers[a].value>memory.registers[b].value else 0 56 | 57 | def eqir(self, memory, a, b, c): 58 | memory.registers[c].value = 1 if a==memory.registers[b].value else 0 59 | 60 | def eqri(self, memory, a, b, c): 61 | memory.registers[c].value = 1 if memory.registers[a].value==b else 0 62 | 63 | def eqrr(self, memory, a, b, c): 64 | memory.registers[c].value = 1 if memory.registers[a].value==memory.registers[b].value else 0 65 | 66 | def _find(self, value, iterable, key): 67 | for e in iterable: 68 | if (key(e) == value): 69 | return e 70 | 71 | def execute(self, command, memory, a, b, c): 72 | fn = self._find(command, self.all_fns, lambda x: x.__name__) 73 | return fn(memory, a, b, c) 74 | 75 | def get_memory(memory): 76 | return (list(map(lambda x: x.value, memory.registers))) 77 | 78 | if __name__ == '__main__': 79 | # file_name = "test.in" 80 | file_name = "1.in" 81 | lines = open(file_name, 'r').readlines() 82 | 83 | memory = Memory(6) 84 | cpu = Cpu() 85 | 86 | # create program 87 | program = [] 88 | for line in lines[1:]: 89 | line = line.rstrip() 90 | command, *args = line.split() 91 | program.append((command, list(map(int, args)))) 92 | 93 | # init ip 94 | matches = re.search("#ip ([012345])", lines[0].rstrip()) 95 | ip = memory.registers[int(matches[1])] 96 | 97 | n = len(program) 98 | while ip.value>=0 and ip.valuememory.registers[b] else 0 56 | 57 | def gtri(self, memory, a, b, c): 58 | memory.registers[c] = 1 if memory.registers[a]>b else 0 59 | 60 | def gtrr(self, memory, a, b, c): 61 | memory.registers[c] = 1 if memory.registers[a]>memory.registers[b] else 0 62 | 63 | def eqir(self, memory, a, b, c): 64 | memory.registers[c] = 1 if a==memory.registers[b] else 0 65 | 66 | def eqri(self, memory, a, b, c): 67 | memory.registers[c] = 1 if memory.registers[a]==b else 0 68 | 69 | def eqrr(self, memory, a, b, c): 70 | memory.registers[c] = 1 if memory.registers[a]==memory.registers[b] else 0 71 | 72 | def parse_before(line): 73 | matches = re.search("Before: \[([0123]), ([0123]), ([0123]), ([0123])\]", line) 74 | values = [matches[1], matches[2], matches[3], matches[4]] 75 | return [int(v) for v in values] 76 | 77 | def parse_after(line): 78 | matches = re.search("After: \[([0123]), ([0123]), ([0123]), ([0123])\]", line) 79 | values = [matches[1], matches[2], matches[3], matches[4]] 80 | return [int(v) for v in values] 81 | 82 | if __name__ == '__main__': 83 | # file_name = "test.in" 84 | file_name = "1.in" 85 | lines = open(file_name, 'r').readlines() 86 | n = len(lines) 87 | i = 0 88 | memory = Memory(4) 89 | cpu = Cpu() 90 | total_samples_gt_3 = 0 91 | while i=3 else 0 111 | 112 | i += 1 113 | print(total_samples_gt_3) -------------------------------------------------------------------------------- /24/1.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | class Group(object): 4 | def __init__(self, units, hit_point, attack_damage, attack_type, initiative, weaknesses, immunities): 5 | self.hit_point = hit_point 6 | self.attack_damage = attack_damage 7 | self.attack_type = attack_type 8 | self.initiative = initiative 9 | self.weaknesses = weaknesses 10 | self.immunities = immunities 11 | self.units = units 12 | 13 | @property 14 | def effective_power(self): 15 | return self.units * self.attack_damage 16 | 17 | def hit(self, damage): 18 | units_damaged = damage // self.hit_point 19 | self.units = max(0, self.units-units_damaged) 20 | 21 | def get_target_selection_order(groups): 22 | # groups has units 23 | def score(group): 24 | return (group.effective_power, group.initiative) 25 | 26 | return sorted(groups, key=lambda x: score(x), reverse=True) 27 | 28 | def select_target(attacking_group, defending_army): 29 | def score(defending_group): 30 | damage = attacking_group.effective_power * (2 if attacking_group.attack_type in defending_group.weaknesses else 1) 31 | return (damage, defending_group.effective_power, defending_group.initiative) 32 | 33 | potential_targets = (group for group in defending_army if attacking_group.attack_type not in group.immunities) 34 | targets = sorted(potential_targets, key=lambda x: score(x), reverse=True) 35 | return targets[0] if len(targets)>0 else None 36 | 37 | def get_attack_order(groups): 38 | def score(group): 39 | return (group.initiative) 40 | 41 | return sorted(groups, key=lambda x: score(x), reverse=True) 42 | 43 | def attack(attacking_group, defending_group): 44 | if not (attacking_group and defending_group): 45 | return 46 | damage = attacking_group.effective_power * (2 if attacking_group.attack_type in defending_group.weaknesses else 1) 47 | defending_group.hit(damage) 48 | 49 | def parse(line): 50 | required = re.search(r"(\d+) units each with (\d+) hit points.*with an attack that does (\d+) (\w+) damage at initiative (\d+)", line) 51 | immune = re.search(r"immune to (.*?)[;\)]", line) 52 | immunity = [] 53 | if immune: 54 | text = immune.groups()[0] 55 | immunity = re.findall(r"(\w+)", text) 56 | weak = re.search(r"weak to (.*?)\)", line) 57 | weakness = [] 58 | if weak: 59 | text = weak.groups()[0] 60 | weakness = re.findall(r"(\w+)", text) 61 | return int(required[1]),int(required[2]),int(required[3]),required[4],int(required[5]),weakness,immunity 62 | 63 | if __name__ == "__main__": 64 | # file_name = "./24/test.in" 65 | file_name = "./24/1.in" 66 | lines = open(file_name, 'r').readlines() 67 | 68 | immune_army = set() 69 | infect_army = set() 70 | current_army = None 71 | for line in lines: 72 | line = line.rstrip() 73 | if "Immune System" in line: 74 | current_army = immune_army 75 | continue 76 | if "Infection" in line: 77 | current_army = infect_army 78 | continue 79 | values = parse(line) 80 | current_army.add(Group(*values)) 81 | 82 | while len(immune_army)>0 and len(infect_army)>0: 83 | groups = immune_army.union(infect_army) 84 | targets = {} 85 | # select 86 | for attacking_group in get_target_selection_order(groups): 87 | defending_army = immune_army if attacking_group in infect_army else infect_army 88 | unchosen_targets = (group for group in defending_army if group not in targets.values()) 89 | defending_group = select_target(attacking_group, unchosen_targets) 90 | targets[attacking_group] = defending_group 91 | 92 | # attack 93 | for attacking_group in get_attack_order(groups): 94 | defending_group = targets[attacking_group] 95 | attack(attacking_group, defending_group) 96 | 97 | # prune 98 | immune_army = set((group for group in immune_army if group.units>0)) 99 | infect_army = set((group for group in infect_army if group.units>0)) 100 | 101 | # of the army should have 0 units 102 | print(sum(group.units for group in immune_army) + sum(group.units for group in infect_army)) -------------------------------------------------------------------------------- /22/2.py: -------------------------------------------------------------------------------- 1 | import heapq 2 | import operator 3 | import re 4 | 5 | class RegionType(object): 6 | Rock,Wet,Narrow = 0,1,2 7 | 8 | class Tool(object): 9 | Torch,Climber,Neither = 0,1,2 10 | 11 | def get_type(position, erosion_level): 12 | return erosion_level[position] % 3 13 | 14 | def parse_depth(line): 15 | matches = re.search("depth: (\d+)", line) 16 | return matches[1] 17 | 18 | def parse_target(line): 19 | matches = re.search("target: (\d+),(\d+)", line) 20 | return (matches[1],matches[2]) 21 | 22 | def shortest_path_djikstra(source, target, erosion_level): 23 | # helper methods 24 | INF = 10000000000 25 | distance = {} 26 | visited_edges = set() 27 | supported_equipments = { 28 | RegionType.Rock : [Tool.Climber, Tool.Torch], 29 | RegionType.Wet : [Tool.Climber, Tool.Neither], 30 | RegionType.Narrow : [Tool.Torch, Tool.Neither] 31 | } 32 | total_explored_edges_to_target = 0 #we exit when we have explored all 4 edges to reach the target 33 | best_equipments = {} 34 | 35 | def relax(u, v): 36 | nonlocal total_explored_edges_to_target 37 | 38 | to_type = get_type(v, erosion_level) 39 | equipments = best_equipments[u] 40 | usable_equipments = set([equipment for equipment in equipments if can_use_equipment(equipment, to_type)]) 41 | cost = 1 if len(usable_equipments)>0 else 8 # None of the equipments can be used and hence have to eat the cost of 42 | usable_equipments = usable_equipments if len(usable_equipments)>0 else set(supported_equipments[to_type]) #swap to one of the supported equipment type 43 | 44 | if v == target or u == target: 45 | total_explored_edges_to_target += 1 46 | if get_distance(u)+cost == get_distance(v): 47 | best_equipments[v] = best_equipments[v].union(usable_equipments) 48 | elif get_distance(u)+cost < get_distance(v): 49 | best_equipments[v] = usable_equipments.copy() 50 | distance[v] = distance[u]+cost 51 | return (True, distance[v]) 52 | 53 | return (False, None) 54 | 55 | def can_use_equipment(equipment, region_type): 56 | return equipment in supported_equipments[region_type] 57 | 58 | def get_distance(u): 59 | return distance[u] if u in distance else INF 60 | 61 | directions = [(0,-1), (0,1), (1,0), (-1,0)] #N,S,E,W 62 | def get_adjacents(u): 63 | for direction in directions: 64 | v = tuple(map(operator.add, u, direction)) 65 | if (v[0]>=0 and v[1]>=0): 66 | yield v 67 | 68 | # Djikstra 69 | distance[source] = 0 70 | best_equipments[source] = set([Tool.Torch]) 71 | pq = [(distance[source], source)] 72 | while total_explored_edges_to_target < 4: 73 | d,u = heapq.heappop(pq) 74 | 75 | if d > get_distance(u): # lazy deletion because we already found a shorter path to that node 76 | continue 77 | 78 | for v in get_adjacents(u): 79 | if not ((u,v) in visited_edges or (v,u) in visited_edges): 80 | visited_edges.add((u,v)) 81 | relaxed,cost = relax(u, v) 82 | if relaxed: 83 | heapq.heappush(pq, (cost, v)) 84 | 85 | return distance[target] + (0 if Tool.Torch in best_equipments[target] else 7) 86 | 87 | if __name__ == '__main__': 88 | # file_name = "test.in" 89 | file_name = "1.in" 90 | lines = open(file_name, 'r').readlines() 91 | depth = int(parse_depth(lines[0])) 92 | target = tuple(map(int, parse_target(lines[1]))) 93 | start = (0,0) 94 | 95 | additional_coverage = 700#Since the terrain can extend beyond problem 1 this is just a approximation 96 | geo_index = {} 97 | erosion_level = {} 98 | for i in range(start[1], target[1]+additional_coverage):#y 99 | for j in range(start[0], target[0]+additional_coverage): #X 100 | if (i==0 and j==0) or (i==target[1] and j==target[0]): 101 | geo_index[(j,i)] = 0 102 | elif (i == 0): 103 | geo_index[(j,i)] = j*16807 104 | elif (j == 0): 105 | geo_index[(j,i)] = i*48271 106 | else: 107 | geo_index[(j,i)] = erosion_level[(j-1,i)] * erosion_level[(j,i-1)] 108 | erosion_level[(j,i)] = (geo_index[(j,i)] + depth) % 20183 109 | 110 | print(shortest_path_djikstra(start, target, erosion_level)) -------------------------------------------------------------------------------- /19/2.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | class Register(object): 4 | def __init__(self): 5 | self.value = 0 6 | 7 | class Memory(object): 8 | def __init__(self, capacity): 9 | self.registers = [] 10 | for _ in range(capacity): 11 | self.registers.append(Register()) 12 | 13 | class Cpu(object): 14 | def __init__(self): 15 | self.all_fns = [self.addr, self.addi, self.mulr, self.muli, self.banr, \ 16 | self.bani, self.borr, self.bori, self.setr, self.seti, self.gtir, self.gtri, self.gtrr, self.eqir, self.eqri, self.eqrr] 17 | 18 | def addr(self, memory, a, b, c): 19 | memory.registers[c].value = memory.registers[a].value + memory.registers[b].value 20 | 21 | def addi(self, memory, a, b, c): 22 | memory.registers[c].value = memory.registers[a].value + b 23 | 24 | def mulr(self, memory, a, b, c): 25 | memory.registers[c].value = memory.registers[a].value * memory.registers[b].value 26 | 27 | def muli(self, memory, a, b, c): 28 | memory.registers[c].value = memory.registers[a].value * b 29 | 30 | def banr(self, memory, a, b, c): 31 | memory.registers[c].value = memory.registers[a].value & memory.registers[b].value 32 | 33 | def bani(self, memory, a, b, c): 34 | memory.registers[c].value = memory.registers[a].value & b 35 | 36 | def borr(self, memory, a, b, c): 37 | memory.registers[c].value = memory.registers[a].value | memory.registers[b].value 38 | 39 | def bori(self, memory, a, b, c): 40 | memory.registers[c].value = memory.registers[a].value | b 41 | 42 | def setr(self, memory, a, b, c): 43 | memory.registers[c].value = memory.registers[a].value 44 | 45 | def seti(self, memory, a, b, c): 46 | memory.registers[c].value = a 47 | 48 | def gtir(self, memory, a, b, c): 49 | memory.registers[c].value = 1 if a>memory.registers[b].value else 0 50 | 51 | def gtri(self, memory, a, b, c): 52 | memory.registers[c].value = 1 if memory.registers[a].value>b else 0 53 | 54 | def gtrr(self, memory, a, b, c): 55 | memory.registers[c].value = 1 if memory.registers[a].value>memory.registers[b].value else 0 56 | 57 | def eqir(self, memory, a, b, c): 58 | memory.registers[c].value = 1 if a==memory.registers[b].value else 0 59 | 60 | def eqri(self, memory, a, b, c): 61 | memory.registers[c].value = 1 if memory.registers[a].value==b else 0 62 | 63 | def eqrr(self, memory, a, b, c): 64 | memory.registers[c].value = 1 if memory.registers[a].value==memory.registers[b].value else 0 65 | 66 | def _find(self, value, iterable, key): 67 | for e in iterable: 68 | if (key(e) == value): 69 | return e 70 | 71 | def execute(self, command, memory, a, b, c): 72 | fn = self._find(command, self.all_fns, lambda x: x.__name__) 73 | return fn(memory, a, b, c) 74 | 75 | def get_memory(memory): 76 | return (list(map(lambda x: x.value, memory.registers))) 77 | 78 | if __name__ == '__main__': 79 | # file_name = "test.in" 80 | file_name = "1.in" 81 | lines = open(file_name, 'r').readlines() 82 | 83 | # create program 84 | program = [] 85 | for line in lines[1:]: 86 | line = line.rstrip() 87 | command, *args = line.split() 88 | program.append((command, list(map(int, args)))) 89 | 90 | # A simulation for register 0 with the helper program below. The helper program was determined after observing the loop in which the program spends a fortune amount of time 91 | # _0value = 0 92 | # for _1value in range(1, total): 93 | # _5value = total // _1value 94 | # if _5value*_1value == total: 95 | # _0value += _1value 96 | # print(_0value) 97 | 98 | # The following states were determined 99 | # ip:9 [4401637, 10551274, 9, 10551276, 10551275, 0] ('gtrr', [3, 4, 5]) 100 | # More advanced than previous 101 | # ip:9 [14952912, 10551275, 9, 10551276, 10551275, 0] ('gtrr', [3, 4, 5]) 102 | memory = Memory(6) 103 | cpu = Cpu() 104 | 105 | memory.registers[0].value = 14952912 106 | memory.registers[1].value = 10551275 107 | memory.registers[2].value = 9 108 | memory.registers[3].value = 10551276 109 | memory.registers[4].value = 10551275 110 | memory.registers[5].value = 0 111 | 112 | ip = memory.registers[2] 113 | 114 | n = len(program) 115 | while ip.value>=0 and ip.value0 else None 36 | 37 | def get_attack_order(groups): 38 | def score(group): 39 | return (group.initiative) 40 | 41 | return sorted(groups, key=lambda x: score(x), reverse=True) 42 | 43 | def attack(attacking_group, defending_group): 44 | if not (attacking_group and defending_group): 45 | return 46 | damage = attacking_group.effective_power * (2 if attacking_group.attack_type in defending_group.weaknesses else 1) 47 | defending_group.hit(damage) 48 | 49 | def parse(line): 50 | required = re.search(r"(\d+) units each with (\d+) hit points.*with an attack that does (\d+) (\w+) damage at initiative (\d+)", line) 51 | immune = re.search(r"immune to (.*?)[;\)]", line) 52 | immunity = [] 53 | if immune: 54 | text = immune.groups()[0] 55 | immunity = re.findall(r"(\w+)", text) 56 | weak = re.search(r"weak to (.*?)\)", line) 57 | weakness = [] 58 | if weak: 59 | text = weak.groups()[0] 60 | weakness = re.findall(r"(\w+)", text) 61 | return int(required[1]),int(required[2]),int(required[3]),required[4],int(required[5]),weakness,immunity 62 | 63 | def solve_part_1(lines, boost): 64 | immune_army = set() 65 | infect_army = set() 66 | current_army = None 67 | for line in lines: 68 | line = line.rstrip() 69 | if "Immune System" in line: 70 | current_army = immune_army 71 | continue 72 | if "Infection" in line: 73 | current_army = infect_army 74 | continue 75 | values = parse(line) 76 | current_army.add(Group(*values)) 77 | 78 | # boost 79 | for group in immune_army: 80 | group.attack_damage += boost 81 | 82 | while len(immune_army)>0 and len(infect_army)>0: 83 | groups = immune_army.union(infect_army) 84 | targets = {} 85 | # select 86 | for attacking_group in get_target_selection_order(groups): 87 | defending_army = immune_army if attacking_group in infect_army else infect_army 88 | unchosen_targets = (group for group in defending_army if group not in targets.values()) 89 | defending_group = select_target(attacking_group, unchosen_targets) 90 | targets[attacking_group] = defending_group 91 | 92 | # no attack possible 93 | if len([v for v in targets.values() if v]) == 0: 94 | raise "stalemate" 95 | 96 | # attack 97 | for attacking_group in get_attack_order(groups): 98 | defending_group = targets[attacking_group] 99 | attack(attacking_group, defending_group) 100 | 101 | # prune 102 | immune_army = set((group for group in immune_army if group.units>0)) 103 | infect_army = set((group for group in infect_army if group.units>0)) 104 | 105 | return immune_army 106 | 107 | if __name__ == "__main__": 108 | # file_name = "./24/test.in" 109 | file_name = "./24/1.in" 110 | lines = open(file_name, 'r').readlines() 111 | 112 | boost_min = 1 113 | boost_max = 50000 #guestimate 114 | 115 | # binary search the optimal boost 116 | while boost_min0: # won 126 | boost_max = boost 127 | else: # lost 128 | boost_min = boost+1 129 | 130 | result = sum(group.units for group in solve_part_1(lines, boost_max)) # boost_max is the best 131 | assert(result>0) #wrong guesstimate 132 | print(result) -------------------------------------------------------------------------------- /7/1.in: -------------------------------------------------------------------------------- 1 | Step C must be finished before step P can begin. 2 | Step V must be finished before step Q can begin. 3 | Step T must be finished before step X can begin. 4 | Step B must be finished before step U can begin. 5 | Step Z must be finished before step O can begin. 6 | Step P must be finished before step I can begin. 7 | Step D must be finished before step G can begin. 8 | Step A must be finished before step Y can begin. 9 | Step R must be finished before step O can begin. 10 | Step J must be finished before step E can begin. 11 | Step N must be finished before step S can begin. 12 | Step X must be finished before step H can begin. 13 | Step F must be finished before step L can begin. 14 | Step S must be finished before step I can begin. 15 | Step W must be finished before step Q can begin. 16 | Step H must be finished before step K can begin. 17 | Step K must be finished before step Q can begin. 18 | Step E must be finished before step L can begin. 19 | Step Q must be finished before step O can begin. 20 | Step U must be finished before step G can begin. 21 | Step L must be finished before step O can begin. 22 | Step Y must be finished before step G can begin. 23 | Step G must be finished before step I can begin. 24 | Step M must be finished before step I can begin. 25 | Step I must be finished before step O can begin. 26 | Step A must be finished before step N can begin. 27 | Step H must be finished before step O can begin. 28 | Step T must be finished before step O can begin. 29 | Step H must be finished before step U can begin. 30 | Step A must be finished before step I can begin. 31 | Step B must be finished before step R can begin. 32 | Step V must be finished before step T can begin. 33 | Step H must be finished before step M can begin. 34 | Step C must be finished before step A can begin. 35 | Step B must be finished before step G can begin. 36 | Step L must be finished before step Y can begin. 37 | Step T must be finished before step J can begin. 38 | Step A must be finished before step R can begin. 39 | Step X must be finished before step L can begin. 40 | Step B must be finished before step L can begin. 41 | Step A must be finished before step F can begin. 42 | Step K must be finished before step O can begin. 43 | Step W must be finished before step M can begin. 44 | Step Z must be finished before step N can begin. 45 | Step Z must be finished before step S can begin. 46 | Step R must be finished before step K can begin. 47 | Step Q must be finished before step L can begin. 48 | Step G must be finished before step O can begin. 49 | Step F must be finished before step Y can begin. 50 | Step V must be finished before step H can begin. 51 | Step E must be finished before step I can begin. 52 | Step W must be finished before step Y can begin. 53 | Step U must be finished before step I can begin. 54 | Step F must be finished before step K can begin. 55 | Step M must be finished before step O can begin. 56 | Step Z must be finished before step H can begin. 57 | Step X must be finished before step S can begin. 58 | Step J must be finished before step O can begin. 59 | Step B must be finished before step I can begin. 60 | Step F must be finished before step H can begin. 61 | Step D must be finished before step U can begin. 62 | Step E must be finished before step M can begin. 63 | Step Z must be finished before step X can begin. 64 | Step P must be finished before step L can begin. 65 | Step W must be finished before step H can begin. 66 | Step C must be finished before step D can begin. 67 | Step A must be finished before step X can begin. 68 | Step Q must be finished before step I can begin. 69 | Step R must be finished before step Y can begin. 70 | Step B must be finished before step A can begin. 71 | Step N must be finished before step L can begin. 72 | Step H must be finished before step G can begin. 73 | Step Y must be finished before step M can begin. 74 | Step L must be finished before step G can begin. 75 | Step G must be finished before step M can begin. 76 | Step Z must be finished before step R can begin. 77 | Step S must be finished before step Q can begin. 78 | Step P must be finished before step J can begin. 79 | Step V must be finished before step J can begin. 80 | Step J must be finished before step I can begin. 81 | Step J must be finished before step X can begin. 82 | Step W must be finished before step O can begin. 83 | Step B must be finished before step F can begin. 84 | Step R must be finished before step M can begin. 85 | Step V must be finished before step S can begin. 86 | Step H must be finished before step E can begin. 87 | Step E must be finished before step U can begin. 88 | Step R must be finished before step W can begin. 89 | Step X must be finished before step Q can begin. 90 | Step N must be finished before step G can begin. 91 | Step T must be finished before step I can begin. 92 | Step L must be finished before step M can begin. 93 | Step H must be finished before step I can begin. 94 | Step U must be finished before step M can begin. 95 | Step C must be finished before step H can begin. 96 | Step P must be finished before step H can begin. 97 | Step J must be finished before step F can begin. 98 | Step A must be finished before step O can begin. 99 | Step X must be finished before step M can begin. 100 | Step H must be finished before step L can begin. 101 | Step W must be finished before step K can begin. -------------------------------------------------------------------------------- /16/2.py: -------------------------------------------------------------------------------- 1 | # Problem is about finding samples that match 3 or more opcodes 2 | # For each sample 3 | # Enumerate thru all the opcode implementations by passing it the notion of a "register" 4 | # Check the register value "C" after execution and see if that matches the expected output 5 | # If match, then increment that there is an opcode match 6 | 7 | import re 8 | from functools import reduce 9 | 10 | class Memory(object): 11 | def __init__(self, capacity): 12 | self.registers = [0] * capacity 13 | 14 | class Cpu(object): 15 | def __init__(self): 16 | self.all_fns = [self.addr, self.addi, self.mulr, self.muli, self.banr, \ 17 | self.bani, self.borr, self.bori, self.setr, self.seti, self.gtir, self.gtri, self.gtrr, self.eqir, self.eqri, self.eqrr] 18 | 19 | def addr(self, memory, a, b, c): 20 | memory.registers[c] = memory.registers[a] + memory.registers[b] 21 | 22 | def addi(self, memory, a, b, c): 23 | memory.registers[c] = memory.registers[a] + b 24 | 25 | def mulr(self, memory, a, b, c): 26 | memory.registers[c] = memory.registers[a] * memory.registers[b] 27 | 28 | def muli(self, memory, a, b, c): 29 | memory.registers[c] = memory.registers[a] * b 30 | 31 | def banr(self, memory, a, b, c): 32 | memory.registers[c] = memory.registers[a] & memory.registers[b] 33 | 34 | def bani(self, memory, a, b, c): 35 | memory.registers[c] = memory.registers[a] & b 36 | 37 | def borr(self, memory, a, b, c): 38 | memory.registers[c] = memory.registers[a] | memory.registers[b] 39 | 40 | def bori(self, memory, a, b, c): 41 | memory.registers[c] = memory.registers[a] | b 42 | 43 | def setr(self, memory, a, b, c): 44 | memory.registers[c] = memory.registers[a] 45 | 46 | def seti(self, memory, a, b, c): 47 | memory.registers[c] = a 48 | 49 | def gtir(self, memory, a, b, c): 50 | memory.registers[c] = 1 if a>memory.registers[b] else 0 51 | 52 | def gtri(self, memory, a, b, c): 53 | memory.registers[c] = 1 if memory.registers[a]>b else 0 54 | 55 | def gtrr(self, memory, a, b, c): 56 | memory.registers[c] = 1 if memory.registers[a]>memory.registers[b] else 0 57 | 58 | def eqir(self, memory, a, b, c): 59 | memory.registers[c] = 1 if a==memory.registers[b] else 0 60 | 61 | def eqri(self, memory, a, b, c): 62 | memory.registers[c] = 1 if memory.registers[a]==b else 0 63 | 64 | def eqrr(self, memory, a, b, c): 65 | memory.registers[c] = 1 if memory.registers[a]==memory.registers[b] else 0 66 | 67 | def parse_before(line): 68 | matches = re.search("Before: \[([0123]), ([0123]), ([0123]), ([0123])\]", line) 69 | values = [matches[1], matches[2], matches[3], matches[4]] 70 | return [int(v) for v in values] 71 | 72 | def parse_after(line): 73 | matches = re.search("After: \[([0123]), ([0123]), ([0123]), ([0123])\]", line) 74 | values = [matches[1], matches[2], matches[3], matches[4]] 75 | return [int(v) for v in values] 76 | 77 | def converge(opcode_fn_map, opcode, used_fns): 78 | # base case; all opcodes satisfied 79 | if opcode >= len(opcode_fn_map): 80 | return (True, {}) 81 | 82 | for fn in opcode_fn_map[opcode]: 83 | if fn not in used_fns: 84 | used_fns.add(fn) 85 | result,state = converge(opcode_fn_map, opcode+1, used_fns) 86 | if result: 87 | state[opcode] = fn 88 | return (True, state) 89 | used_fns.remove(fn) 90 | 91 | return (False, None) 92 | 93 | def find(value, iterable, key): 94 | for e in iterable: 95 | if (key(e) == value): 96 | return e 97 | 98 | if __name__ == '__main__': 99 | # file_name = "test.in" 100 | file_name = "1.in" 101 | lines = open(file_name, 'r').readlines() 102 | n = len(lines) 103 | 104 | opcode_fn_map = {} 105 | for i in range(16): 106 | opcode_fn_map[i] = [] 107 | 108 | # explore possibilities for opcode 109 | i = 0 110 | memory = Memory(4) 111 | cpu = Cpu() 112 | while i E,G -> to track : attack power, hit point, position 6 | Board -> Position (x,y), Type (wall, player, space) 7 | Game is about move and attack 8 | All units move 9 | After all units have moved/attacked a round ends 10 | Movement 11 | For every unit 12 | Identify range 13 | Just shortest path from the player. Shortest path also resolves with reading order 14 | Choose in range 15 | pick the nearest one - sort by y and then by x. 16 | Attack 17 | If enemy in range then attack 18 | deduct 3 from enemy hit point 19 | ''' 20 | from collections import deque 21 | from functools import cmp_to_key 22 | 23 | class UnitType(object): 24 | Goblin,Elf = 0,1 25 | 26 | class Unit(object): 27 | def __init__(self, type, position): 28 | self.type = type 29 | self.position = position 30 | self.attack_power = 3 31 | self.hit_count = 200 32 | 33 | direction = [(-1,0), (0,-1), (0,1), (1,0)] #T,L,R,B 34 | def distance(unit_position, board): 35 | d = {} 36 | p = {} 37 | e = set() 38 | 39 | d[unit_position] = 0 40 | p[unit_position] = unit_position 41 | e.add(unit_position) 42 | 43 | q = deque([unit_position]) 44 | while len(q)>0: 45 | parent = q.popleft() 46 | for heading in direction: 47 | child = (parent[0]+heading[0], parent[1]+heading[1]) 48 | if board[child] == '.' and child not in e: 49 | q.append(child) 50 | d[child] = 1+d[parent] 51 | p[child] = parent 52 | e.add(child) 53 | 54 | return d,p 55 | 56 | def compare(x,y): 57 | return (x>y) - (x E,G -> to track : attack power, hit point, position 6 | Board -> Position (x,y), Type (wall, player, space) 7 | Game is about move and attack 8 | All units move 9 | After all units have moved/attacked a round ends 10 | Movement 11 | For every unit 12 | Identify range 13 | Just shortest path from the player. Shortest path also resolves with reading order 14 | Choose in range 15 | pick the nearest one - sort by y and then by x. 16 | Attack 17 | If enemy in range then attack 18 | deduct 3 from enemy hit point 19 | ''' 20 | from collections import deque 21 | from functools import cmp_to_key 22 | 23 | class UnitType(object): 24 | Goblin,Elf = 0,1 25 | 26 | class Unit(object): 27 | def __init__(self, type, position): 28 | self.type = type 29 | self.position = position 30 | self.attack_power = 3 31 | self.hit_count = 200 32 | 33 | direction = [(-1,0), (0,-1), (0,1), (1,0)] #T,L,R,B 34 | def distance(unit_position, board): 35 | d = {} 36 | p = {} 37 | e = set() 38 | 39 | d[unit_position] = 0 40 | p[unit_position] = unit_position 41 | e.add(unit_position) 42 | 43 | q = deque([unit_position]) 44 | while len(q)>0: 45 | parent = q.popleft() 46 | for heading in direction: 47 | child = (parent[0]+heading[0], parent[1]+heading[1]) 48 | if board[child] == '.' and child not in e: 49 | q.append(child) 50 | d[child] = 1+d[parent] 51 | p[child] = parent 52 | e.add(child) 53 | 54 | return d,p 55 | 56 | def compare(x,y): 57 | return (x>y) - (x velocity=< 3, -1> 2 | position=< 32025, -10468> velocity=<-3, 1> 3 | position=< 32018, -31724> velocity=<-3, 3> 4 | position=< 21393, -52982> velocity=<-2, 5> 5 | position=< 42645, 10793> velocity=<-4, -1> 6 | position=<-21111, -10461> velocity=< 2, 1> 7 | position=< 21436, -10468> velocity=<-2, 1> 8 | position=< 42695, -10468> velocity=<-4, 1> 9 | position=< 21388, -10463> velocity=<-2, 1> 10 | position=<-31720, -42355> velocity=< 3, 4> 11 | position=< 10800, -31725> velocity=<-1, 3> 12 | position=< 32052, 42691> velocity=<-3, -4> 13 | position=< 10808, 53314> velocity=<-1, -5> 14 | position=< 42690, -21097> velocity=<-4, 2> 15 | position=< 32060, -52979> velocity=<-3, 5> 16 | position=< 32007, -31728> velocity=<-3, 3> 17 | position=< 10808, 21423> velocity=<-1, -2> 18 | position=<-31760, -21095> velocity=< 3, 2> 19 | position=<-21111, -42353> velocity=< 2, 4> 20 | position=<-10457, -21096> velocity=< 1, 2> 21 | position=<-53001, -10466> velocity=< 5, 1> 22 | position=< 32052, -31728> velocity=<-3, 3> 23 | position=< 32047, -21098> velocity=<-3, 2> 24 | position=< 21395, 42691> velocity=<-2, -4> 25 | position=<-53009, -31727> velocity=< 5, 3> 26 | position=<-53017, 21428> velocity=< 5, -2> 27 | position=<-21135, -52986> velocity=< 2, 5> 28 | position=<-21140, 32061> velocity=< 2, -3> 29 | position=< 10774, 53316> velocity=<-1, -5> 30 | position=< 42653, -52984> velocity=<-4, 5> 31 | position=<-53033, 53318> velocity=< 5, -5> 32 | position=<-53001, 53313> velocity=< 5, -5> 33 | position=< 42685, -42353> velocity=<-4, 4> 34 | position=<-21135, -52981> velocity=< 2, 5> 35 | position=<-31733, -31720> velocity=< 3, 3> 36 | position=<-21082, 10795> velocity=< 2, -1> 37 | position=<-52972, 21423> velocity=< 5, -2> 38 | position=<-21087, 10800> velocity=< 2, -1> 39 | position=< 10806, -21098> velocity=<-1, 2> 40 | position=< 21406, 42691> velocity=<-2, -4> 41 | position=< 21409, -10468> velocity=<-2, 1> 42 | position=<-53013, -52988> velocity=< 5, 5> 43 | position=<-31745, -31721> velocity=< 3, 3> 44 | position=< 42681, 21425> velocity=<-4, -2> 45 | position=< 21378, -21089> velocity=<-2, 2> 46 | position=< 53286, 32052> velocity=<-5, -3> 47 | position=<-52982, 21422> velocity=< 5, -2> 48 | position=<-10484, 21431> velocity=< 1, -2> 49 | position=<-53001, 21431> velocity=< 5, -2> 50 | position=< 32066, -52988> velocity=<-3, 5> 51 | position=< 32060, -21090> velocity=<-3, 2> 52 | position=< 42673, -10464> velocity=<-4, 1> 53 | position=<-42378, -21091> velocity=< 4, 2> 54 | position=<-21110, -31728> velocity=< 2, 3> 55 | position=< 21389, 21429> velocity=<-2, -2> 56 | position=< 10755, 21424> velocity=<-1, -2> 57 | position=<-31725, -42357> velocity=< 3, 4> 58 | position=< 21437, 42686> velocity=<-2, -4> 59 | position=<-31721, 53318> velocity=< 3, -5> 60 | position=<-10502, -42354> velocity=< 1, 4> 61 | position=< 42642, -31719> velocity=<-4, 3> 62 | position=< 21379, 42691> velocity=<-2, -4> 63 | position=<-52973, -52988> velocity=< 5, 5> 64 | position=<-42359, 42685> velocity=< 4, -4> 65 | position=<-53017, -31725> velocity=< 5, 3> 66 | position=<-21143, -52982> velocity=< 2, 5> 67 | position=< 32051, -31725> velocity=<-3, 3> 68 | position=<-53001, 42685> velocity=< 5, -4> 69 | position=<-42379, 42682> velocity=< 4, -4> 70 | position=<-31757, -52985> velocity=< 3, 5> 71 | position=<-31765, -52988> velocity=< 3, 5> 72 | position=<-10460, -52987> velocity=< 1, 5> 73 | position=< 42678, -42356> velocity=<-4, 4> 74 | position=<-53004, -21090> velocity=< 5, 2> 75 | position=< 53311, 53319> velocity=<-5, -5> 76 | position=<-53017, -42350> velocity=< 5, 4> 77 | position=<-10501, 21429> velocity=< 1, -2> 78 | position=< 42669, 42688> velocity=<-4, -4> 79 | position=< 53275, 32059> velocity=<-5, -3> 80 | position=< 21387, 10796> velocity=<-2, -1> 81 | position=< 21418, 10795> velocity=<-2, -1> 82 | position=<-21092, 42687> velocity=< 2, -4> 83 | position=<-42359, -10462> velocity=< 4, 1> 84 | position=<-21118, 42684> velocity=< 2, -4> 85 | position=< 10764, -10459> velocity=<-1, 1> 86 | position=< 42682, 32053> velocity=<-4, -3> 87 | position=< 42653, -42350> velocity=<-4, 4> 88 | position=<-31738, -31724> velocity=< 3, 3> 89 | position=<-10469, 10794> velocity=< 1, -1> 90 | position=<-31725, -42358> velocity=< 3, 4> 91 | position=<-10456, 21426> velocity=< 1, -2> 92 | position=< 21417, -10459> velocity=<-2, 1> 93 | position=<-42385, 10801> velocity=< 4, -1> 94 | position=< 10792, -52987> velocity=<-1, 5> 95 | position=< 21401, 32053> velocity=<-2, -3> 96 | position=<-31712, -10466> velocity=< 3, 1> 97 | position=< 32016, -42354> velocity=<-3, 4> 98 | position=< 32049, 53316> velocity=<-3, -5> 99 | position=<-10494, -42349> velocity=< 1, 4> 100 | position=<-52977, -10459> velocity=< 5, 1> 101 | position=<-31773, 10798> velocity=< 3, -1> 102 | position=< 10776, -10468> velocity=<-1, 1> 103 | position=< 21385, 32059> velocity=<-2, -3> 104 | position=<-10462, -52988> velocity=< 1, 5> 105 | position=< 10795, -42351> velocity=<-1, 4> 106 | position=<-21090, 42684> velocity=< 2, -4> 107 | position=<-31745, -21091> velocity=< 3, 2> 108 | position=< 53275, 21427> velocity=<-5, -2> 109 | position=< 53283, -21092> velocity=<-5, 2> 110 | position=<-10477, -52988> velocity=< 1, 5> 111 | position=< 53267, -21098> velocity=<-5, 2> 112 | position=< 10757, -31728> velocity=<-1, 3> 113 | position=< 21433, 53315> velocity=<-2, -5> 114 | position=<-53033, 21426> velocity=< 5, -2> 115 | position=<-31725, -10463> velocity=< 3, 1> 116 | position=< 21413, 32056> velocity=<-2, -3> 117 | position=< 21402, -21095> velocity=<-2, 2> 118 | position=< 42672, 32056> velocity=<-4, -3> 119 | position=<-53033, -42354> velocity=< 5, 4> 120 | position=< 10788, -31726> velocity=<-1, 3> 121 | position=<-10488, -52981> velocity=< 1, 5> 122 | position=< 42654, 10801> velocity=<-4, -1> 123 | position=< 10779, -52985> velocity=<-1, 5> 124 | position=<-31755, 53321> velocity=< 3, -5> 125 | position=<-10508, 42691> velocity=< 1, -4> 126 | position=<-52985, 42686> velocity=< 5, -4> 127 | position=< 32047, 21430> velocity=<-3, -2> 128 | position=<-42350, 10800> velocity=< 4, -1> 129 | position=<-42403, -10459> velocity=< 4, 1> 130 | position=< 42669, 10801> velocity=<-4, -1> 131 | position=< 42693, -31724> velocity=<-4, 3> 132 | position=<-10463, -52984> velocity=< 1, 5> 133 | position=<-52985, 21430> velocity=< 5, -2> 134 | position=<-10503, -31728> velocity=< 1, 3> 135 | position=<-53017, 10800> velocity=< 5, -1> 136 | position=<-42359, 21428> velocity=< 4, -2> 137 | position=<-21116, 10796> velocity=< 2, -1> 138 | position=< 53295, 10795> velocity=<-5, -1> 139 | position=<-52980, -10467> velocity=< 5, 1> 140 | position=<-42363, -21097> velocity=< 4, 2> 141 | position=< 53283, -52983> velocity=<-5, 5> 142 | position=< 21433, 10797> velocity=<-2, -1> 143 | position=< 10760, 53321> velocity=<-1, -5> 144 | position=<-31764, -52984> velocity=< 3, 5> 145 | position=< 32039, 53314> velocity=<-3, -5> 146 | position=<-21135, 21423> velocity=< 2, -2> 147 | position=< 21390, -21095> velocity=<-2, 2> 148 | position=< 10787, -10467> velocity=<-1, 1> 149 | position=< 42637, 21430> velocity=<-4, -2> 150 | position=<-31769, -10459> velocity=< 3, 1> 151 | position=<-21108, -10468> velocity=< 2, 1> 152 | position=<-21132, 10792> velocity=< 2, -1> 153 | position=<-31753, -52979> velocity=< 3, 5> 154 | position=<-53017, 21423> velocity=< 5, -2> 155 | position=<-10487, 10797> velocity=< 1, -1> 156 | position=<-42378, 32058> velocity=< 4, -3> 157 | position=< 32051, -52986> velocity=<-3, 5> 158 | position=<-52985, -52981> velocity=< 5, 5> 159 | position=<-10497, -42356> velocity=< 1, 4> 160 | position=<-10465, -10463> velocity=< 1, 1> 161 | position=< 42671, -42358> velocity=<-4, 4> 162 | position=< 21396, 10801> velocity=<-2, -1> 163 | position=< 53267, -31724> velocity=<-5, 3> 164 | position=<-42363, 32053> velocity=< 4, -3> 165 | position=< 32048, 10799> velocity=<-3, -1> 166 | position=< 53280, -31727> velocity=<-5, 3> 167 | position=<-52985, -21096> velocity=< 5, 2> 168 | position=< 21385, 53312> velocity=<-2, -5> 169 | position=<-10479, 42682> velocity=< 1, -4> 170 | position=<-10487, 10796> velocity=< 1, -1> 171 | position=<-42352, -10463> velocity=< 4, 1> 172 | position=<-53007, 32056> velocity=< 5, -3> 173 | position=< 21386, 32052> velocity=<-2, -3> 174 | position=<-10465, 10792> velocity=< 1, -1> 175 | position=<-31757, 42683> velocity=< 3, -4> 176 | position=< 42678, -10461> velocity=<-4, 1> 177 | position=<-52975, 32056> velocity=< 5, -3> 178 | position=<-53009, 32060> velocity=< 5, -3> 179 | position=<-10476, -42358> velocity=< 1, 4> 180 | position=<-31752, -10460> velocity=< 3, 1> 181 | position=<-10481, 53313> velocity=< 1, -5> 182 | position=<-21125, -21098> velocity=< 2, 2> 183 | position=< 53303, -31728> velocity=<-5, 3> 184 | position=< 21429, -10464> velocity=<-2, 1> 185 | position=<-53009, 21431> velocity=< 5, -2> 186 | position=< 32047, 32060> velocity=<-3, -3> 187 | position=< 21405, -52986> velocity=<-2, 5> 188 | position=<-42359, 21424> velocity=< 4, -2> 189 | position=< 10758, 10792> velocity=<-1, -1> 190 | position=< 32055, 32059> velocity=<-3, -3> 191 | position=< 21433, 53320> velocity=<-2, -5> 192 | position=< 32027, -21089> velocity=<-3, 2> 193 | position=<-31721, -10464> velocity=< 3, 1> 194 | position=<-31733, -52988> velocity=< 3, 5> 195 | position=< 42645, 21425> velocity=<-4, -2> 196 | position=<-53033, -31719> velocity=< 5, 3> 197 | position=<-10513, -31727> velocity=< 1, 3> 198 | position=< 10747, 53314> velocity=<-1, -5> 199 | position=< 42693, 53313> velocity=<-4, -5> 200 | position=< 53299, -21098> velocity=<-5, 2> 201 | position=<-10452, 32055> velocity=< 1, -3> 202 | position=<-21098, 32052> velocity=< 2, -3> 203 | position=< 53301, 21426> velocity=<-5, -2> 204 | position=< 21389, 42688> velocity=<-2, -4> 205 | position=< 32016, 32056> velocity=<-3, -3> 206 | position=< 53323, 32059> velocity=<-5, -3> 207 | position=< 10808, -52985> velocity=<-1, 5> 208 | position=< 32007, -42356> velocity=<-3, 4> 209 | position=< 21390, 53314> velocity=<-2, -5> 210 | position=< 21405, 21429> velocity=<-2, -2> 211 | position=<-31717, -31721> velocity=< 3, 3> 212 | position=<-10457, -42353> velocity=< 1, 4> 213 | position=< 42685, -21089> velocity=<-4, 2> 214 | position=<-21095, 21430> velocity=< 2, -2> 215 | position=<-21102, -42352> velocity=< 2, 4> 216 | position=<-10465, 32052> velocity=< 1, -3> 217 | position=< 21433, 42691> velocity=<-2, -4> 218 | position=<-21135, -31720> velocity=< 2, 3> 219 | position=< 42653, -31727> velocity=<-4, 3> 220 | position=< 32063, -31725> velocity=<-3, 3> 221 | position=< 32032, -21092> velocity=<-3, 2> 222 | position=< 10798, 21422> velocity=<-1, -2> 223 | position=< 32060, -10459> velocity=<-3, 1> 224 | position=<-10479, -21098> velocity=< 1, 2> 225 | position=<-21091, 32052> velocity=< 2, -3> 226 | position=<-31745, -52982> velocity=< 3, 5> 227 | position=<-31752, -10467> velocity=< 3, 1> 228 | position=< 53317, -52988> velocity=<-5, 5> 229 | position=< 32032, 10794> velocity=<-3, -1> 230 | position=<-42378, 42684> velocity=< 4, -4> 231 | position=< 21389, 21429> velocity=<-2, -2> 232 | position=<-21098, -42349> velocity=< 2, 4> 233 | position=<-42355, 10795> velocity=< 4, -1> 234 | position=< 32043, 42682> velocity=<-3, -4> 235 | position=< 10755, 53313> velocity=<-1, -5> 236 | position=< 53267, 21427> velocity=<-5, -2> 237 | position=< 53300, 42686> velocity=<-5, -4> 238 | position=<-42354, 21426> velocity=< 4, -2> 239 | position=< 21409, -10463> velocity=<-2, 1> 240 | position=<-21135, 42688> velocity=< 2, -4> 241 | position=< 32039, -42354> velocity=<-3, 4> 242 | position=<-31717, -21091> velocity=< 3, 2> 243 | position=< 53323, 32058> velocity=<-5, -3> 244 | position=< 21412, 32052> velocity=<-2, -3> 245 | position=< 53308, 10795> velocity=<-5, -1> 246 | position=<-53020, -31727> velocity=< 5, 3> 247 | position=< 10791, 21428> velocity=<-1, -2> 248 | position=<-31741, -10461> velocity=< 3, 1> 249 | position=< 42649, 32058> velocity=<-4, -3> 250 | position=< 10755, -52979> velocity=<-1, 5> 251 | position=<-21114, 10792> velocity=< 2, -1> 252 | position=<-21143, -10461> velocity=< 2, 1> 253 | position=< 32052, 53320> velocity=<-3, -5> 254 | position=<-10470, 53316> velocity=< 1, -5> 255 | position=<-21092, -31724> velocity=< 2, 3> 256 | position=<-10465, 21428> velocity=< 1, -2> 257 | position=< 32036, -21097> velocity=<-3, 2> 258 | position=< 32007, -52985> velocity=<-3, 5> 259 | position=< 42669, -21091> velocity=<-4, 2> 260 | position=< 42669, -10467> velocity=<-4, 1> 261 | position=< 53283, 32059> velocity=<-5, -3> 262 | position=<-10505, 10796> velocity=< 1, -1> 263 | position=< 53302, -21098> velocity=<-5, 2> 264 | position=< 21394, 21422> velocity=<-2, -2> 265 | position=< 53317, 10792> velocity=<-5, -1> 266 | position=<-10476, -10468> velocity=< 1, 1> 267 | position=<-42387, -31725> velocity=< 4, 3> 268 | position=< 42697, 53316> velocity=<-4, -5> 269 | position=<-42376, 10797> velocity=< 4, -1> 270 | position=<-31724, -21098> velocity=< 3, 2> 271 | position=< 53267, 42683> velocity=<-5, -4> 272 | position=< 32023, 10794> velocity=<-3, -1> 273 | position=<-10452, -31727> velocity=< 1, 3> 274 | position=<-21143, 32057> velocity=< 2, -3> 275 | position=< 32033, 21427> velocity=<-3, -2> 276 | position=<-10457, 32053> velocity=< 1, -3> 277 | position=<-21092, -31724> velocity=< 2, 3> 278 | position=<-10500, -42357> velocity=< 1, 4> 279 | position=< 42645, -31722> velocity=<-4, 3> 280 | position=< 10803, -21093> velocity=<-1, 2> 281 | position=<-10492, -31720> velocity=< 1, 3> 282 | position=< 42650, -21089> velocity=<-4, 2> 283 | position=< 53267, -42357> velocity=<-5, 4> 284 | position=< 21428, 21426> velocity=<-2, -2> 285 | position=<-31725, 10794> velocity=< 3, -1> 286 | position=<-21102, -31721> velocity=< 2, 3> 287 | position=<-42347, 10793> velocity=< 4, -1> 288 | position=< 42654, -42358> velocity=<-4, 4> 289 | position=< 42671, -10464> velocity=<-4, 1> 290 | position=<-53025, -21094> velocity=< 5, 2> 291 | position=< 21410, 42682> velocity=<-2, -4> 292 | position=< 42669, -31725> velocity=<-4, 3> 293 | position=< 53278, 53312> velocity=<-5, -5> 294 | position=< 53299, 21430> velocity=<-5, -2> 295 | position=< 32035, -31726> velocity=<-3, 3> 296 | position=< 21393, -31724> velocity=<-2, 3> 297 | position=<-21091, -10461> velocity=< 2, 1> 298 | position=<-10504, -21098> velocity=< 1, 2> 299 | position=< 42650, -21096> velocity=<-4, 2> 300 | position=<-10481, 53314> velocity=< 1, -5> 301 | position=< 21436, 42686> velocity=<-2, -4> 302 | position=<-42347, -31725> velocity=< 4, 3> 303 | position=< 42693, -31728> velocity=<-4, 3> 304 | position=<-21111, 10798> velocity=< 2, -1> 305 | position=< 32063, 21424> velocity=<-3, -2> 306 | position=< 21434, -10468> velocity=<-2, 1> 307 | position=< 21401, -31727> velocity=<-2, 3> 308 | position=< 21420, 42687> velocity=<-2, -4> 309 | position=<-10500, -21090> velocity=< 1, 2> 310 | position=<-10485, -31725> velocity=< 1, 3> 311 | position=< 32063, -42356> velocity=<-3, 4> 312 | position=< 21406, -52987> velocity=<-2, 5> 313 | position=<-31732, 53318> velocity=< 3, -5> 314 | position=<-42361, -10463> velocity=< 4, 1> 315 | position=<-31713, -31724> velocity=< 3, 3> 316 | position=<-10468, -21097> velocity=< 1, 2> 317 | position=<-10492, 32060> velocity=< 1, -3> 318 | position=< 42694, -10464> velocity=<-4, 1> 319 | position=<-42403, -42351> velocity=< 4, 4> 320 | position=< 42661, 42690> velocity=<-4, -4> 321 | position=<-53017, -21091> velocity=< 5, 2> 322 | position=< 32056, 21426> velocity=<-3, -2> 323 | position=< 10805, 42682> velocity=<-1, -4> 324 | position=< 53299, -21089> velocity=<-5, 2> 325 | position=<-31765, 42685> velocity=< 3, -4> 326 | position=< 21394, 53312> velocity=<-2, -5> 327 | position=< 10800, 42690> velocity=<-1, -4> 328 | position=< 53309, 10797> velocity=<-5, -1> 329 | position=< 53325, 42686> velocity=<-5, -4> 330 | position=< 53323, 32052> velocity=<-5, -3> 331 | position=< 21377, -52988> velocity=<-2, 5> 332 | position=<-10505, -42358> velocity=< 1, 4> 333 | position=< 21389, -31724> velocity=<-2, 3> 334 | position=< 32017, -10464> velocity=<-3, 1> 335 | position=< 42685, 10794> velocity=<-4, -1> 336 | position=< 53279, 53312> velocity=<-5, -5> 337 | position=< 32048, -52985> velocity=<-3, 5> 338 | position=< 21385, 10797> velocity=<-2, -1> 339 | position=< 53267, 32055> velocity=<-5, -3> 340 | position=<-21143, 32061> velocity=< 2, -3> -------------------------------------------------------------------------------- /25/1.in: -------------------------------------------------------------------------------- 1 | 8,-4,-1,-6 2 | -8,5,0,-7 3 | 1,6,-8,-2 4 | -6,8,3,-7 5 | -1,4,8,3 6 | -7,-1,0,-5 7 | 8,-8,-6,-1 8 | 0,8,-4,4 9 | -1,-1,3,5 10 | 8,0,-2,-8 11 | -6,-5,1,-2 12 | 2,4,-3,-3 13 | 8,6,3,6 14 | 2,-7,8,-1 15 | 2,1,-7,7 16 | 8,8,3,3 17 | -8,-8,1,0 18 | -8,0,2,5 19 | -1,0,-5,0 20 | 8,-2,0,4 21 | 1,2,3,3 22 | -6,6,2,-8 23 | 4,8,0,-6 24 | 2,3,4,2 25 | -6,-8,-4,8 26 | 4,-8,2,1 27 | 8,8,2,-1 28 | -4,-4,0,3 29 | 6,3,-5,-5 30 | -3,6,-8,0 31 | 3,-4,3,-3 32 | 8,0,7,3 33 | 0,3,-7,-1 34 | 0,5,6,4 35 | -1,-3,-6,8 36 | 0,4,7,4 37 | 6,0,0,-5 38 | -6,3,-4,-6 39 | -3,6,8,4 40 | 0,0,4,0 41 | -3,-5,5,0 42 | 8,8,2,8 43 | 3,-2,3,-4 44 | 3,8,-6,2 45 | -4,-1,1,-7 46 | 5,-6,5,-7 47 | -2,-3,4,8 48 | 8,8,5,0 49 | -2,5,2,-3 50 | 5,6,7,2 51 | -3,3,-5,-6 52 | 3,-8,0,-1 53 | -5,-3,0,-5 54 | -4,-5,-4,4 55 | 3,2,-2,-4 56 | -5,6,4,-4 57 | 0,4,2,0 58 | -8,0,-8,6 59 | -8,0,-6,3 60 | 5,6,-1,4 61 | 0,4,-8,-1 62 | -4,-4,1,0 63 | 1,3,-4,-8 64 | 2,8,-6,-4 65 | 1,4,3,-7 66 | -6,-3,4,5 67 | 0,-7,-8,6 68 | -5,4,8,8 69 | -4,0,7,8 70 | 6,0,0,-8 71 | 6,3,-2,6 72 | 7,2,-1,3 73 | 0,0,-8,0 74 | 2,-2,-4,-1 75 | 0,2,0,5 76 | -4,4,2,0 77 | -2,-8,-1,-5 78 | -6,4,3,4 79 | -5,0,-3,-6 80 | 2,-1,3,-3 81 | 3,3,0,1 82 | 2,4,-3,-1 83 | -4,8,7,0 84 | 3,-3,-5,0 85 | -1,-8,-3,-2 86 | 1,4,2,-7 87 | 3,-1,-1,8 88 | -1,0,3,-1 89 | 4,-3,3,0 90 | 4,-1,-1,-7 91 | -8,-3,6,8 92 | -2,4,4,-5 93 | 7,-3,2,4 94 | 8,8,6,2 95 | 4,8,7,3 96 | -1,1,0,5 97 | 0,-8,6,3 98 | -5,-1,-5,0 99 | 7,5,-7,1 100 | -8,3,-2,2 101 | 0,0,-3,1 102 | -4,7,8,-8 103 | 0,-2,2,-2 104 | 0,8,2,7 105 | -6,0,2,-5 106 | 4,-1,6,-4 107 | -7,-1,-3,2 108 | -8,5,-1,4 109 | -1,-1,7,-8 110 | 1,-1,7,-8 111 | -2,5,8,-8 112 | -5,7,-6,-2 113 | -2,4,-7,7 114 | 1,4,5,7 115 | 6,7,-2,-2 116 | 0,7,0,4 117 | -6,2,-3,5 118 | 8,-7,4,-2 119 | 6,-3,5,-6 120 | 7,5,-4,-1 121 | 0,3,5,-1 122 | 0,3,8,3 123 | 2,8,0,-6 124 | 0,6,1,0 125 | 4,2,8,7 126 | -3,6,-2,-2 127 | -2,-1,4,0 128 | 4,0,-2,3 129 | -4,0,4,-4 130 | 8,-8,5,-1 131 | 2,3,8,6 132 | -4,1,-8,1 133 | 0,-2,-8,1 134 | 6,3,-5,0 135 | -8,-6,-5,-8 136 | -7,5,-8,-2 137 | 8,1,2,-4 138 | -7,-6,-7,6 139 | 8,7,-6,6 140 | 2,5,-5,-6 141 | 2,-1,-5,-6 142 | 7,-6,0,-7 143 | -1,1,-4,-8 144 | 3,-6,1,-5 145 | 0,-1,0,-2 146 | 3,-2,2,-1 147 | 7,-6,4,-6 148 | -8,0,-2,3 149 | 5,0,-1,-7 150 | 1,1,5,2 151 | 1,-2,6,3 152 | 8,4,7,0 153 | -4,-4,-3,6 154 | 3,6,1,0 155 | 8,-4,1,-3 156 | 2,-7,-3,-5 157 | 4,-2,-1,-4 158 | -6,6,5,-7 159 | 0,-1,-5,0 160 | 2,2,3,0 161 | 0,3,8,4 162 | 8,0,-2,4 163 | -7,2,0,4 164 | -8,-7,2,0 165 | -2,-3,6,5 166 | 2,0,2,6 167 | 0,-4,5,8 168 | 7,-3,-1,-7 169 | -3,1,2,0 170 | 2,3,6,1 171 | -1,-2,4,-3 172 | 4,-4,-6,-3 173 | -4,-2,0,6 174 | -6,-2,-1,-1 175 | -7,0,8,8 176 | -2,-5,1,-2 177 | 7,4,0,-2 178 | -1,6,6,0 179 | -3,4,0,0 180 | 0,-3,1,2 181 | -2,-5,2,-1 182 | -2,-8,-7,1 183 | 8,-8,-5,0 184 | -6,8,-1,-1 185 | 4,7,6,0 186 | 0,4,-1,-2 187 | -7,2,7,-7 188 | 6,7,8,-1 189 | 0,-1,-3,-5 190 | 2,-3,6,-7 191 | 7,-2,8,2 192 | -8,-3,-3,6 193 | 0,2,0,-1 194 | -5,-5,-4,2 195 | 8,0,0,-4 196 | 3,0,-2,8 197 | 3,6,-4,6 198 | 0,-8,2,5 199 | -4,3,2,-1 200 | 8,2,-4,3 201 | 7,-7,8,-6 202 | -8,7,-1,8 203 | -5,-4,0,-6 204 | 2,-8,0,1 205 | -6,-7,-4,7 206 | 4,-6,-5,4 207 | -6,-7,-5,-1 208 | -8,0,-1,2 209 | -1,-1,-5,2 210 | 7,3,-6,-8 211 | -3,-6,-8,0 212 | -6,7,1,3 213 | 7,-8,6,7 214 | -3,-3,-3,-2 215 | 7,-3,8,-2 216 | -7,7,-1,2 217 | -7,0,-3,5 218 | 2,-4,-2,-8 219 | -7,-2,-1,7 220 | -3,-7,-8,-5 221 | -4,1,1,7 222 | 2,7,-2,-1 223 | 1,-7,-8,-1 224 | 7,7,3,3 225 | -1,-5,7,-4 226 | -1,-7,7,6 227 | -5,-3,-2,3 228 | -7,-6,-4,-8 229 | 7,2,8,1 230 | 4,8,3,4 231 | 8,1,-6,4 232 | -6,-2,-8,-3 233 | 4,0,7,-4 234 | 4,7,-3,-3 235 | -2,-2,0,-7 236 | -1,-8,6,7 237 | 4,-6,-4,5 238 | 7,-2,1,8 239 | -6,1,-1,-6 240 | -2,-1,3,7 241 | -4,8,-2,7 242 | -5,2,4,-8 243 | -8,0,-3,1 244 | -6,8,-5,0 245 | -2,7,-6,-6 246 | 3,8,-6,0 247 | 5,4,0,4 248 | -4,-3,7,-7 249 | 0,0,6,8 250 | 5,-8,3,-5 251 | 5,1,0,3 252 | 3,-7,2,-8 253 | 0,-3,-8,-2 254 | 5,-4,-4,1 255 | 4,4,7,-3 256 | 5,1,8,3 257 | 3,-6,-3,-2 258 | 0,0,4,8 259 | -1,-6,-3,8 260 | 1,-3,4,0 261 | 0,0,-1,-4 262 | 6,-3,-6,8 263 | 7,-1,-7,-3 264 | 1,-3,5,2 265 | 3,-4,-3,-6 266 | -4,8,-4,8 267 | -8,-8,3,7 268 | -6,6,-6,6 269 | 4,7,0,-5 270 | 7,8,7,-4 271 | -6,0,0,1 272 | -8,2,2,6 273 | -2,8,-7,-1 274 | -2,7,4,1 275 | 1,6,-2,-5 276 | -6,2,4,0 277 | 0,8,-1,-3 278 | 1,-8,6,8 279 | -5,6,0,6 280 | -8,4,4,8 281 | 6,1,7,5 282 | 8,7,0,0 283 | -3,1,0,8 284 | -3,-8,-2,8 285 | 8,8,-5,7 286 | -8,-2,3,5 287 | 0,-5,-2,7 288 | -8,3,-1,0 289 | -3,-2,-4,-1 290 | -1,6,-6,5 291 | -7,0,-4,-5 292 | 5,0,-1,0 293 | 0,8,0,-7 294 | -6,4,0,4 295 | -6,5,4,-3 296 | -6,6,7,0 297 | -5,2,6,2 298 | 1,6,2,5 299 | -4,-4,2,8 300 | -5,2,4,0 301 | 7,7,0,-3 302 | -2,5,3,-1 303 | -5,-4,7,7 304 | -2,-7,-2,6 305 | -6,-6,8,5 306 | -4,8,0,4 307 | -2,-1,8,-7 308 | 0,6,7,5 309 | 3,-1,4,3 310 | 4,-8,-2,2 311 | 4,1,-2,7 312 | 6,2,-1,-8 313 | 2,8,-5,7 314 | -5,5,-1,0 315 | 0,-4,3,0 316 | 0,-7,0,4 317 | 3,2,6,3 318 | 4,-8,3,2 319 | 3,6,2,1 320 | -8,7,-7,8 321 | -6,-5,-2,6 322 | -7,0,-6,6 323 | 1,0,-5,4 324 | -4,-7,4,6 325 | 8,-4,-6,3 326 | -8,-4,6,3 327 | -4,-8,-1,-2 328 | -2,1,-3,3 329 | -2,4,8,2 330 | 2,5,8,-5 331 | 1,-4,-4,-5 332 | 5,3,5,-4 333 | -3,-1,-7,0 334 | 7,5,-8,-6 335 | -1,-6,-8,0 336 | -2,-2,-1,-5 337 | 8,7,7,1 338 | -6,7,1,4 339 | -8,2,-3,0 340 | -8,-8,4,2 341 | 8,7,3,-8 342 | 5,4,2,-3 343 | -1,-4,-7,5 344 | -1,5,-2,-1 345 | -5,3,-5,0 346 | 7,-4,-4,1 347 | 5,8,-1,-3 348 | -1,0,-4,-5 349 | 4,-6,0,-6 350 | 6,3,3,-8 351 | -1,-6,0,8 352 | 3,-2,0,-8 353 | -5,6,7,6 354 | -2,5,-2,0 355 | -5,7,-6,-7 356 | -2,1,-1,6 357 | -8,7,6,-4 358 | -4,2,1,-2 359 | 2,6,1,-2 360 | 0,-6,-7,5 361 | -6,6,-3,-1 362 | -4,0,-8,-8 363 | -5,0,8,2 364 | 3,-5,2,3 365 | 6,-4,3,-5 366 | 1,1,0,2 367 | 3,-2,0,8 368 | -3,0,-7,3 369 | -8,8,1,0 370 | 0,-2,0,8 371 | 1,6,-2,4 372 | 7,0,5,-7 373 | -1,6,0,3 374 | 5,-4,2,0 375 | 3,5,0,1 376 | -8,-8,-4,-2 377 | 5,-2,5,-1 378 | -2,4,-2,0 379 | 4,-5,3,-7 380 | -2,3,-6,-3 381 | 0,5,0,8 382 | -5,-6,0,-1 383 | 0,3,-4,-4 384 | -1,-5,-6,4 385 | -6,-7,4,4 386 | 7,0,6,4 387 | -1,-2,-4,4 388 | 1,0,-1,-4 389 | -2,8,1,0 390 | -3,-7,-2,-7 391 | -6,-5,1,-6 392 | 7,7,-8,-6 393 | -3,-4,8,-1 394 | -5,-2,-3,1 395 | -4,6,0,5 396 | -4,5,2,5 397 | 4,2,4,-4 398 | -7,-1,7,-5 399 | 1,-6,-5,4 400 | 7,0,0,0 401 | 8,5,8,-8 402 | 2,6,-5,7 403 | 1,1,-3,0 404 | 3,-3,2,-7 405 | 8,3,4,3 406 | 0,2,8,-7 407 | 4,-7,3,-7 408 | -7,5,-3,-1 409 | 4,-5,5,2 410 | 7,-1,6,-4 411 | 4,-8,7,-3 412 | 6,-8,-7,2 413 | -3,-5,7,0 414 | -8,-3,-5,-6 415 | -3,4,-1,0 416 | -5,-6,5,2 417 | -6,7,-1,-5 418 | -6,-2,-7,6 419 | 4,-3,6,4 420 | 4,7,5,7 421 | 4,-5,-7,-8 422 | -8,8,-6,8 423 | -2,-5,-5,-4 424 | 8,-7,-2,1 425 | -6,-4,-7,0 426 | -8,7,0,-7 427 | -5,5,-2,-4 428 | 6,4,-3,-1 429 | 3,4,2,3 430 | -4,4,-7,-5 431 | -5,-1,-1,-5 432 | -3,4,4,-7 433 | -5,-3,-3,6 434 | -5,4,-2,8 435 | -1,-8,-5,-7 436 | 8,-7,1,4 437 | 3,4,-1,-4 438 | -1,5,0,8 439 | 4,0,0,4 440 | 1,3,-7,4 441 | 3,0,-8,-6 442 | -4,7,2,0 443 | 8,-8,-2,3 444 | 7,5,-8,2 445 | 6,-8,-7,0 446 | 1,-5,-5,4 447 | -7,0,-1,8 448 | 5,-1,-7,5 449 | -4,-3,7,-5 450 | 0,4,-7,-4 451 | -8,2,-4,-2 452 | 1,-2,0,-3 453 | 2,-4,-1,3 454 | -8,4,-8,8 455 | -1,6,4,-7 456 | 1,8,6,4 457 | 5,6,8,-1 458 | -2,0,8,-4 459 | -4,8,-5,-7 460 | -1,-2,4,-4 461 | -3,5,-4,-6 462 | 4,-2,5,-3 463 | 7,-5,0,0 464 | 7,2,6,-6 465 | 7,2,1,6 466 | -7,-5,6,-5 467 | 1,8,-4,1 468 | -8,1,1,7 469 | 3,2,7,-7 470 | 6,5,-6,3 471 | -3,-1,2,-3 472 | 2,-7,3,1 473 | -2,0,2,2 474 | 0,3,-5,-4 475 | -7,0,6,1 476 | 4,-7,4,0 477 | 1,2,-8,-8 478 | 0,1,4,1 479 | -6,6,0,3 480 | 0,0,1,-7 481 | 0,-8,-6,4 482 | 8,-1,4,2 483 | 0,-1,-6,0 484 | -2,8,-5,-5 485 | -1,6,3,-1 486 | -3,1,-4,0 487 | -4,6,-3,-4 488 | -4,3,2,-3 489 | 2,5,4,-7 490 | 8,4,0,1 491 | 7,5,-4,4 492 | 0,8,7,1 493 | -1,-4,-8,-6 494 | -6,0,4,1 495 | 8,6,-8,-2 496 | 2,-7,1,-3 497 | -3,1,-2,8 498 | -3,5,0,0 499 | -6,-1,1,3 500 | -4,0,-5,-3 501 | -8,-1,-1,-6 502 | -7,8,-7,-2 503 | 7,5,0,-2 504 | 0,3,7,-6 505 | -8,2,5,4 506 | -2,-2,7,-6 507 | 4,6,-4,4 508 | -7,-3,6,-4 509 | 0,5,0,-3 510 | -6,0,-2,-7 511 | 4,3,4,-3 512 | 0,-1,-5,-4 513 | -6,-7,-4,-7 514 | 7,-6,1,-1 515 | -1,4,-3,2 516 | 4,-2,1,-3 517 | -3,5,2,5 518 | 5,-4,-2,-5 519 | 7,8,-3,0 520 | 6,-7,-3,2 521 | 0,0,-5,1 522 | 4,6,-2,1 523 | 3,5,-5,-2 524 | 7,8,7,5 525 | -1,-8,0,3 526 | -8,6,-3,0 527 | 5,0,-4,4 528 | 0,-8,4,4 529 | 5,2,7,-7 530 | -8,-3,-7,6 531 | -4,-2,0,-6 532 | 0,6,-8,-1 533 | 6,2,3,3 534 | 0,0,8,0 535 | 1,1,8,-1 536 | -3,5,6,-7 537 | -6,5,-7,-6 538 | 2,-3,0,-3 539 | -4,2,-6,3 540 | 7,7,-2,-2 541 | -5,-8,-8,-6 542 | -3,-1,0,-7 543 | 3,-7,3,-5 544 | -1,6,-7,-8 545 | 1,-2,-2,-8 546 | 1,-3,-7,0 547 | -3,2,4,2 548 | -1,6,4,0 549 | -4,-1,-2,-5 550 | 7,6,7,-4 551 | -4,8,-7,-8 552 | -7,4,-1,8 553 | -2,3,0,4 554 | -1,6,-8,-5 555 | 4,4,3,6 556 | -3,-5,6,1 557 | -4,6,0,8 558 | -1,-5,-4,1 559 | 3,-4,8,5 560 | -5,-1,-4,2 561 | 5,-8,4,-4 562 | 3,-2,-8,1 563 | 6,2,-2,-7 564 | 4,-7,-4,-1 565 | 5,8,-3,-7 566 | -2,-1,-7,4 567 | 5,-7,-8,-5 568 | -3,3,7,-3 569 | 2,-6,-6,6 570 | -4,4,-4,-1 571 | 1,-3,4,-5 572 | 0,4,-6,-1 573 | -1,7,7,1 574 | 3,-2,-6,7 575 | -1,0,6,4 576 | -1,-8,-7,0 577 | -1,0,6,-4 578 | 3,-8,4,2 579 | 8,0,0,-3 580 | -4,2,4,-6 581 | 5,0,-5,-2 582 | 6,5,0,7 583 | -1,1,-2,-5 584 | 7,3,1,-8 585 | -2,-3,2,2 586 | -7,2,-5,-5 587 | 2,4,-8,-5 588 | -8,1,-1,7 589 | -4,-1,-7,4 590 | 4,-3,1,3 591 | 7,-7,1,2 592 | 2,2,2,-7 593 | 4,-1,-3,8 594 | 1,-2,8,1 595 | 3,-8,-7,-8 596 | -6,0,0,0 597 | 8,3,1,6 598 | 6,-7,-2,7 599 | -5,-1,6,1 600 | 6,0,-8,5 601 | 6,3,-6,-5 602 | 2,-6,6,-1 603 | -7,2,-4,4 604 | 0,-7,-4,3 605 | 8,7,4,7 606 | -6,8,3,-8 607 | -4,-8,8,-4 608 | 7,7,-6,-6 609 | 3,-6,4,-4 610 | 0,-6,1,-8 611 | 8,4,1,2 612 | -4,-1,8,7 613 | 0,-7,0,-2 614 | -2,5,0,-4 615 | 1,-7,-8,6 616 | -2,-2,-3,-5 617 | 3,5,7,-8 618 | -1,-8,7,8 619 | 5,-2,-4,2 620 | 8,-7,6,-7 621 | -5,7,-4,8 622 | 2,0,0,6 623 | 7,8,0,4 624 | 4,4,8,4 625 | -4,-1,-5,-7 626 | -8,-1,-5,1 627 | -4,4,-6,1 628 | 8,-7,-1,2 629 | 3,-6,-2,8 630 | -7,-2,-3,4 631 | 0,0,-4,3 632 | -7,0,-8,7 633 | -8,-2,-3,-6 634 | 7,0,8,3 635 | -5,7,7,8 636 | 8,6,0,0 637 | -2,1,-6,-6 638 | -1,-3,-2,-1 639 | 6,1,-8,3 640 | 1,7,-5,-5 641 | 5,-4,-6,0 642 | 7,4,0,3 643 | -2,-6,0,8 644 | -7,-8,5,7 645 | -7,4,6,-3 646 | -3,-8,-6,-1 647 | 6,0,1,-2 648 | 5,5,-5,1 649 | 6,6,6,0 650 | -4,0,7,2 651 | 0,6,-4,-5 652 | -6,-4,-8,7 653 | 2,-3,8,-5 654 | 6,-5,8,5 655 | -2,-5,7,-2 656 | -2,-3,-7,-1 657 | 6,-7,5,4 658 | -7,1,4,0 659 | -8,5,3,-1 660 | 6,-4,-4,1 661 | -1,0,-8,-6 662 | 0,0,-5,-2 663 | -5,1,6,-1 664 | 1,3,4,3 665 | 4,3,-6,0 666 | 1,-8,2,6 667 | -7,3,-3,1 668 | 1,-6,2,-3 669 | 5,8,-6,7 670 | -5,-4,5,8 671 | -3,-3,6,-1 672 | 3,4,-2,3 673 | 8,2,-8,0 674 | 8,-8,-4,4 675 | -8,3,-7,8 676 | 3,7,-5,1 677 | -3,2,-3,-7 678 | -8,7,0,-8 679 | 6,-8,7,5 680 | 7,-8,5,3 681 | -4,1,0,-3 682 | 6,-7,8,5 683 | 6,0,-4,-3 684 | 0,7,7,-1 685 | -2,2,-7,6 686 | -4,-2,3,-4 687 | -5,-6,0,-4 688 | 0,7,-8,-4 689 | -8,-1,-2,-7 690 | -2,0,-2,4 691 | -4,8,-4,-2 692 | -2,-1,0,0 693 | 0,-5,4,-8 694 | 0,-7,-2,7 695 | -4,6,7,8 696 | 6,5,3,2 697 | -1,1,5,-4 698 | -5,-5,4,-2 699 | 0,-1,-7,5 700 | 7,-3,-5,1 701 | 7,-1,-4,-8 702 | -4,-3,7,-1 703 | 7,-8,6,-7 704 | -5,-8,-6,6 705 | 0,-6,4,-4 706 | 8,7,-5,0 707 | 3,5,8,3 708 | 7,2,2,6 709 | -7,-7,7,0 710 | 4,-8,-3,8 711 | 1,-5,-8,3 712 | 2,5,-7,-6 713 | 8,-7,5,-7 714 | -8,-3,6,7 715 | -8,0,-1,-1 716 | -1,2,8,0 717 | 5,-5,-4,6 718 | -8,8,-1,-8 719 | 6,0,-7,0 720 | 3,7,-2,3 721 | 1,4,-5,0 722 | -6,-4,1,3 723 | 3,8,-5,-8 724 | -5,6,0,-5 725 | -3,-3,0,4 726 | 5,-1,-2,-5 727 | 0,-5,-7,-5 728 | -7,6,8,2 729 | 0,-8,1,-7 730 | -4,-8,-3,3 731 | 7,-6,-2,7 732 | 1,-4,1,-6 733 | 0,-7,-4,1 734 | -3,-4,5,-5 735 | -2,5,0,7 736 | 0,-5,0,3 737 | -8,-8,6,7 738 | 6,-8,8,-7 739 | 0,1,6,-3 740 | 7,-3,-5,0 741 | -5,-4,-3,-7 742 | 0,6,-5,2 743 | 0,0,-1,0 744 | -6,-6,-2,-6 745 | -1,4,-3,-2 746 | -2,-7,3,-2 747 | 2,-7,0,1 748 | -4,8,2,5 749 | 6,2,4,6 750 | 4,-6,7,4 751 | -7,-3,0,-4 752 | -1,-2,0,1 753 | -7,0,6,-2 754 | 1,-4,7,5 755 | -2,-3,-3,2 756 | 7,0,4,-6 757 | 4,1,6,8 758 | 0,0,4,3 759 | -3,7,7,7 760 | 0,5,4,2 761 | -5,-1,7,1 762 | -3,1,-3,-8 763 | -6,-1,-5,-8 764 | -7,-2,2,6 765 | 0,-2,0,1 766 | 0,-4,-1,8 767 | 5,4,-1,-3 768 | 2,6,1,2 769 | 2,8,8,0 770 | -6,-2,1,-2 771 | -6,-7,6,-8 772 | -1,5,0,-7 773 | 1,-5,0,0 774 | -2,0,2,-1 775 | -1,-3,3,0 776 | 0,1,-6,-2 777 | 8,0,1,4 778 | 1,3,7,-3 779 | -6,-5,-7,0 780 | 7,3,-1,4 781 | 0,-5,-4,5 782 | 6,0,5,-3 783 | -4,-8,2,-5 784 | 3,-6,-2,0 785 | -5,3,4,-6 786 | -3,-5,-6,0 787 | -5,-7,3,-6 788 | -8,-5,7,6 789 | 6,1,8,3 790 | -2,6,0,6 791 | -2,3,6,5 792 | 0,-1,2,-2 793 | 0,8,-4,-6 794 | 1,-6,8,-3 795 | 1,1,-5,2 796 | 6,7,0,1 797 | 1,0,-3,7 798 | -6,-8,6,-6 799 | -8,2,-7,-2 800 | -1,7,6,-3 801 | -5,-7,1,2 802 | 6,-8,5,2 803 | 0,0,2,6 804 | 0,4,6,-6 805 | -1,-3,-2,4 806 | 4,0,-4,-3 807 | 3,4,7,5 808 | -6,0,5,-5 809 | 0,0,1,-3 810 | -4,-7,-5,8 811 | 3,4,5,-7 812 | 1,-8,3,-6 813 | -1,-7,0,-2 814 | 7,-2,2,-6 815 | 7,7,-4,7 816 | -6,7,-2,7 817 | 8,7,1,-6 818 | 2,-1,0,-2 819 | -7,-6,6,0 820 | -6,7,0,-6 821 | -4,0,-8,7 822 | -8,2,2,2 823 | -8,1,8,3 824 | 8,-2,-7,5 825 | -8,-4,6,-5 826 | -2,4,-3,1 827 | -3,-1,-6,-3 828 | 4,3,-4,-6 829 | 0,-8,4,1 830 | 4,-7,2,3 831 | -7,1,-1,1 832 | 3,-8,8,8 833 | -1,2,-1,8 834 | 0,7,-8,-1 835 | 0,7,0,-8 836 | 8,-2,-8,-7 837 | -5,-3,-5,5 838 | -6,2,-5,2 839 | 5,-7,4,1 840 | -5,0,-1,4 841 | 4,-2,7,6 842 | -5,5,-2,1 843 | 6,6,3,-1 844 | -6,-1,-1,8 845 | -2,8,4,-5 846 | 7,-5,0,-3 847 | -7,-4,-7,-8 848 | -6,-5,-5,1 849 | -8,8,-1,3 850 | -7,2,0,-2 851 | 8,-7,-7,-1 852 | -6,4,3,-7 853 | -7,-8,-2,4 854 | -8,4,2,8 855 | -4,-4,8,4 856 | -1,0,-1,2 857 | -2,3,-2,6 858 | -3,2,-3,0 859 | -2,-1,5,-2 860 | 3,5,2,0 861 | 0,4,8,-7 862 | -1,-4,-5,2 863 | 2,0,0,-4 864 | 2,0,-2,5 865 | -5,4,8,-8 866 | 0,-4,4,-2 867 | 3,5,3,0 868 | 8,-5,0,7 869 | 5,-4,0,0 870 | -8,3,-4,3 871 | -3,8,-8,5 872 | -5,-5,-5,3 873 | -5,8,-6,3 874 | 0,-3,7,8 875 | 0,7,5,-4 876 | 3,4,-3,4 877 | -5,0,-2,5 878 | 1,8,3,-4 879 | -8,5,1,6 880 | 1,1,2,0 881 | 7,7,7,8 882 | 5,5,0,-2 883 | 8,6,-7,-7 884 | 8,0,7,2 885 | 3,-5,7,-5 886 | 6,6,4,5 887 | 0,6,5,0 888 | 7,-1,-3,-4 889 | 7,2,-4,7 890 | -5,-7,-3,-1 891 | 2,-8,0,-8 892 | 6,8,-8,5 893 | 6,3,6,7 894 | -7,-2,4,4 895 | 6,-7,7,-8 896 | -8,-3,8,-7 897 | 3,5,-7,8 898 | 0,2,0,4 899 | 8,-4,4,8 900 | 4,-2,-7,4 901 | -5,6,0,-2 902 | 1,1,7,6 903 | -2,8,4,0 904 | 0,-8,-6,-1 905 | 5,8,0,-4 906 | 3,4,-8,4 907 | 8,3,-1,5 908 | -1,2,4,-6 909 | -7,-2,3,3 910 | -4,6,-4,0 911 | 2,-3,-5,-8 912 | -1,4,-7,0 913 | 2,-5,-2,8 914 | 3,0,-8,2 915 | -6,8,-7,7 916 | 0,-4,-5,8 917 | -2,0,7,4 918 | 6,8,1,0 919 | 0,-3,0,-5 920 | -4,0,0,8 921 | -8,8,-1,-3 922 | -1,5,0,6 923 | 7,2,-3,5 924 | 6,-5,4,-1 925 | 0,2,-4,-8 926 | 6,0,-1,-5 927 | 7,-1,3,-1 928 | 7,0,8,1 929 | -8,0,-6,1 930 | -3,-3,-6,4 931 | 0,-3,-8,-8 932 | 4,0,-4,7 933 | -4,8,2,-2 934 | 8,-1,1,8 935 | -1,7,8,-4 936 | -2,6,0,2 937 | -6,-8,-4,0 938 | -3,2,4,0 939 | 0,8,7,-4 940 | 0,-1,-1,-4 941 | 5,-3,7,2 942 | 0,0,7,1 943 | -2,-8,6,0 944 | 0,3,-6,0 945 | 8,-6,2,1 946 | -4,7,5,8 947 | 5,-7,3,1 948 | -6,-8,-3,-1 949 | 6,5,-7,-8 950 | -5,-5,-5,1 951 | -8,-8,7,2 952 | -7,1,5,1 953 | -6,-4,-8,-4 954 | 7,-8,-2,-3 955 | 8,0,0,7 956 | 5,8,0,7 957 | -2,5,-1,0 958 | -6,-8,-4,-2 959 | -3,0,0,4 960 | 1,-4,1,-3 961 | 2,2,3,4 962 | -6,-6,2,-2 963 | -6,0,6,4 964 | 2,0,3,3 965 | -7,6,6,2 966 | 4,-1,5,-8 967 | -4,4,1,8 968 | 2,4,7,5 969 | 0,3,3,-5 970 | 5,4,4,-4 971 | -3,5,2,-2 972 | -8,-1,-5,3 973 | -6,-3,4,8 974 | -1,3,7,8 975 | -4,-2,0,-4 976 | -5,-2,-8,5 977 | -3,-4,0,2 978 | 0,7,2,8 979 | -6,-1,4,-6 980 | 7,-4,-1,-3 981 | 0,-8,1,3 982 | 4,-1,-6,3 983 | -5,-6,5,-2 984 | 1,-7,-1,8 985 | 0,-8,-1,-8 986 | -1,2,-1,1 987 | 1,-7,7,-2 988 | 1,6,-6,-6 989 | 8,3,-1,4 990 | 2,1,-1,7 991 | 5,6,-7,4 992 | -1,4,-4,4 993 | 2,-3,5,4 994 | -5,-7,5,-5 995 | 3,4,-3,-6 996 | -1,-3,7,-7 997 | -3,0,5,7 998 | -7,8,0,-4 999 | 8,-3,7,-1 1000 | -6,0,3,-6 1001 | -4,-3,-4,-7 1002 | 3,-2,1,-8 1003 | 0,0,6,-8 1004 | -1,2,2,6 1005 | 7,-4,-7,2 1006 | -1,2,-7,-6 1007 | 0,-1,-1,3 1008 | 1,-8,0,-1 1009 | -3,-3,0,-5 1010 | 2,-1,5,1 1011 | 7,0,-5,-7 1012 | 8,6,-5,3 1013 | -3,-6,-7,-7 1014 | 8,5,-8,3 1015 | 7,-2,-6,5 1016 | -4,7,-3,-8 1017 | -4,-8,3,4 1018 | 1,-7,-2,2 1019 | 8,-3,6,5 1020 | 3,-2,4,1 1021 | -4,4,8,8 1022 | -5,-8,7,-2 1023 | -6,3,4,5 1024 | -4,5,-5,8 1025 | -5,7,-8,5 1026 | 6,7,-3,6 1027 | 4,7,-2,2 1028 | 4,-5,-8,-3 1029 | 8,1,4,-8 1030 | -5,1,0,0 1031 | 0,-6,7,1 1032 | 7,8,0,-4 1033 | 8,4,-5,-5 1034 | 0,-7,-5,-7 1035 | -6,1,0,-6 1036 | 0,-3,2,-8 1037 | -6,-5,5,-3 1038 | 1,3,-5,7 1039 | 0,-7,-2,-3 1040 | 4,-4,0,1 1041 | -3,4,-7,8 1042 | 0,0,-5,2 1043 | 7,-1,-8,0 1044 | -8,5,-6,-7 1045 | -3,2,2,3 1046 | -2,1,-4,4 1047 | -4,3,2,1 1048 | 5,1,-1,4 1049 | -7,-8,-8,3 1050 | -5,3,-4,2 1051 | 6,1,-7,6 1052 | 8,-8,0,4 1053 | -8,3,-5,6 1054 | -3,0,-5,0 1055 | 3,0,-3,7 1056 | -3,5,0,-7 1057 | -3,5,5,-5 1058 | -2,3,-7,-4 1059 | -8,-3,1,3 1060 | 1,5,5,1 1061 | 7,-4,-3,0 1062 | 0,2,2,-6 1063 | -1,1,8,5 1064 | 8,-1,-2,6 1065 | -4,1,0,5 1066 | -1,-3,7,-5 1067 | 3,5,-5,-4 1068 | 5,-5,-2,-6 1069 | -1,0,7,0 1070 | -3,-7,5,-3 1071 | 7,-6,4,6 1072 | -4,-7,3,5 1073 | -7,5,3,-6 1074 | -7,4,6,7 1075 | 2,5,3,0 1076 | 4,2,8,-5 1077 | 2,-8,7,-6 1078 | -8,1,4,-8 1079 | -1,-1,-7,5 1080 | 4,6,-5,4 1081 | 7,3,-2,-8 1082 | 0,8,4,6 1083 | 3,-2,-7,1 1084 | -1,-8,8,5 -------------------------------------------------------------------------------- /13/1.in: -------------------------------------------------------------------------------- 1 | /-----------------------\ /-------------\ 2 | | /----------+-----------------------------------+----\ | /-----------\ 3 | | | /-+---------------------\ | | | /----------------------------------+------\ | 4 | | | | | /-----------------+-------------+---\| | | | | | 5 | | /--+--------+-+--\| /--------------+-------------+---++--\ | /-----------+----------------------------------+------+---\| 6 | /--+---------+--+--------+-+--++--+--------------+-------------+---++--+-----+-+-----------+------------\ | | || 7 | | | | | | | || | | /+---++--+-----+-+-----------+------------+---------------------+------+---++-------\ 8 | | | | | | | || | /----+------------++\ || | | | | | /--------+------+--\|| | 9 | | | | | /+-+--++--+---------+----+------------+++--++--+---\ | | | | | | | ||| ^ 10 | | | | | /---++-+--++--+---------+--\ | ||| || | | | | /----+------------+------------+--------+------+--+++----\ | 11 | | | | | |/--++-+--++--+---------+--+-+------------+++-\|| | | | | | | | | | | ||| | | 12 | | | | /+---++--++-+--++--+--------\| | | |\+-+++--+---+-/ | | | | | | | ||| | | 13 | /+--+---------+-++---++--++-+--++--+--------++--+-+-<----------+-+-+++--+---+---+------+----+----------\ | | | | ||| | | 14 | || | | || || || | || | /++--+-+------------+-+-+++--+---+---+------+----+----------+-+------------+-\ | | ||| | | 15 | || | | || || || | || | /--+++--+-+------------+-+-+++--+---+\ | | | /---+-+------------+-+------+------+-\||| | | 16 | || | | || || || | || /+----+--+++--+-+\ /+-+-+++--+-\ || | | | | | | /------+-+-\ | | |||| | | 17 | ||/-+---------+\|| || || | || || | ||| | || || | ||| | | || | | | | | | /--+------+-+-+\ | | |||| | | 18 | ||| | |||| || || | || || | ||| | || /---++-+-+++--+-+-++--+------+----+------+-\ | | | | | | || | | |||| | | 19 | ||| | /-----++++---++--++-+--++-++----+--+++--+-++------+---++-+-+++--+-+-++--+------+----+------+-+-+-+-\| | \-+-++---+------+-+/|| | | 20 | ||| | | |||| || || | |\-++----+--+++--+-++------+---++-+-+/| | | || | | | | | | | || | | || | | | || | | 21 | ||| | | |||| /++--++-+--+--++----+--+++--+-++----->+---++-+-+-+--+-+-++--+------+----+------+-+-+-+-++--+--------+-++--\| | | || | | 22 | ||| | | |||| ||| |\-+--+--++----+--+++--+-/|/-----+---++-+-+-+--+-+-++--+------+----+------+\| | | || | | || || | | || | | 23 | ||| | | |||| ||| | | | || | ||| | || | || |/+-+--+-+-++--+------+----+---\ /+++-+-+-++--+-----\ | || || | | || | | 24 | ||| | | |||| /+++--+--+--+--++----+--+++--+--++-----+---++-+++-+--+-+\|| | | | | |||| | | || | /---+--+-++--++-----\| | || | | 25 | ||| | | |||| |||| | | | || /-+--+++--+--++-----+---++-+++-+--+-++++--+------+----+---+-++++\| | || | | | | || || || | || | | 26 | ||| | | |||| |||| | | | \+--+-+--+++--+--/| | |\-+++-+--+-++++--+------+----+---+-++++++-+-++--+-+---+--+-++--++-----++-+-++----+--/ 27 | ||| | /-+-----++++-++++--+--+--+---+--+-+--+++--+---+-----+---+--+++-+--+-++++--+\ | | | |||||| | || | | | | || || || | || | 28 | ||| | | | |||| |||| | | | | | | ||| | | | | ||| |/-+-++++--++-----+----+---+-++++++-+-++--+-+---+--+-++--++-----++-+\|| | 29 | ||| | | | |||| |||| | | | | | | ||| | | | | ||| || | |||| || | | | |||||| | || | | | | || || || |||| | 30 | ||| | | | /++++-++++--+--+--+---+--+-+--+++--+---+-----+---+--+++-++-+-++++--++-----+----+---+-++++++-+-++\ | | | | || || || |||| | 31 | ||| | | | ||||| |||| | | | | | | ||| | | | | ||| || | |||| || | | | |||||| | ||| | | | | || || || |||| | 32 | ||| | | | ||||| |||| | | | | | \--+++--+---+-----+---+--+++-++-+-+++/ || /+----+---+-++++++-+-+++-+-+\ | | || || || |||| | 33 | ||| | | | ||||| |||| | | | \--+----+++--+---+-----+---+--+++-++-/ ||| || || | | |||||| | ||| | \+--+--+-++--++-----/| |||| | 34 | ||| | | | ||||| |||| | | | | ||| | | | | ||| || /+++---++----++----+---+-++++++-+-+++-+--+--+--+-++\ || | |||| | 35 | ||| | | | ||||| |\++--+--+--+------+----+++--+---+-----+---+--+++-++--++++---++----++----+---+-++++++-+-+++-+--+--+--+-+++-/| | |||| | 36 | ||| | | | ||||| | || | | | | ||| | | | | ||| || |||| || || | | ||||||/+-+++-+--+-\| | ||| | | |||| | 37 | ||| | | | ||||| | || | | | \----+++--+---+-----+---+--+++-++--++++---++----++----+---+-++++/||| |\+-+--+-++--+-+/| | | |||| | 38 | ||| | | | ||||| | || | | | |||/-+---+-----+---+--+++-++--++++---++----++----+---+-++++-+++-+-+-+--+-++--+-+<+--+------+-++++-\ | 39 | ||| | | |/---+++++-+-++--+--+--+---------\ |||| | | | | ||| || |||| || || | | |||| ||| | | | | || | | | | | |||| | | 40 | ||| | | || ||||| | || | | | |/++++-+---+-----+---+--+++-++--++++---++----++----+---+-++++-+++-+-+-+--+-++--+-+-+--+------+\|||| | | 41 | ||| | | || ||||| | || | | | /++++++-+---+-----+---+--+++-++--++++---++----++----+---+-++++-+++-+-+\| | || | | | | |||||| | | 42 | ||| | | || ||||| | || |/-+--+--------+++++++-+---+-----+---+-\||| || |||| /-++----++\ | | |||| ||| | ||| | || | | | | |||||| | | 43 | ||| | | || ||||| | || || | | ||||||| | | | /+-++++-++--++++-+-++----+++---+---+-++++-+++-+-+++--+-++--+-+-+--+--\ |||||| | ^ 44 | ||| | | || ||||| | || || | | ||||||| | | | || ||||/++>-++++-+-++----+++---+---+-++++-+++-+-+++--+-++--+-+-+--+--+---++++++-+--+\ 45 | ||| | | || ||||| | || || | | ||||||| | | /+--++-+++++++--++++-+-++----+++---+---+-++++-+++-+-+++--+-++--+-+-+--+\ | |||||| | || 46 | ||| | | ||/--+++++-+-++--++-+--+--------+++++++-+---+----++--++-+++++++--++++-+-++----+++--\| | |||| ||| | ||\--+-++--+-/ | || | |||||| | || 47 | ||| | | ||| ||||| | || || | | ||||||| | | || || ||||||| |||| | || ||| || | |||| ||| | || | || | | || | |||||| | || 48 | ||| | | ||| ||||| | || || | | /--+++++++-+---+----++--++-+++++++--++++-+-++----+++--++---+-++++-+++-+-++---+-++--+--\| || | |||||| | || 49 | ||| \-+-+++--+++++-+-++--++-/ | | ||||||| | | |\--++-+++++++--++++-+-++----+++--++---+-+++/ ||| | || | || | |v || | |||||| | || 50 | ||| | ||| ||||| | |\--++----+-----+--+++++++-+---+----+---++-+++/||| |||| | || ||| || | ||| ||| | || | || | || || | |||||| | || 51 | ||| | ||| ||||| | | || | /-+--+++++++-+---+----+---++-+++-+++--++++-+-++----+++--++---+-+++--+++-+-++---+-++--+--++-\|| | |||||| | || 52 | ||| | ||| ||||| |/+---++----+---+-+--+++++++-+---+----+---++-+++-+++--++++-+-++----+++\ || | ||| ||| | || | || | || ||| | |||||| | || 53 | ||| | ||| ||||| ||| || | | | ||||||| | | | || ||| ||| |||| | || |||| || | ||| ||| | || | || | || |\+-+---+++++/ | || 54 | ||| | ||| ||||| ||| || | | | ||||||| | | | || ||| ||| |||| | || |||| || | ||| ||| | || | || | || | | | ||||| | || 55 | ||| /+-+++--+++++\||| || | | | ||||||| | | |/--++-+++-+++--++++-+-++----++++\|| | ||| ||| | || | || | || | | | ||||| | || 56 | ||| || ||| ||||||||| || | | | ||||||| | | || || ||| ||| |||v | || ||||||| /+-+++--+++-+-++---+-++--+--++-+-+-+---+++++--+--++\ 57 | ||| || ||| ||||||||| || | | | ||||||| | | ||/-++-+++-+++--++++-+-++----+++++++--++-+++--+++-+-++---+-++--+--++-+-+-+\ ||||| | ||| 58 | ||| || |||/-+++++++++---++----+---+-+--+++++++-+---+---\||| || ||| ||| |||| | || ||||||| || ||| ||| | || | || | || | | || ||||| | ||| 59 | ||| || |||| ||||||||| || | | | ||||||| | /+---++++-++-+++-+++\ |||| | || ||||||| || ||| ||| | || | || | || | | || ||||| | ||| 60 | ||| || |||| ||||||||| || | | | ||||||| | || |||| || ||| |||| |||| | || ||||||| ||/+++--+++-+-++---+-++--+--++-+-+-++--+++++--+--+++--\ 61 | ||| || |||| ||||||||| || | | | ||||||| | || |||| || ||| |||| |||| | || ||||||| |||||| ||| | || | || /+--++-+-+-++--+++++--+\ ||| | 62 | ||| || |||| ||||||||| || | | | ||||||| | || |||| || ||| |||| |||| | || ||||||| |||||| ||| | || | || || || | | || ||||| || ||| | 63 | ||| || |||| ||||||||| || | /-+-+--+++++++-+--++---++++-++-+++-++++-++++-+-++----+++++++--++++++--+++-+-++---+-++-++--++-+-+\|| ||||| || ||| | 64 | ||| || |||| |||||||||/--++----+-+-+-+--+++++++-+--++---++++-++-+++-++++-++++-+-++----+++++++--++++++--+++-+-++-\ | || || || | |||| ||||| || ||| | 65 | ||| || |||| |||||||||| || /--+-+-+-+--+++++++-+--++---++++-++-+++-++++-++++-+-++<---+++++++\ |||||| ||| | || | | || || || | |||| ||||| || ||| | 66 | ||| ||/++++-++++++++++--++-+--+\| | | ||||||| |/-++---++++-++-+++-++++-++++-+-++----++++++++-++++++-\||| | || | | || || || | |||| ||||| || ||| | 67 | ||| ||||||| \+++++++++--++-+--+++-+-+--+++++++-++-++---++++-++-+++-++++-++++-+-++----++++++++-++++++-++++-+-/| | | || || || | |||| ||||| || ||| | 68 | ||| |||||\+--+++++++++--++-+--+++-+-+--+++++++-++-++---++++-++-+++-++++-++++-+-++----+++++/|| \+++++-++++-+--+-+-+-++-++--++-+-++++--+++++--++-++/ | 69 | ||| ||||| | ||||||||| || | ||| \-+--+++++++-++-++---++++-++-+++-++++-++++-+-++----+++++-++--+++++-++++-+--+-+-+-++-++--++-/ |||| ||||| || || | 70 | ||| ||||| | ||||||\++--++-+--+++---+--+++++++-++-++---++++-++-+++-++++-++++-+-++----+++/| || ||||| |||| | | | | || || || |||| ||||| || || | 71 | ||| ||||| | |||||| || || |/-+++---+--+++++++-++-++---++++-++-+++-++++-++++\| || ||| | || ||||| |||| | | | | || || || |||| ||||| || || | 72 | ||| |\+++-+--++++++-++--++-++-+++---+--+++++++-++-++---++++-++-+++-++++-++++++-+/ ||| | || |||||/++++-+--+-+-+-++-++--++\ |||| ||||| || || | 73 | ||| | ||| | |||||| || || || ||| | ||||||| || \+---++++-++-+++-+++/ |||||| | |\+-+-++--++++++++++-+--+-+-+-++-++--+++--++++--+++++--++-/| | 74 | ||| | ||| | |||||| || || ||/+++---+--+++++++-++--+---++++-++-+++-+++--++++++-+-----+-+-+-++--++++++++++-+--+-+-+-++-++--+++-\|||| ||||| || | | 75 | ||| | ||| | |||||| || || |||||| | ||||||| || | |||| || ||| |||/-++++++-+-----+-+-+-++--++++++++++-+-\| | | || \+--+++-+++++--+++++--+/ | | 76 | ||| | ||| \--++++++-++--++-++++++---+--+++++++-++--+---/||| |\-+++-++++-+/|||| | | | | ||/-++++++++++-+-++-+-+-++--+--+++-+++++--+++++\ | | | 77 | |||/-+-+++----++++++-++--++-++++++-\ |/-+++++++-++--+----+++\| ||| |||| | |||| | | | | ||| |||||||||| | || | | || | ||| ||||| |||||| | | | 78 | |||| | ||| |||||| || || |||||| | || |||||\+-++--+----+++++--+/| |||| \-++++-+-----+-+-+-+++-++++++++++-+-++-+-+-++--+--+/| ||||| |||||| | | | 79 | |||| | ||| |||||| || || |||||| | || ||||| | || | ||||| | | ||\+---++++-+-----+-+-+-+++-++++++++++-+-++-+-+-++--+--+-+-+++++--+++/|| | | | 80 | |||| | ||| |||||| || || |||||| | || ||||| | || | ||||| | | || | |||| | | | | \++-++++++++++-+-++-+-+-++--+--+-+-+++++--/|| || | | | 81 | |||| | ||| |||||| || || |||||| | || ||||| | || | ||||| | | || | |||| | | | | || ||\+++++++-+-++-+-+-+/ | | | ||||| || || | | | 82 | \+++-+-+++----++++++-++--++-++++++-+-++-+++++-+-++--+----+++++--+-+-++-+---++++-+-----+-+-+--++-++-++++/|| | || | | | | | | ||||| || || | | | 83 | ||| | ||| |||||| || || \+++++-+-++-+++++-+-++--+----+++++--+-+-++-+---++++-+-----+-+-+--/| || |||| || | || | | | | | | ||||| || || | | | 84 | ||| | ||| |||||| || || ||||| | || ||||| | ||/-+----+++++--+-+-++-+---++++-+-----+-+-+---+-++-++++-++-+-++-+-+-+---+--+-+-+++++\ || || | | | 85 | ||| | ||| |||||| || || ||||| | || ||||| | ||| | ||||| | | || | |||| | | | | | || |||| || | || | | | | | | |||||| || || | | | 86 | ||| | \++----++++++-++--++--+++/| | || ||||| | ||| | ||\++--+-+-++-+---++++-+-----+-+-+---+-++-++++-++-+-++-+-+-+---+--+-+-++++/| || || | | | 87 | ||| | || |||||| || || ||| | | || ||||| | ||| | || || | | || | |||| | | | | | || ||\+-++-+-++-+-+-+---+--+-/ |||| | || || | | | 88 | ||| | || |||||| || || ||| | | || ||||| | ||| | || || | \-++-+---++++-+-----+-+-+---+-/| || | || | || | | | | | |||| | || || | | | 89 | ||| | || |||||| || \+--+++-+-+-++-+++++-+-+++-+----++-++--+---++-+---+/|| | | | | \--+-++-+-++-+-++-+-+-+---+--+---++++-+--++-+/ | | | 90 | ||| | || |||||| || | ||| \-+-++-+++++-+-+++-+----++-++--+---++-+---+-++-+-----+-+-+------+-++-+-++-+-++-+-+-+---+--+---++/| | || | | | | 91 | ||| | || |||||| ||/--+--+++---+-++-+++++-+-+++-+----++-++--+---++-+---+-++-+-----+-+-+------+-++-+-++-+-++-+-+\| | | || | | || v | | | 92 | ||| | /++----++++++-+++--+-\||| | \+-+++++-+-+++-+----++-++--+---++-+---+-++-+-----+-+-+------+-++-+-++-+-++-+-+++---+--/ || | | || | | | | 93 | ||| | ||| |||||| ||| | |||| | | ||||| | ||| | || || | || | | ||/+-----+-+-+------+-++-+-++-+-++-+-+++---+------++-+-+--++-+--+---+-\ | 94 | \++-+-+++----++++++-+++--+-++++---+--+-+++++-+-+++-+----++-++--+---++-+---+-++++-----+-+-+------+-++-+-+/ | || | ||| | || | | || | | | | | 95 | /-++-+-+++----++++++-+++--+-++++--\| | ||||| | ||| | \+-++--+---++-+---+-++++-----+-+-+------+-++-+-+--+-++-+-+++---+------+/ | | || | | | | | 96 | | || | ||| |||||| ||| | |||| || | ||||| | ||| | \-++--+---++-+---+-++++-----+-+-/ | || | | | ||/+-+++---+------+--+-+--++-+--+---+\| | 97 | | || | |^| |||||| ||| | |||| || | ||||| | ||| | || /+---++-+---+-++++-----+-+--------+-++-+-+--+-++++-+++---+------+--+-+--++-+--+\ ||| | 98 | | || | ||| \+++++-+++--+-+++/ || |/+++++-+-+++-+-\ || || || | | |||| /-+-+--------+-++-+-+--+-++++-+++---+------+--+-+--++-+-\|| ||| | 99 | | || | ||| ||||| ||| | ||| || ||||||| | ||| | | || || || | | |||\---+-+-+--------+-++-+-+--+-++++-+++---+------+--+-+--++-/ ||| ||| | 100 | | || | ||| /+++++-+++--+-+++---++--+++++++-+-+++-+-+-----++-++---++-+---+-+++--\ | | | | || | | |/++++-+++---+------+--+-+--++-\ ||| ||| | 101 | | || | ||| /-++++++-+++--+-+++---++--+++++++-+-+++-+-+-----++-++---++-+\ | ||| | | | | | \+-+-+--++++++-+++---+------+--+-+--+/ | ||| ||| | 102 | | || | ||| | |||||\-+++--+-+++---++--+++++++-+-+++-+-+-----++-++---++-++--/ ||| |/+-+-+------\ | | | | |||||| ||| | | | | | | ||| ||| | 103 | | |\-+-+++--+-+++++--+++--+-+++---+/ \++++++-+-+++-+-+-----/| || || || ||| ||| | | | | | | | |||||| ||| | | | | | | ||| ||| | 104 | | | | ||| | |||\+--+++--+-+++---+----++++++-+-+++-+<+------+-++---+/ \+----+++--+++-+-+------+-+--+-+-+--++/||| ||| | | | | | | ||| ||| | 105 | | | | ||| | ||| | ||| | ||| | |||||| | ||| | | | || | | ||| ||| | | | | | | | || ||| ||| | | | | | | ||| ||| | 106 | \-+--+-+++--+-+++-+--+++--+-+++---/ |||||| | ||| | | | ^| | | ||| ||| | | | | | | \--++-+++-++/ | | | | | | ||| ||| | 107 | | | ||| | ||| | ||| | ||| |||||| | ||| | | | || \---+----+++--+++-+-+------+-+--+-+----++-+++-++----+------+--+-+--+--+-+++--/|| | 108 | | | ||| | ||| | ||| | ||| ||||\+-+-+++-+-+------+-++-------+----+++--+++-+-+------+-+--+-+----++-+++-++----/ | | | | | ||| || | 109 | | | \++--+-+++-+--+++--+-/|| |||| | | ||| | | | || | ||| ||| | | | | | | || ||| || | | | | | ||| || | 110 | | | || | ||| | ||| | || |||| | | ||| | | | || | ||| ||| | | /--+-+--+-+----++-+++-++-----------+--+<+--+-\| ||| || | 111 | | | || | ||| | ||| | || |\++-+-+-+++-+-+------+-++-------+----+++--+++-+-+---+--+-+--+-+----++-/|| || | | | | || ||| || | 112 | | | || | ||| | ||| | || | || | | ||| | | /---+-++-------+----+++--+++-+-+---+--+-+--+-+----++--++-++-----------+--+-+--+-++\||| || | 113 | | | || |/+++-+--+++--+--++--------+-++-+-+-+++-+-+--+---+-++-------+----+++--+++-+-+\ | | | | | || || || | | | | |||||| || | 114 | | \--++--+++++-/ ||| | || | || | | ||| | | | | || | ||\--+++-+-++--+--+-+--+-+----++--++-++-----------+--+-+--+-++++++---+/ | 115 | | || ||||| ||| | || | || | \-+++-+-+--+---+-++-------+----++---+++-+-++--+--+-+--+-+----++--++-++-----------+--+-+--+-++++/| | | 116 | | || ||||| \++--+--++--------+-++-+---/|| | | | | || |/---++---+++-+-++--+--+-+--+-+----++--++-++-----------+\ | | | |||| | | | 117 | \-----++--+++/| || | || | || | || | | | | || ||/--++---+++-+-++--+--+-+--+-+----++--++-++-\ || | | | |||| | | | 118 | || ||| \-----++--+--++--------+-++-/ || \-+--+---+-++-------+++--++---+++-+-++--+--+-+--/ | || || || | || | | | |||| | | | 119 | || ||| || | || | |\------++---+--+---+-++-------+++--++---+++-+-++--+--+-+----+----++--++-++-+---------++-+-+--/ |||| | | | 120 | \+--+++-------++--+--++--------+-+-------++---+--+---+-++-------+++--++---+++-+-++--+--+-+----+----/| || || | || | | |||| | | | 121 | | ||| || | || | | || | \---+-++-------+++--++---+++-+-++--+--+-+----+-----+--++-++-+---------++-+-+----++/| | | | 122 | | ||| || | || | | || | | || ||| || ||| | || | | | | \--++-++-+---------++-+-+----+/ | | | | 123 | | ||| /--++--+--++--------+-+-------++---+------+-++-------+++--++---+++-+-++--+--+-+----+------\ || || | || | | | | | | | 124 | | \++----+--++--+--++--------+-+-------++---+------+-++-------/|| || ||| | || | | | | | || || | || | | | | | | | 125 | | || | || | || \-+-------++---/ | || || || ||| | || | | \----+------+-++-++-+---------++-+-+----+--+-+---+--/ 126 | | || | || | || | /-++>---------+-++--------++--++---+++-+-++--+--+------+-\ | || || | || | | | | | | 127 | | || | || | || | | || | || || || /+++-+-++--+--+------+-+----+\|| || | || | | | | | | 128 | | ||/---+--++--+--++----------+-----+-++------\ | || ||/-++--++++-+-++--+--+------+-+----++++-++-+--------\|| | | | | | | 129 | | ||| | || | || | | || | | || ||| || |||| | || | | | | |||| || | ||| v | | | | | 130 | | ||| | || | \+----------+--->-+-++------+---+-++--------+++-/| |||| | || | | | |/---++++-++-+-------\||| | | | | | | 131 | | ||| | |\--+---+----------+-----+-++------+---+-++--------+++--+--++++-+-++--+--+------+-++---++++-+/ | |||| | | | | | | 132 | | ||| | | | | | | || | | || ||| | |||\-+-++--+--+------+-++---++++-+--+-------++++-+-+----+--/ | | 133 | | ||| | | \---+----------+-----+-++------+---+-+/ ||| | ||| \-++--+--+------+-++---++++-/ | |||| | | | | | 134 | /--+---+++---+--+-------+----------+--\ | || | | | ||| | ||\----++--+--/ | || |||| | |||| | | | | | 135 | | | ||| | | \----------+--+--+-++------+---+-+---------+++--+--++-----++--+---------+-++---++++----+-------++/| | | | | | 136 | | | ||| | \------------------+--+--+-++------+---+-+---------+++--+--++-----++--+---------+-++---+++/ | || | | | | | | 137 | | | ||| | | | | || | | | ||| | \+-----++--+---------+-++---+/| | || | | | | | | 138 | | | ||\---+---------------------+--+--+-++------/ | | ||| \---+-----/| \---------+-++---+-+-----+-------++-+-+-+----/ | | 139 | | | || \---------------------+--+--+-++----------+-+---------+++------+------+------------+-++---/ | | || | | | | | 140 | | | || | | \-++----------+-+---------+++------+------+------------+-/| | | || | | | | | 141 | | \---++--------------------------/ | || \-+---------+++------+------+------------+--+-----+-----+-------++-+-/ | | | 142 | | || | || | ||| | | | | | | || | | | | 143 | | || | || | \++------+------+------------+--+-----+-----+-------++-/ | | | 144 | | |\-----------------------------+----++------------+----------++------/ | | | | | || | | | 145 | \------+------------------------------/ || | \+-------------+------------+--+-----+-----/ || | | | 146 | | \+------------+-----------+-------------+------------/ \-----+-------------/| | | | 147 | | \------------+-----------+-------------+---------------------+--------------+-----/ | | 148 | \-------------------------------------------------+-----------+-------------/ \--------------+---------------+---/ 149 | | \--------------------------------------------------/ | 150 | \------------------------------------------------------------------------------/ 151 | --------------------------------------------------------------------------------