Day 3!

This commit is contained in:
Steph 2022-12-01 21:02:00 +01:00
parent 6852dafe59
commit c54bcf38bd
4 changed files with 375 additions and 0 deletions

323
2020/3/input Normal file
View File

@ -0,0 +1,323 @@
.........#..##..#..#........#..
#...#..#..#...##.....##.##.#...
....#..............#....#....#.
#.#..#.....#...#.##..#.#.#.....
........#..#.#..#.......#......
.#........#.#..###.#....#.#.#..
........#........#.......#.....
...##..#.#.#........##.........
#.#.##..###............#...#...
............#....#.......###.##
....##....##..#........#......#
............#.#..........#.....
#.#....#....##...#.....#.....#.
......#.#.#...#.....###....#..#
...........##..#.........#..#.#
..#..#.................#..#..#.
.#....###...#.......#.........#
#.#.#.#...#......#.......#...#.
.......#.#.#...#..............#
...##.......#..##.#.......##...
#.#.##....#..##..##..###...###.
.#......##.##.#....#.##........
..###.............##..##..#....
.....#.#...........#..##..##...
.###.#.#......#.....#........##
...#.......#...##..#..#..#.....
..............#.#..##.##..##..#
#..#.#......#............#.....
........#..#....#..............
...#...#..............#.#####..
...##......#........#.#...#....
..##......#............#..#..#.
....#.........#.#.#.....###.#..
#....#........#........#....#.#
.....#...#..##.....##...#.....#
#...#.#.#...##..##.###.#.#.....
......#.#..........#...#.##....
..............##...#..#.......#
........##.....#.....#.#....#..
..............#..#..#...#.....#
##......##.......##...#.#....#.
.....#.............#.#.........
#.........##..#..#.........##..
..#..#.....#####.........##.#..
.......##.#......#........#....
#.................#.#...#....#.
...#........#.###.##.##.....#..
#.....##..#...##.#.#......#....
.....#..#.#..........##..#.##..
..###.............#..#..#...#..
...###..#...#.....##..........#
#.......#.#...#....#..##..#..#.
.#..#.........#..............#.
..######.....#....##......#....
#..##...#......#..#.#....#.....
.#...................#.#.....#.
..#...#.#..#.#......#..#...#..#
..##..##.#.##.........#.#.#....
...#...#...........#..##.##...#
#...#....#....#....#..#.##..#..
..#.##....#....###..#..........
#.#..##.#.#...##.#..#.##..#.#..
#......##...#.#..........#..#..
#.#...#..#...#.#.#..#........#.
#.#.##.#..#...#..#.#.##........
.....#......#........#..#......
...#....#.#....#...............
....#..###..#....#..#....#....#
.#........###..........##.##.#.
#.#......##....##...##.#......#
#..##.##...#...........##.#.#..
.#.....#.#...#.................
##..........#..#....#.....#...#
....#.#..........##..#.....#.##
#.#..#..#..##..........#.......
..#.#.###......................
......##..##.....#..##.##....#.
...#.......#.##....#......#....
...#...#........#...#.#...#..##
##...#....#.#...#.#.##..##...#.
...#.....#...#...#....###.#..#.
..#.#..#........#......#..##..#
...#......#...#.#.##...##.#.#.#
....#.#....#....#.....#.....##.
.....#.#..##.#....##....##.....
.#...###..#.....#............#.
#..#.#.#..#..#...#....#...#....
#.....#..#...#................#
..........#..#.......#......#.#
...#..#......#...#......#......
.#.#.....#.#.#.#......#..#..#..
.....#.........#.#.#.....##.#..
.....#.#.....#..#..#..#.....###
##....#......##....##.#....#.#.
#####........#..........##.....
.#...##...#...#.......#....#...
#.#.##...##...##..##........#..
#.#..............#.#...#...###.
...#.....##..#.........#....#.#
#.#....#....#..##.#..#...#.....
..#....#.#..#...#...##.....#...
....#...#......................
..#...#.......#..#...##....#...
.#........#...#.....##.##...#..
#......#..............#..#..#..
...........#.#..#.#.#....#....#
.##..##.......#...#..#.....#..#
...#.........#.........###..#..
...#.##....#....#.....#.....#..
.#.#.#.........#.#.#....#....#.
...#..........##..#....#.#.....
...#....##................#....
#....##..#..#........##...#....
#...#...##.#............#....#.
##..#....#...#...............#.
..........#.#...#..##..#.#.....
..##...##..#....#.#......#.....
.......#......#.#.....#.....##.
#...###.....##..##....#.#....#.
.###......#.....#.#............
#.....#.....####.##....#..#....
......###.............#......##
.........##.......##..#..#..#..
.#.......#....#...#...#.#......
#...#..#...#........#...##..#..
.#....#........#.........##..#.
..............##.#...##..#.##.#
.#....#...#....#......#..#.....
#....##.#...#.#.....###..#....#
#.......##.#..###..............
#..#..#..#......#.#..#...#..#.#
.......#.#.#..#..#...#..#......
.#..#......#.....#......##..##.
....#....#.......#.......#.#.##
.......#.#................#...#
#.#.....#.......#.#........#...
.....#....##...#......#.....##.
.#......#.#...#..#....#....#.##
##...#.###.#....#..#....#.#...#
....#.##..##.#.............#...
#..#.............##.......#.#..
##.#..#..#.#...........###...##
.#.#.....#......###........#...
#.#...#.#....##......#.#....#..
#.........#..........#.........
.......#....#...#..#.....#...##
.......................#...#..#
.###...........##...#........##
#.#....######.#........#..##.#.
..#.##.#...#.#.......#.##.##..#
#.............###..#.##.#......
...#..##......#...#..###.....#.
..........#.....#..#...##..#...
..##..........#.#..#.....#...#.
...#.......#.....##.........#..
#..#.#...#..#...###...#...#.#..
#.##....#..#.#.......#..#..#...
..#.##.#......#.#......#....#..
..........#...##.....###.......
...#...##..#......#...##.......
....#........#.#.......#..###..
.....#.#..........##.#..#..#.#.
.............##.....#.#..##....
...#...............##...#......
....#......#..#....#...##..#...
.##.#....#.#.....#.#.........#.
.....#.###....#..###..#.#.....#
.#.........##.........##...#...
..#.....###....##..........#..#
........#..#.#.#..#.......#..##
..#.#..#.#............#.##.#..#
.#....#.....#..#...#.......##..
.#...........#.#..#..###.###...
..#.....#..#........#.#........
.#........##........#..#.##....
......#.....##........##..#....
.#..................##....#.#..
.#..#.#..#.#...#........#......
...#..##.#......#..#..........#
....#.##...#....##.............
#....#.##....##.###..#..#..#...
..........#..#...##.##....#..#.
.###.#.....#...#...#...#.......
............#...............#.#
#....#...#......#....#.#.#.#.##
...#..........#.#.#.....###....
#.#...##...#..#.....###...#....
......#...#..#..#..#.##...##...
...#..#.#....#...#.#.........##
##....#..###.#.##.....##.......
..#.#...#..##.......#.#.......#
##......#...........#......#...
.......#..###....###..##.#...##
.........#.....#..#.......##..#
.......#.##..#....#...#.#...#..
#..#.#..................##.#..#
...#..#..#.....#..#........#...
...#.#..###..#.....##...#....#.
..#..#......#...........#...#..
#...##.##..###.......##........
.#.....#..#....#.....#.##....#.
#..#........#.#....#..#...#.###
..#...#.#.#.....#.....#..#.....
.##.............#.#......##...#
.#....#####............#.....##
#.###.......#.#...##.....#.....
......#.##..#...#..#..##.#..##.
......#.#...##.....#...#....##.
....#............#...#...#....#
.........##.#.#....#....#....##
.#...##.#...#.......#.##....#.#
#....#.#...#.#...#.#.#...#.....
.#.#.........##..#..#..........
.#.........#.#.....#..#.#..###.
....##.#.#..........#..####....
....#..#.#.#...#...#..#....#...
..#.#...#...##.......#.#.#..#..
...##...#......#.....#.#...#..#
......#.###.#.......##...#...#.
.....#.#.#......##..........###
##.#.#.#..#....#...............
.#.#.##.......#....#.#.....#..#
.........#...#.#..#.......#....
....#.####.#......#...#...##...
#..#..#..#..#....#...##.....##.
......####.#..##..#.....##.....
##.#.........#........#..#.#...
.#.#....#....#.......#.#....##.
....#....#.......##..#.....#...
.#......#..#....#.#............
#..#.#.##.....#..#.#.#.#.#.##..
.#.....#.....#...#..#.#...#.#..
.#.#.##............#.#.#.#.#.#.
.##..........#.....#...###.....
#.#...#...#................#.#.
##...#.##.....#.....#.#.##.....
####.....##..........#......#..
#.............#..............#.
.###....#.#...#..#..#..#.......
..#.#.....#...#..#..####.......
...#.#..#........#..##..#..#.##
.#........#..........#.#...##..
.#.......#.#.#..#...#..#.#...##
.#.....##......##..............
......#..#.#.##...##.#.....#...
.........#.#...##.....##....#.#
.....##...#........#..#.#..#.#.
.#.##..#.....##...#...###.#.#..
...##...#...#..#.#..#..........
##..............#...#...#.#..#.
......#..#......#..#.....#...#.
.......#...#..#....#.....#.....
..##.....##..#.#........#......
.###.#...#.....................
..#...#.................#...#..
#..#.##...####.............#...
.##....#..####.......#.........
#..#...###...#...#..#..##......
....#.##.#.#.........#.....#..#
.....#...#.....#.#.#.##.#...##.
.............#........#.....#..
...##.###.#....##.......#..#...
#..#....#....#.#............#..
.........#.##........##.....#..
.........#.#.#..#..#.......#...
.......#.#..#.......#.....#.#..
##.#.....##...##.....#.#.......
.#.#.#......##.##.#.........#..
..#.##..###.....###.........##.
.#......#..#..##...#.#...##.#.#
......#.#............#.....#...
###.#..#..#..#..#.##...#.......
.#.#.##..###....#......##..###.
#...#.#.#..#..#..##.#.##....#..
..#...#...####...#......####.##
..##.#.####........#..#......#.
.#..#.......#...#.#.........#..
........#.#....#..#####..#.....
.#...........#..#..#..#...#....
....#....#...#.................
....##..#....##....#..#....#.##
....#.##.....###...#...##.##...
......##.#..##.#.#.#....#.#.#..
##.#...###....#.#..#.#.###....#
......###..#..#..........##...#
..........#.##...##..#....##.#.
.#...#.#..#.#.#..#.....#.......
.#....#..#.#..#.#...##.#.#.....
.##.....#...#..##.#........#...
....#......#.........#....#..##
.#..#.#.#.#..#..#.#.........#..
.........#.....#...#....#......
#..#..#........#...#.#.........
...#.#.#...##.#.#...#..#......#
#.#.#.#........#...#..#.....#..
.###..#..#..###..#..#..........
.....#......#.#..#...#.......#.
##.##.........#.......##.......
#...##.......#..#.#.......#....
#..#..#.....#...#......#.......
.#..#..#.##....#.#..#...#...#..
.#...#.....#..#.........#..#...
...#.#.#.......#....#..##.....#
.........#..##.#..#..#.#.......
#.##.....##..###..#..#..#.##...
........#......#...##...###..##
.##....##..#..#..###......#....
............##......#...#..##..
...##.......#......#...##.##..#
...#..#..#.#...####.#.......#..
..#.##..#....#......#.#.....#..
..#.##..............#..##.....#
.....##....#......#....#......#
......#..#......#.........#..#.
...#.##.###...###..#.##........
..........####.#.##.....#..#.##
#...##...........#...........##
#.#..#.#....#.#..#....##......#
.......#...#.....#......#.#.##.
....#.##..##..........#..#.....
#.#.#...#......#...#.....#.##.#
........#.......#..##.....##...
.....####.#....#.#.............

16
2020/3/trajectory.fish Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/fish
set lines (cat input)
set pos 0
set trees 0
for val in $lines
set width (string length $val)
set char (string sub -s (math $pos + 1) -l 1 $val)
set pos (math "($pos + 3) % $width")
if test "$char" = "#"
set trees (math $trees + 1)
end
end
echo "total nr of trees is $trees"

36
2020/3/trajectory2.fish Executable file
View File

@ -0,0 +1,36 @@
#!/usr/bin/fish
set lines (cat input)
function traverse
set hv $argv[1]
set vv $argv[2]
set pos 0
set trees 0
set i -1
for val in $lines
set i (math $i + 1)
if test (math $i % $vv) -ne 0
continue
end
set width (string length $val)
set char (string sub -s (math $pos + 1) -l 1 $val)
set pos (math "($pos + $hv) % $width")
if test "$char" = "#"
set trees (math $trees + 1)
end
end
echo $trees
end
set a (traverse 1 1)
set b (traverse 3 1)
set c (traverse 5 1)
set d (traverse 7 1)
set e (traverse 1 2)
echo "Total number of things is ($a * $b * $c * $d * $e) " (math "$a * $b * $c * $d * $e")

Binary file not shown.