File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ from itertools import count
2+ from math import prod
3+ import re
4+
5+ import numpy as np
6+
7+ with open ("input" ) as f :
8+ ns = [list (map (int , re .findall ("-?\\ d+" , x ))) for x in f .read ().strip ().split ("\n " )]
9+
10+ # Part 1
11+ w = 101
12+ h = 103
13+ qs = [0 , 0 , 0 , 0 ]
14+ for px , py , vx , vy in ns :
15+ px = (px + 100 * vx ) % w
16+ py = (py + 100 * vy ) % h
17+ if px != w // 2 and py != h // 2 :
18+ qs [(px > w // 2 ) + 2 * (py > h // 2 )] += 1
19+ print (prod (qs ))
20+
21+ # Part 2
22+ zs = np .array ([px + 1j * py for px , py , _ , _ in ns ])
23+ vs = np .array ([vx + 1j * vy for _ , _ , vx , vy in ns ])
24+ max_has_neighbour = 0
25+
26+ for t in count (1 ):
27+ zs = np .array ([int (z .real ) % w + (int (z .imag ) % h ) * 1j for z in zs + vs ])
28+ zs_set = set (zs )
29+ num_has_neighbour = sum (z + dz in zs_set for z in zs for dz in (1 , - 1 , 1j , - 1j ))
30+ if num_has_neighbour > max_has_neighbour :
31+ max_has_neighbour = num_has_neighbour
32+ a = np .zeros ((h , w ), dtype = int )
33+ a [zs .imag .astype (int ), zs .real .astype (int )] = 1
34+ print (t )
35+ print ("\n " .join ("" .join (" ■" [x ] for x in row ) for row in a ))
36+ print ()
You can’t perform that action at this time.
0 commit comments