diff --git a/day11/input b/day11/input new file mode 100644 index 0000000..5550d0e --- /dev/null +++ b/day11/input @@ -0,0 +1,140 @@ +.#...........#.........................................................................#...............#...........#........................ +.......................#.................................................................................................................... +...............................#...........#.................#.............................#.............................................#.. +......#............................................#........................................................................................ +......................................................................#.....#.....................#......................................... +.................#.......#.......................................#................#.....#.....................#............................. +.........................................#.................#................................................................................ +................................#.............................................................#..........#.................................. +#.......................................................................#..............................................#.................#.. +..........#....................................#......................................#............................................#........ +................#....................................#........#............................................................................. +......#........................................................................#............................................................ +......................#..............#..............................................................#..........#.....#...................... +..................................................#.......................#..................................................#..........#... +............................#............................................................................................................... +........#................................................................................................................................... +..................#.......................#................................................................#................................ +.............................................................#........#..................................................................... +..............................#.......#......................................#.............#........................#....................... +.#............................................................................................................#...........................#. +...................................................................................................#....................#................... +....................#......................#.............#.....#..................................................................#......... +.................................................................................................................#.......................... +............................................................................................................................................ +....................................................................#.....................#................................................. +.................................#..............................................#..............#............#.............#................. +...........................#............................................#...........................................#....................... +......................#.........................#........................................................................................... +.......................................#....................................#...................................#........................... +.....#..........#.........................................#...............................................................................#. +#..........#......................#...................................................#.......#.....#....................................... +.........................#.................................................................................................................. +....................#..............................#.............#.........................................#.......#........#............... +...........................................#........................................................................................#....... +...........................................................#....................#........................................................... +..........#....................................................................................................#............................ +...............#................................#..........................#..............................................................#. +..#.................................#.................................................................#.......................#............. +.....................#......#...............#........................#................................................#..................... +..............................................................................................#....................................#........ +................................#.......#................................................................................................... +..........#................................................#...................#.....#..............#..........#..........#................. +.........................#.................................................................................................................. +..................#...............................#...........................................................................#............. +.........................................................................#............................................#..................... +........#.....#..............................................................................#.........#..................................#. +.#...............................#......#............#.............................................................................#........ +....................................................................................#.............#...............#........#................ +...........................#................................................................................................................ +......................#..................................#..............#................................#.............#................#... +...............................................................#..............#............................................................. +..................................#........................................................#........#....................................... +......#.................................#.......#....................#...............................................................#...... +.................#............#..............................................................................#.............................# +............................................................................................................................................ +..#.....................#.............................................................................#..................................... +.......................................................................................#..............................#..................... +...............................................................................#.............#.............................................. +....................#.....................#...............................................................#................................. +..........#........................#............#...................#.............................................#...............#......... +............................#.............................#..........................#...................................................... +...........................................................................................#................................................ +.................................................................#.................................#.........................#........#..... +.................#........................................................#..................................#.............................. +......................................#......................#.............................................................................. +.............#...........#...............................................................................#..........#....................... +.................................#...........#...........................................................................#..............#... +.......#............................................#.....#....................#..............#.....#....................................... +...................#...........................................#................................................#........................... +........................................................................................#................................................... +...#....................#.....#............#.........................................................................................#...... +...............#.............................................................#..................#........#................#................. +.........#.....................................#............................................................................................ +................................................................................................................................#........... +.....................#.............#.........................................................................#.............................. +.....#...............................................................................................................#..............#......# +...........#.......................................#.....#.................#.................#.............................................. +............................................................................................................................................ +.#.......................................#..........................................#................#...................................... +......................#.............#.................#.......................#...........#.............................#................... +...............#.............#................................#......#.......................................................#.............. +............................................................................................................................................ +...#............................................................................................#....................#...................... +..........#.....................#.............................................................................#............................. +...........................#...............................................................................................#...............# +.....................#......................................#.......#......#........#..................#...........................#........ +.....#...............................#............#......................................................................................... +............................................................................................................................................ +.........................................................#........................................................#......................... +#..............................#..........#..............................................................................#................#. +....................#..............................................#.......................#.........#...................................... +............................................................................................................................................ +...........#.......................................#.............................................................................#.......... +...#......................#...............................................#......................#.......................................... +..................#......................................................................................................................... +...........................................................#........#...........#.....#......#........................#.................#... +........#................................................................................................................................... +....................................................................................................#......#................................ +................................#...........#....................#.....#...................................................#........#....... +........................#............#......................................#.............#................................................. +...................#............................................................................................#........................... +#................................................................................................................................#.......... +..............#.............................................#............................................................................... +..............................#...............................................#.................#......................................#.... +....#....................#......................................#...................#...............................#.......#............... +........................................#..........#........................................#................#.............................. +............................................................................................................................................ +............................................................................................................................................ +........................................................................................................................................#... +...........................................................#..................#.................#.................#......................... +.......#........................................................#................................................................#.......... +..........................#......#......#..................................................................................#................ +...............................................#.....#.................#.................................................................... +......................................................................................................#..................................... +................#....................#.....................................................................#........#....................... +..............................................................................................................................#............. +...........................................#.............................................................................................#.. +....#........................#..............................#.............#................#................................................ +......................#..........................................................................................#......#................... +....................................................#................................#.........#............................................ +..........................#.......................................#......................................................................... +.................#........................#.....#........................................................#.................................. +.#.........................................................#............#....................................................#.............. +..........#..................#.....#..................................................................................................#..... +.................................................................................#.......................................................... +.....................................................#....................................#.........#...........#.....#..................... +.............................................#.....................#.......................................#.......................#........ +................................#........................................................................................................... +......#........................................................#..............................#............................................. +............#......................................#.....#............................#........................................#............ +............................................................................#............................................................... +.......................................#...............................#...................#..............................#...........#..... +.......................#..............................#..........................#..............................#........................... +.................................................................#...................................#...................................... +......................................................................................................................#...................#. +.................#.......................................................................................................................... +.........#......................#.....#...........#.......................................................#................................. +...........................................#.................#................#.....................................................#....... +..#...............................................................#......................................................................... +.....................#......#......#.............................................................#............#...........#................. diff --git a/day11/sample1.in b/day11/sample1.in new file mode 100644 index 0000000..986aad4 --- /dev/null +++ b/day11/sample1.in @@ -0,0 +1,10 @@ +...#...... +.......#.. +#......... +.......... +......#... +.#........ +.........# +.......... +.......#.. +#...#..... diff --git a/day11/sol.tcl b/day11/sol.tcl new file mode 100755 index 0000000..8f7b696 --- /dev/null +++ b/day11/sol.tcl @@ -0,0 +1,74 @@ +#!/usr/bin/env tclsh + +source ../prelude.tcl +set input stdin +set map [split [string trim [read $input]] "\n"] +puts $map + + +proc empty {row} { return [regexp {^\.+$} $row] } + +set map' {} +foreach row $map { + if {[empty $row]} { + lappend map' "${row}" + } + lappend map' $row +} +set map ${map'} + +puts $map + + +proc column {i} { + global map + set c {} + foreach row $map { + lappend c [string index $row $i] + } + return [join $c ""] +} + + +set map' {} +set W [string length [lindex $map 0]] +for {set i 0} {$i < $W} {incr i} { + set col [column $i] + if {[empty $col]} { + lappend map' $col + } + lappend map' $col +} +set map ${map'} +puts [join $map "\n"] + +set points {} + +for {set x 0} {$x < [llength $map]} {incr x} { + set col [lindex $map $x] + for {set y 0} {$y < [string length $col]} {incr y} { + if {[string index $col $y] eq "#"} { + lappend points $x $y + } + } +} + +puts $points + +proc dist {x y u v} { + return [expr {abs($x-$u) + abs($y-$v)}] +} + +set mins {} +foreach {x y} $points { + #set d 100000 + foreach {u v} $points { + if {$u > $x || ($u == $x && $v > $y)} { + #set d [min $d [dist $x $y $u $v]] + lappend mins [dist $x $y $u $v] + } + } + #lappend mins $d +} +puts $mins +puts [ladd $mins]