diff --git a/day14/input b/day14/input new file mode 100644 index 0000000..db47c66 --- /dev/null +++ b/day14/input @@ -0,0 +1,100 @@ +.O....O.OOO..O.#.#.###.#O....OO..OO.O...O...O###..#.#....#.#....##..O.O.O##.......O.#.O.......##O#O. +..#.#.#......O........O#OOOO#.O.#.#.#..O.#O...#..O...#..O.O#......#O...##O...O.#...O.O...##O.O.O...# +.......O.OO..O.##.#..O.#...O#.#.......O.O.##.......#.O..#.......O.....#...O...#.#OO......#....#..... +....#.....O#.O..O..#..#OO.#OO....#.......O..O.O...#.....#.O.....O..O.O....#..#O..O.#.O....O.......#O +.........O.O....O.#O..#..........#O#......###.#..OO...#.O#O.O.O#....##...O.O..#.O..OO.#.OO...O#.OOO. +.#O..#.O....#O...O#.........O#O..#O..#O.O.OO..O..#...#O...O..OOOO.....O..O.........O..#O##......O##. +..O#.O.....#.O..O.#.O......O#O.#..#.O.O..#..O.O#..O..#O.....##.#....#..OO.#.........OO....#...O....O +.O.O#..O.###....O#....O...#....O.O....O.O.O......O.O###OO.#.O...O..O..O.....O.#.O#..OO..O#.OO#OO.#OO +OO...#O#......#####OOO.O###...........O#....#.#.O.O.##...O#.O...........OO.#...#......O.O....#..O..# +.O..OO....#.#.##O.O#..OO....#...O..O...O.O###.##O.......#O.....##.O..O##.....O...OO.#....#.#.O.....# +OOO#O.....O.O....O.O#....O.OOO........#..#.O..#...O...OO#.O...OO#..O..O.#..##.......#......O....O.O. +......O..OOO..OOO..##OO...O...#.#.#..O..#..#OOO...O.O.O#......O#.....#..O#O...#.OO.....#.O.#.OOO..#. +O...........OOOO.OO#O....#........O...#.##......#.OO..O.OO.#.O.....OO#.#..#.OOO.#.#..#..O.....OO..#. +....O..O.O.#....OO.#.#O..#....#..O#..........O..O.O#......#....###.O.#..#.#......O......O....#.#O..O +....#O....#..OO..O#O.#.OO##O..O##..O..O.......##......OO..OOO#..O..OO....O.#..O##..#......#.O.....OO +.O.#.O..##O#...##....##.#.O..#O#O.......#...O..........O.O.......O.....O..#.....#....#.O.#.#...O...O +....###....#.....#O.#O###O#.O....#O#O.##.OO#.O#O..#..O..#..#.O##.............O....#O...#.....O...O## +.O...##....O..#..#..O#.......O....O...O.O..#O...#.......#.......O.O..O#.O##..O.O......#...#......O.. +......O##..OOOO#.........O......O.#O.....#OO..#.O..OO......#.O...##.##...O#.........#.....#......... +.#.....OO....OO..O.#OO#..#.#.##.O....O..OO.O.........O..O.O....##...#.O#.O..#........O#.O##.#...#.OO +.O.#....O.O#......OO..#OOO.O........##.O.....#O......#.....OO..O#..O...O..O#O...........#.#O...#O... +....O#O...#...#..#.##O...OO.#.#.O..#....O....#.O....##.........O.O.#...#...#....O...#...##.#..#...O. +..#O##...O.OO.#.#....O...#...#....O...O....#.#.O.O.OO..O.OO.......#.O#....O##.O#.O..O##O........OO#. +.#...##.#.O...O..........O.O##..##.O###..##...O..#.O.....O##O...O.....O.......O..#..#.O#.#....#O#... +O..#O#.O......#..##.O...O.##O.#...O....O.O.#....O........OO..#.O...O....###.O.O#.#O...O.#O.....#.O.. +#.O...O.O......O.O.O....O..#O...O..OO.OOO...#.O.OO....#......#.#.O.O#..O..O...#O#.......O.OO.##..O.. +..OO..#O#.O#..##....#..OOO...#O..O.O.#.#.OOO#.#...#.OO#O......#.#..#......OO..O..#..#..##..O#....O#. +.OO#...O#O.#.#..O..#......O...O......O#.#.##O...#.#..#..#.###..O.###.#....O...O..#...#O......O....O. +O....#O..##...O...O..O#O#.....#O.....#..#.#....#...##..#.....#.#......###O....#OO#.##O..O.O....O.... +....O.###.....O...O.O...O...O#OO..#.#.....O.OO.....#O...##O#OOO.#..O...OO#O.O....O....O..#..O....#.. +...O..#O..O...O......##OO..O..O.....O....O..O##O.#OO..#O..O.#......#.O..#O.......O....O#...O.O.....O +...O#O..#..O.O......O.....#..................#O..##.#....O..O....O#...##.O...#.O.#........#O#..#..OO +O....O.#.......#O#....O...O.#O...OO.O..OOO..#...#.OOOO.O..#..#....O.........#.#..O..#..#.#.O..OO.O.. +#O..O......O...O#......O#..#...O.#O.#.O...#.#.#.O....#O.#..O#...OO...#O#..O...#O.#.##O.O..O#O#.#O.O# +#.##...O..O.O...##...O..#OO...OO........O....OO..OO.......O##.OO..#..#............#.O.......#.O.OO#. +O#..#.OO..##....#O..OO..#...#..#..###.#O...O#..#.....O.O.#OO.........O..O...#....#.#O....#.O.....O.. +..OO.O......O.OO.OO.....O..#OO...##.O.O.O.#.#O#..#...O...O...#...O...O...#.........#....#.#.O#...... +O..#.....##O.#O....OOO.........O..#...#......##.#O.......O.OO....OO..OO..#.#...O#O..##........#O..O. +##.O...#..#.O##.O......O...#....#.O..#...OO....O.OOO...#O#.#OO....##.#O......##......O..OO.......#.. +....O........#.O#...........O..#..#OO.OOO#.OO##...#.OO............##O...O.O.O#.....#..#.O.#.#.O...O. +O.#....O....#...O#O..#O.O..#..#O...#.O..O.O.....OO....OO##....O.O#.......#...O.....#OO.#....O.OOO... +O...#..#...#..OO...##.....#OO#O....#.#.OO.......O..O..O..#..#......O..OO...O.OO.O..OO#..###O#O.....# +........OO#.O..#.....###....O........O....O.O..O#.OOO....#OO##.O#OO.......#.O......O.O......O...O.O. +...#.#...#O..#...O.#.OO.O........O#....#O..O..O.O#.O...#..#.OO.OOOO.#...#...O...#O..#..OOO..O...O#.O +O.OO#O#.#.#O..O#OOO..O..#.##..#.##OO#.#..#O.O#O.O...OO...O..O.......O.......##........#.##.......#.. +OO.O.##.#.#...#...OO##.....#.O...#....O#.#.O..O..#...#....#O...OO....#.O...##O....#O.O..O#O...OO#.#O +.#...#....#....O#.O..#...OO##...O.#.#......#.O###.O.#OO....#......OO.......O#..#O#.OO..O.O......#O#. +..O#..O..O....#.#..#OOO....##O..#...O...##..##..##.O.O#...O......#........OOOO..O#.....O.#.#O.....#. +.#..#.O.........#..........OO.#...#.#..O...##OOO.......O..O###..#...#.......#.OO#..O..#....#OO...... +.O..#.##.O..#..O....#.O......O#.......#..O.OO..O...#....##..O.#O.#..#.##O#.O..OO#O.#..O...#.#.O.O#.O +##....OO..##.OO....OO#.O#.O.#..#...O..#.#.O...O.O......O#...#.##.O........OO.....#O...##.#..OO.....O +..#.OOO......O.....O.#..O..O##..O..#.#...OO..#..O....O..#.#O........#.#.O...#.O....#...O...O......O. +..O#..#.#.#.O...O#..O.O..O.O#O...O..O..#O...#..O.O....#....O#...#O..##.#O..O.##O.O.#..O.O.....OO...O +..#.....OO....O.O..#....OO..O...#.#..OO..#O..#...O..O..#.##.OO.O.O.O.O.....#..#...#O.##..O...O.#.#.. +....O...O....OO.......O.O.....O....OO...###..O##.......#...#O.#.O....O..#.O...#.OO#..O#.#..#...##... +...#O....OOO.OO..#.#.O.O.O.#..O..O#...O.#O..........#..#OO...#.O..#O...OOO..#...#....#...O.OO#O....O +O...O....O.O...#...##O...O....OO#O.O##.##..O..#...OO.......#....OOO.O.#.#....O...OOOO.#.....#....#O. +.....OOO....O..O.#..O#O#......OO...........#......O.OO.OO.#..O..#.O#.OOOOO.O..##OO...O..#.O..O.O.O.O +#..#.O..OO....#.###O...O....#O#O#OO...O.O#.....OO.O..O.O......O.OOO#.........O.#..O..O.O.O#.O.O..OO. +#O.O..#....#O.#..O#OO....O........#.....O...##...OOOO.O............O.....OO.O....##O..##.#......O... +O#.#..#.O.....#O....#.#..O.O.......O..O...#OO....#...OO.#....O.O.O.....O...#O.#O.O.O#....O#......... +..O.O......O..#.O..O..O#OO........O..#.O.#.....O#O#O#.#O#..##O....OO.#..O.O#..OO.....OO.OO......##O# +.OOOO.##.#.#......O..O...O##O##.O.OOO#.O.O.OO....O.......O.#....O..##......#...O..#..##O#OO..##...O. +......#O.##....#...O.#.#.O##..O.#.......##.OO#O#.##..O.....#.#.#O.....#O.O#O......O....#.#....O#.OOO +..#......#..O#.......O#.#OOO...#...O#............O.O.#.#O..##...#O#O....#.....##O#.O.OO...O...O#.OO. +.#.O.#.#.OOO..#.#.O#...#..#...O...O...O#.OO...OO.O#..O.#...OO#.#..O....#.O#.O#..O#.##.O.O..O.O#.O.O. +O.O#.OO#O.OO#O.....O.O.O.O...#OO....#.#...O.O.OO.O#.#.O.OO..#.O.O...#.....#....OOO....#.O.O.OO#...O. +O#O......O......O..#......O.....#O#O..O......#...O....O#O##.....O#....#...#.#.....OO#.O.O.O#OO..#.#O +O#.....#.O#O.#.....O.OOOO........#.#O......OO.O.O.....O....#O.##.O.....OO....O#..O......O......#..OO +..#..#..OO..#.#...#O...###...O...#.#....O...O.#..O...O.O.#......#......#O.O...#OO.#O...#.O....O...O# +OOO.O.OO..#.O.#O.OO.........#..........#.O#......O..#O.#..#O......#..#.O#.......O..............O..O. +.OO.O.....OO...O.O..##....O.......OO..#O##..O..#.#.O#.#.O.....#..#.O.......O.##.O..#.OO.OO.......... +.........##O.#.#......#...O...##OO.OO....OO...#.OOO#.....O..#...#O.O..##.O#.O...........O#.O#.#O.O.. +..O#..#O#..........OO.O......#...O.....O.O#..O#.#..........OO...#.#...O##....OO.#O.....##O...O.#.... +.###.O.#O.#....O.#.#O#..O..........O..#.##O.#...O.O#..#..#O.O.##...#O....O.#..O.O..#.O..#O#.#......O +OO.......#.O...##..#.#..#OO...O...............OO#.....#.O...#.........#..O...O....O.....##..O....... +.#..O..##.OO..O#...O.....OOO.#..O#.OO...##.O.OO.O...OO.O.O#O.....O#...........#..OOO.OO##.O#..#OO.O. +.O.....O..#...O..O......O.O...O.....O........O...#.#O...O#O.O...###.O..O.O...#O...O.O.OO.O.O...O#OO. +.............#...#O..O#O.O.O....O................#....O....#O.O..........OO#.##..#.O##.........#.... +#O##O#OOO.#..O..O....O..O.##..OOO..O.O...............O..O.O#O.###......O...O......OOO.##.#...OO..O.# +O...OO#O.O#.OO..OO........#.O....O...#........O...#..O...##O...O#...........#.O.#...O#...O#..#OO..O. +.##O.#...O...O....#O#...#O.O#.O##...#....O#..#..#OO....#......#..O#..O.O..O...O..........O...#..O... +.....O...#...........O..O..##.....O.OO.....#O..OO..#..O.....#......O...##O##.#.#...O.OO.OO##.#.#..#. +#..O...#.##O#.#OO..##O....O...#.O.#O#..O...OO..O....O#O#.#....O...........O......##O.....#...#...##O +O..........OO..O.#..O.#...O.#.#.#......#.O..O#......O....O.O.O.O.##.O#..##....O#O#....O........#.O.O +OO...##.....O..O.#O...O..OO.#.O.O.#.O.........O...O.O.O.O.#.#O...O..#.O.....#....#..#...O#..#..O...# +O##...#OO#.##.OO.O..#..OO.......OO.OO#.OO..O.......O.......OOO.#...#O#O.#..O......O..O.....#...##.#. +#..O..#.OO.#.O.O.O.#.O##...#.O.O....###......O#OO.......OO..OO....#...O...#.........OO....O.......O. +...#.#.##.....#...........O.OO.....O.OO..O.O..#..#....#..#O..O#....O#OO##.#.....O.....#.......O#O.O. +.#..O.#...##...O.O.#...O.....#O.#O..#.OOO...........##.....#.#O#.##....OO#.O.....O.....OO.O.O.OO.... +#O#..OO..O#..O..O...OO.OO.#.....OO.......#.....O.O.O#..OOO......O.#..#O...O..O..O.#....O.O..OO#OO#.. +O.###O.O...O.....O..#.O..O...O..OO##.O..##..O..O...##O.#....#.O.O....O.O.........#OO#O....O.....O..O +........#.O...O...#.#.#OO.O.#.O.....O#...O....O..#....#..O..#..........OO..#.O....OO.O..O...OOO...O# +.#.#...........O.O.......#.#O..O....#O..O...O.O..O..#.#.....O.....O.#...OO.O....#O..O.O#.O.....#.... +.O.#...##.#.OO..#O...#....#.#.......#...#O....#.....O...O#.#.OO.#.O#.....OO....#.OO..#..O.O.OO....O. +.OO#OO#.##.##OO..O.....O..O#OO.O.#....#....#.OO##..#..#.........#..............OO...O.....O.......#. +..O.....#..#.......O..#O...#...#.O.........###.#...O.O.#....O................O.#O#O#..O..#.#...#..#O +..#O...O.......OO#.#..#O.....OO.OO..O..##....#.O#...#.O..O.OO.....#..O...OO.O.O....#O..O.#..#......O +.O.......O.....O..O...#.....O..O##..#......O.#...O#O.#.O.O.O.OO.O.#......OO.OOO.O#.OOO#O...#..#.O... +...O.O#.OOO##.O#O...O##.O....O..O.##.#OO..O#.O.O...OOO#..O...##......#O........O..O.O....O........OO diff --git a/day14/sample1.in b/day14/sample1.in new file mode 100644 index 0000000..5a24dce --- /dev/null +++ b/day14/sample1.in @@ -0,0 +1,10 @@ +O....#.... +O.OO#....# +.....##... +OO.#O....O +.O.....O#. +O.#..O.#.# +..O..#O..O +.......O.. +#....###.. +#OO..#.... diff --git a/day14/sol.tcl b/day14/sol.tcl new file mode 100755 index 0000000..abc5f88 --- /dev/null +++ b/day14/sol.tcl @@ -0,0 +1,38 @@ +#!/usr/bin/env tclsh +source ../prelude.tcl +set input stdin + +proc roll-left lane { + set prev {} + while {$prev ne $lane} { + set prev $lane + #regsub -all {(O+)(\.+)} $lane {\2\1} lane + regsub -all {(\.+)(O+)} $lane {\2\1} lane + } + return $lane +} + +proc calc-load lane { + set N [slen $lane] + set load 0 + for {set i 0} {$i < $N} {incr i} { + if {[string index $lane $i] eq "O"} { + incr load [expr {$N - $i}] + } + } + return $load +} + +set map {} +while {[gets $input line] >= 0} { + lappend map $line +} + +set part1 0 +foreach l [transpose $map] { + set r [roll-left $l] + set n [calc-load $r] + puts "$l => $r | $n" + incr part1 $n +} +puts $part1 diff --git a/prelude.tcl b/prelude.tcl index 2650a04..dd5dcf0 100644 --- a/prelude.tcl +++ b/prelude.tcl @@ -32,3 +32,17 @@ proc must_regexp args { error "regexp failed" } } + +# transpose an array of strings +proc transpose strings { + set out {} + set C [slen [lindex $strings 0]] + for {set i 0} {$i < $C} {incr i} { + set column {} + foreach row $strings { + lappend column [string index $row $i] + } + lappend out [join $column ""] + } + return $out +}