diff options
author | Aleteoryx <alyx@aleteoryx.me> | 2024-12-09 21:09:57 -0500 |
---|---|---|
committer | Aleteoryx <alyx@aleteoryx.me> | 2024-12-09 21:09:57 -0500 |
commit | 0f6d3c97e450d129b020b6fe2f3d63bc0bc7aa61 (patch) | |
tree | 4068a09e59fb383481618ff3746d6053bb70e341 | |
parent | 3cb8f4912dac55f840089940374f92e7c618c3c0 (diff) | |
download | adventofcode-0f6d3c97e450d129b020b6fe2f3d63bc0bc7aa61.tar.gz adventofcode-0f6d3c97e450d129b020b6fe2f3d63bc0bc7aa61.tar.bz2 adventofcode-0f6d3c97e450d129b020b6fe2f3d63bc0bc7aa61.zip |
2024.8
-rw-r--r-- | 2024/input.08.txt | 50 | ||||
-rwxr-xr-x | 2024/tcl/08.tcl | 69 |
2 files changed, 119 insertions, 0 deletions
diff --git a/2024/input.08.txt b/2024/input.08.txt new file mode 100644 index 0000000..a0e2233 --- /dev/null +++ b/2024/input.08.txt @@ -0,0 +1,50 @@ +............s...............1..................... +......................E......3.....S.............. +.......................3.....S.................... +...e........T.t.......S.1...........I............. +..................B..................I.....O...... +g.......z........i39......B..I.................... +.......s....S.......3......................i..I... +....e.............2..........B.................... +.......tC...z.......g......1...................... +.E......s....R.................................... +..G...t..........2................................ +.........K...C.......2............................ +....T..e...........5...C.......................... +...T................................O...o......... +...............................g..............o... +.........z...................g......i............o +...9.E............H...........Y.......O........... +..........R..H...............7.O.................. +...........H.............v......7........B........ +..9.Q.......................W......1........Y..... +.........................z.7.................Y.... +.....Q................................v........... +....K.......E.....R...............2..........o.... +.n............H......v...........................Y +.G.y..........................Q................... +......G....A5.....................h............... +..........D...5.w...9............................. +......n....5...L.................................. +............................v..................... +............L...0t..........7..................... +..n....k............y....................W........ +..k..........0.........................W.......... +...n.......R..L..a........................W....... +.........................................h........ +..0..L........c...b............................... +.....................8.y.......................... +.......w.................6.............h.......N.. +..........y..4.................................... +...0....8...k.....Z........r...................... +..............a...8Z.........G......4............. +........4..b.q.....................K.............. +.q...........kZ.K......b..D.........d............. +.8.....................D................r......... +.....w.........a...............d........A......... +................................d.A.hV............ +................c..........D.....V....r........... +.......Z......6.....l........................A.d.. +...................l..6..c....b......r...........N +......a....4........q..l..V..c................N... +l.....w...........q..6............V............... diff --git a/2024/tcl/08.tcl b/2024/tcl/08.tcl new file mode 100755 index 0000000..e62ed69 --- /dev/null +++ b/2024/tcl/08.tcl @@ -0,0 +1,69 @@ +#!/bin/env tclsh + +source lib.tcl +setup 8 grid + +puts {Part 1: Antinode count in map} + +set antinodes {} +set resonant_antinodes {} +set antennae {} + +for {set x 0} {$x < $input(w)} {incr x} { + for {set y 0} {$y < $input(h)} {incr y} { + set cell [lindex $input(grid) $y $x] + if {[regexp {[a-zA-Z0-9]} $cell]} { + if [dict exists $antennae $cell] { + foreach antenna [dict keys [dict get $antennae $cell]] { + lassign $antenna x2 y2 + dict set resonant_antinodes [list $x $y] 1 + dict set resonant_antinodes [list $x2 $y2] 1 + + set xoff [expr {$x - $x2}] + set yoff [expr {$y - $y2}] + + set ax [expr {$x + $xoff}] + set ay [expr {$y + $yoff}] + if {$ax >= 0 && $ax < $input(w) && $ay >= 0 && $ay < $input(h)} { + dict set antinodes [list $ax $ay] 1 + + while {$ax >= 0 && $ax < $input(w) && $ay >= 0 && $ay < $input(h)} { + dict set resonant_antinodes [list $ax $ay] 1 + set ax [expr {$ax + $xoff}] + set ay [expr {$ay + $yoff}] + } + } + + set ax [expr {$x2 - $xoff}] + set ay [expr {$y2 - $yoff}] + if {$ax >= 0 && $ax < $input(w) && $ay >= 0 && $ay < $input(h)} { + dict set antinodes [list $ax $ay] 1 + + while {$ax >= 0 && $ax < $input(w) && $ay >= 0 && $ay < $input(h)} { + dict set resonant_antinodes [list $ax $ay] 1 + set ax [expr {$ax - $xoff}] + set ay [expr {$ay - $yoff}] + } + } + } + } + dict set antennae $cell [list $x $y] 1 + } + } +} + +puts "Antinodes: [llength [dict keys $antinodes]]" + +puts "" +puts {Part 2: Resonant antinode count in map} + +puts "Resonant Antinodes: [llength [dict keys $resonant_antinodes]]" + +#foreach ra [dict keys $resonant_antinodes] { +# lassign $ra x y +# lset input(debug) $y $x "#" +#} + +#foreach line $input(debug) { +# puts [join $line ""] +#} |