diff options
author | Jack Sangdahl <[email protected]> | 2024-12-07 22:57:33 -0700 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2024-12-07 22:57:33 -0700 |
commit | de47d10a64bbc19bec07fa60091a866506ed15ba (patch) | |
tree | b898edb0fa8f2966ca96418092132bc854c39607 | |
parent | 18f63e38d377c45d149e8b0fb174068d9b9545df (diff) | |
download | aoc-de47d10a64bbc19bec07fa60091a866506ed15ba.tar.gz aoc-de47d10a64bbc19bec07fa60091a866506ed15ba.zip |
Day 8 2024
-rw-r--r-- | 8_2024.py | 42 | ||||
-rw-r--r-- | data/8_2024.txt | 50 |
2 files changed, 92 insertions, 0 deletions
diff --git a/8_2024.py b/8_2024.py new file mode 100644 index 0000000..e18f383 --- /dev/null +++ b/8_2024.py @@ -0,0 +1,42 @@ +from collections import defaultdict + +input = "data/8_2024.txt" +data = open(input).read().strip() +line = data.split("\n") +row, col = len(line), len(line[0]) +a1, a2, dic = set(), set(), defaultdict(list) + + +for r in range(row): + for c in range(col): + if line[r][c] != ".": + dic[line[r][c]].append((r, c)) + + +for r in range(row): + for c in range(col): + for k, vs in dic.items(): + for r1, c1 in vs: + for r2, c2 in vs: + if (r1, c1) != (r2, c2): + d1 = abs(r - r1) + abs(c - c1) + d2 = abs(r - r2) + abs(c - c2) + dr1 = r - r1 + dr2 = r - r2 + dc1 = c - c1 + dc2 = c - c2 + if ( + (d1 == 2 * d2 or d1 * 2 == d2) + and 0 <= r < row + and 0 <= c < col + and (dr1 * dc2 == dc1 * dr2) + ): + a1.add((r, c)) + if 0 <= r < row and 0 <= c < col and (dr1 * dc2 == dc1 * dr2): + a2.add((r, c)) + + +p1 = len(a1) +p2 = len(a2) +print(p1) +print(p2) diff --git a/data/8_2024.txt b/data/8_2024.txt new file mode 100644 index 0000000..deeba80 --- /dev/null +++ b/data/8_2024.txt @@ -0,0 +1,50 @@ +...........................A.............W........ +.......x..........AZ......P.........m......k..W... +....v.....Z..K...V..........A.......R....f........ +.............d..........V.............2........... +.........Z........d...V.....B....C.....e.......... +............Z.vA...........m...................s.W +...x..o.....................ek.................... +...O.....VK..................R......B............. +.........O..................my....kB.............. +.v...................y..........C........B.....z.. +xb.v..................................C..z........ +.........................2.ey..................... +..K.......................y...................s... +..........................................z....... +.......................2.......R........z......F.. +O.....d..................D..k.........F........... +..........O..........D.............s....E......... +..o......9....................D........C..s....... +.....o..r....................c...................m +.......P..............................e........... +..............1......................d............ +...................o...............3.............. +........................c.......24..........S..... +....x..................c.............F4.........S. +P............N..8.......W.D....................... +.....K............1.8............................. +.........P..............Q...M..................... +9...................R........4...8.....0.......... +....n.........................F................... +........Y...n......1......................3..J.... +.........................3...8.................... +...n...M............................0.......ja...S +....f................................6.....S.....E +....................i.........M...J............... +...r..........q..........1......l..0.....L........ +.........f7....i.Nc......................j.......l +..9....Y7......X.........Q...M5....J4...........3. +.Y........NX..I............Q........L............. +......Xw...nb.............0..............l6....... +......b.....f....5..q.....................a..6.... +.......5..........iq.9.....p..........a........... +........X........I................p...6........... +..................N.............L.........j....... +...b.7.......................p....Q......E........ +....Y....7......................p................j +.......r.......................................... +.................i...................a............ +..w.........5..................................... +......w........I..............J................... +.w............r.....................lL............ |