rename repo, subdir for yearly challenges
This commit is contained in:
323
2020/day03/INPUT.txt
Normal file
323
2020/day03/INPUT.txt
Normal file
@@ -0,0 +1,323 @@
|
||||
....#............#.###...#.#.#.
|
||||
.#.#....##.........#.....##.#..
|
||||
.#..#.#...####.##..#......#..##
|
||||
......#...#...#.......#........
|
||||
........#...###..#.#....#....#.
|
||||
..##.....#.....#.#.........#.#.
|
||||
.##.......#.#.#...#..#...##...#
|
||||
...##.....#....##....#...###.#.
|
||||
..#...#......##.#.##.....#.#..#
|
||||
.#....#.###.........#..........
|
||||
.#.#..##.....###.....###....#.#
|
||||
....###....#......#...#......##
|
||||
......##...#.##.........#.#..#.
|
||||
##.#....##...#..##....#.#..#.##
|
||||
.#...#..#.....#.#.......#...#..
|
||||
..........#..###.###......##..#
|
||||
..#.##.#..#......#.......###.#.
|
||||
...#...#.#.#..#...#.#..........
|
||||
#........#..#..#.#....#.##..###
|
||||
#...#.....#..####.........####.
|
||||
.....###..........#.#...##...#.
|
||||
.....#...#..#.......#....##.#..
|
||||
...........#..##.....#...#..#..
|
||||
......##..#........#...........
|
||||
#.#..#.#.#..#.....#....#.....#.
|
||||
..#....##....##...#.....#......
|
||||
.#.#....#..#.#......#..###...#.
|
||||
.......#...#.#....##..#..#..#..
|
||||
.#.#.#.......#....#.#.#.......#
|
||||
.#..........#.##.#...#..#.#.##.
|
||||
..#.#..........#.#....##.#.##..
|
||||
###..#..#.#...##.#.#..#........
|
||||
##....#...#....#....#...#.#....
|
||||
#...#.#....#.##..##...#.#......
|
||||
......#...#.###......##....#...
|
||||
.................#.###......#..
|
||||
##..#....#....##...###.#.#..###
|
||||
..#..........#..####..##..#...#
|
||||
.#......#..#.#...........##.#..
|
||||
.#..#......#...#.#.#..#.#.#.#.#
|
||||
.#......###.....#.#.#......##..
|
||||
#..........#.##...#...........#
|
||||
..#....#.##....#.........#.....
|
||||
.#..##....#...##.........#..#..
|
||||
....##..#.###..#.#...#..###..#.
|
||||
..#......#........#...#.#......
|
||||
........#..#..#..#...#.##......
|
||||
.##.#.#......#...#.........#...
|
||||
#..###.#...#....###.##..###....
|
||||
........##.............#....#..
|
||||
...#...............#....#.#....
|
||||
#..........#..#..#.#.....#...#.
|
||||
.#.............#...#.......#..#
|
||||
.#..#..#...#........##.........
|
||||
.....#.#..#.#..#..##.........#.
|
||||
..#..##...#....#.#...#.###..#..
|
||||
#...........##.....#...#.##....
|
||||
#.#.#.#........##......#...#.#.
|
||||
......#..#.###.#...#.##.##....#
|
||||
.#....#...#....#........#....#.
|
||||
..#.#..........#..##.......#..#
|
||||
.....#...##..#................#
|
||||
.#...............##...#.##...##
|
||||
#.####....##.....#.......#.##..
|
||||
......#.##.#...##..###..#.#....
|
||||
.#.##.#...##..#.......#.#..#...
|
||||
#...#.##..........##..........#
|
||||
#.###...#...#..#.....#.#.##..##
|
||||
.##.....#....#...##.....##.....
|
||||
...#........#..###.###...#.....
|
||||
##..#....#.....#...#.#....#.#..
|
||||
#....#....#.#..........#...#..#
|
||||
...##..#......#..#..#..#..#....
|
||||
.....##...#..####..##.........#
|
||||
.....#..#.#...#..#....##..##...
|
||||
..#.......##.#..#.##...#.#....#
|
||||
.#..#.#...##..##....#..#......#
|
||||
..##.##..##...###..#....#...#..
|
||||
........##.......##...##.....##
|
||||
.#....###...#..#..#..#.......#.
|
||||
#.###............#....##.....#.
|
||||
..........#...#...##..#...#....
|
||||
..#......#.##.......#....##..##
|
||||
..#..###.....#...#.......#.....
|
||||
#.#...##.....#...#....#.......#
|
||||
....##.##.#....#.....#.#....#..
|
||||
...#....#.###............#..###
|
||||
#..##..#.........##.....#.#...#
|
||||
....#.......##......#....#...#.
|
||||
....#..##.#..........#.........
|
||||
....#...#.###.......#...#.#....
|
||||
#..#..#...#.......##...#..#.##.
|
||||
#.......#...##.##......#.......
|
||||
##..##...##...#......#...#...##
|
||||
..#...#.#.####.#...##.....##...
|
||||
#...#..#..#...##......#.#..#..#
|
||||
..##..##.#.#..#...####.....###.
|
||||
.#........#..##.###...#.##.#...
|
||||
........#..#...##......#.#....#
|
||||
..#...###.......##..##..#....#.
|
||||
.##...#.#..#.##.......##.###...
|
||||
#....#.#.#........#....#..#.##.
|
||||
....#.##.#.##..#.#####.....###.
|
||||
#.#..#..#...#.#..#.......#.#...
|
||||
....#...#....###...............
|
||||
.###.#.....#.#.......###......#
|
||||
##...#.#.###....##..#...##.....
|
||||
...#.#..#.###.#.......#...#.#..
|
||||
.#...#....#...#..####....###...
|
||||
..#....##.....##.#.#.##....#...
|
||||
#....#..##.......#...##.##....#
|
||||
.##..#.......#..#....###.......
|
||||
#.##.....##.#.........#......##
|
||||
.####.#...#.....#..#...#.##..#.
|
||||
....#...........#.....#........
|
||||
.#............##...#.......#.#.
|
||||
#....#.##........#....#.#..#..#
|
||||
#....#.##....#...##...#..#..#..
|
||||
...#..#.####.#....#............
|
||||
....#......#.........#.........
|
||||
#....##....###.....#......#.#..
|
||||
...#..#....#........###..#...#.
|
||||
..#.#........#.#.#.###..#.#.#..
|
||||
.....###.....##.#....###.#.....
|
||||
##.#....#....##...##.###.#.##..
|
||||
.###.#..#.......##...#...##....
|
||||
.#...###........#.......##.##..
|
||||
#......####...#...##.#.######..
|
||||
....##.............#..##.##...#
|
||||
...........#..##.#...#.#.#...#.
|
||||
###.......#.##..#....#...#....#
|
||||
.........#.....#.#.#..##.#.....
|
||||
#...##..#....#..#.............#
|
||||
...#.......#.##.............#.#
|
||||
.....#..#...##......####..#....
|
||||
.#.#.#.....#...####..#...##...#
|
||||
#...#.#..#..#.#..#.##..........
|
||||
.....#.##..#.#.##..#.#.#....#.#
|
||||
...##..#...#...#..#....#.......
|
||||
........#.#..#...#...#.#...#...
|
||||
##..#........#..#.....#......##
|
||||
.........#..#...#......#......#
|
||||
..#.#.#........##...#.##.....##
|
||||
.###....##....#...#....#..#....
|
||||
.#.............###...#..##..###
|
||||
.##.##.##.......###.........#.#
|
||||
..#..###...#...#....#..#.#..#.#
|
||||
......#..#.#..#.....#.#........
|
||||
......#...####...#.#.....#.....
|
||||
.#...##.......#..#......#...#..
|
||||
#..#...#.......###..#..#.#.#.#.
|
||||
.....#.....###.##....#.#.##.#.#
|
||||
#........#....##...#..#.##..#..
|
||||
...#.#........##....#.#..###.#.
|
||||
#...#...##.........#........###
|
||||
##...#.##..##...#.....#.###.#..
|
||||
#.###.#.#..#...........##..#...
|
||||
........#.......#..#..#.###....
|
||||
#........#....#......###.......
|
||||
..#.###.######...#.###..#......
|
||||
...#...######..#.....#....#.#..
|
||||
..#.......#..#..#.........#...#
|
||||
.#...#..##.##.........##.......
|
||||
.........#.#.##.#..#....#.#...#
|
||||
#.......#....#......#.....###.#
|
||||
##..............#.###........#.
|
||||
..#.##..#.##.....#...#.#.#..###
|
||||
..#.#......#..#..##.#........#.
|
||||
..#.....#...#.#...#...###..#.#.
|
||||
.......#...........#..#..#.#.##
|
||||
.......#...##..#.###...........
|
||||
.#........#.###.#..#..#..#..#..
|
||||
##.#.##....#..###..#.##.##...#.
|
||||
.....#....##.#........#.#.#....
|
||||
....##....#..#..#....##....#.#.
|
||||
#.....##....#.....#.###.#....#.
|
||||
.#.##.##..#..#...#...........##
|
||||
...#..###..#.....##....#.......
|
||||
...#..##..###.#..#..#.#........
|
||||
......##..#.......#..##.....###
|
||||
.#...##.#.#.#......#...#.#.#.##
|
||||
....#.#....#...#........#...#..
|
||||
....#.#......#.#.###.#.#.##.#..
|
||||
#..#........###..#..#..#.....#.
|
||||
...#....#...##...#........##.##
|
||||
.....#..#..#.....#....#.#...#..
|
||||
..#.###....#.#..##......#.##.#.
|
||||
..####......#..#.#.#..#.#####..
|
||||
.......##..#..###.#............
|
||||
..###.#........#..........##.##
|
||||
#.#.........#.##.#......#..#...
|
||||
...#.....#.....##..#..##.##..#.
|
||||
#.#.##....#.......###....##....
|
||||
...##.#..#...##.#..#......#..#.
|
||||
..##.........#.##.#####...#.#..
|
||||
.#....#...#....#.#.....##...###
|
||||
##.....#..####............###.#
|
||||
......#...........#....#.......
|
||||
.#......#.....##...........###.
|
||||
#......##.......#.#.#..##.....#
|
||||
...###.#.....##.#...#.#....#.#.
|
||||
...###.......#...#.............
|
||||
..#..#.#....#.#.###.#.#.##..##.
|
||||
..##...#..#.#..##.#.##....##...
|
||||
..#...........#..#....#....#...
|
||||
#.##...........#..#.#..##.#.#..
|
||||
...##...##................#..#.
|
||||
.#...#.##......#.#......#.####.
|
||||
#.##....#....#.........#....###
|
||||
.....###........#.#.#.##...#.##
|
||||
.....#....#.#....#.........#..#
|
||||
..#...#.#.#.#...#...#...##.#..#
|
||||
###.......#.....#.............#
|
||||
#.####.#.......#.#.#.#..#.#....
|
||||
#..#..#####......#....#..##....
|
||||
...............#.....#.#....###
|
||||
.###.....#...#.##..#.#..#.#####
|
||||
#.##.....#......##.......##....
|
||||
..........###.......#...#.#....
|
||||
..#.#..#...##.....#........#.#.
|
||||
........##.##....#####.#.#..##.
|
||||
..##.#.#...#####..........#.#.#
|
||||
#.........#......##...#.....#..
|
||||
.##.#........#...#..##...#...#.
|
||||
.......##..#...#.....#.##......
|
||||
....#.#...##..##..#....##......
|
||||
#........#..........##..####.#.
|
||||
...###...#.#.###.#...#....#.#.#
|
||||
.....##.#.....#........#.#....#
|
||||
#.......#....#...##..#......#..
|
||||
...#..........#.#.#...#.#.###.#
|
||||
....##.....#.##..#.#.#.........
|
||||
#.##..##..#....#.........#...#.
|
||||
.###..........#...##.#..#......
|
||||
.....####.............##...###.
|
||||
.#..#....#..#...#..#...........
|
||||
#..#..##..#...#.##..#.###.#...#
|
||||
......#.#..###...#..#.....#..#.
|
||||
##.##......#...#.#...#.........
|
||||
....##.#.......#.#..##....#.#.#
|
||||
#..##..#...###.#....##.........
|
||||
.............#.#....#...##..#..
|
||||
..#....#...#.....#.##.#..##..##
|
||||
##.#..##.#..##.#.#.##.#...#.#..
|
||||
.##.#..#.#........##.#...##....
|
||||
#.........##....##..#......#...
|
||||
.#.#.......##...#..#......###.#
|
||||
........#.#.#.#......#....#..#.
|
||||
...##..#...#...#.##..#....#.#..
|
||||
...#.#.#.#.......#.......###..#
|
||||
...#..##..#####.#.....##.#..#..
|
||||
.......#.#.....#.....#...#...##
|
||||
#...#...#......##.#....##......
|
||||
#.....#.#.#.....#....#......#..
|
||||
..#..#.##.#......##..#.#..#..##
|
||||
####...#.....#....#.#..........
|
||||
....#.....###...#...##......#..
|
||||
.....#....#...#............#...
|
||||
...#...#..##.........#...#...##
|
||||
#.#..#.#...##.#.......#..#.#...
|
||||
.#.....#...##.............#...#
|
||||
.....#..##..#....#......#.##..#
|
||||
....#...###.................#..
|
||||
...###...#....#...#...#........
|
||||
....#.##.#.......#..#..........
|
||||
...#..#......#.#...###...#.#...
|
||||
..#.#..#...#.......#.......#.#.
|
||||
.#.#...#.#.##........#.........
|
||||
...#..#...#....#.#.#.#.#..###..
|
||||
.#..##......#.#.##..#.##....#..
|
||||
#....#.......##.....#.#........
|
||||
..###..#.#.#.......##....#.....
|
||||
........#.#.#....##...##..#....
|
||||
#....##.#....#...##..##...#....
|
||||
...#..##.#.....#...#.....##....
|
||||
.#.#..#..#...#....#..##.#....#.
|
||||
##.#.##....#.....#....#....#.#.
|
||||
.##......#............##...#...
|
||||
#..##.#.####.#.#....#..#..#.#.#
|
||||
#...##...#......##....###.....#
|
||||
..#.##.....#....#....#......#..
|
||||
.##.#...#.....#.#.#.#........##
|
||||
.#..#....#.#...........#...#...
|
||||
#.....#..#.....#.#.##.#.....#..
|
||||
....#.....#..#.#....###........
|
||||
.....###...........#.#..##.#.#.
|
||||
....###....#.......###..#...#.#
|
||||
.###.....#...##.#...##........#
|
||||
..#..#.#..#...#.#...#.#..#...#.
|
||||
#.####.......#....##.#..#.#..#.
|
||||
....#.#.##.#..###.........##.#.
|
||||
..#..#.#....#....#.##..........
|
||||
..##.###..#.#..#.#......#....#.
|
||||
.#..#.....##...#.#......##.#..#
|
||||
#.#....#..#.#.#........#.###...
|
||||
...#....##....##..###.###.#.#..
|
||||
..#....#.....#....##.#.........
|
||||
#.......#....#.........##..#...
|
||||
.#..#...#.#..#.#....#.#........
|
||||
...#..###...#.....#......##....
|
||||
..#...........#.....#..........
|
||||
....###.#...#......#...#..#....
|
||||
.....#.##..#..#....#.......#..#
|
||||
....##..#.#.#..............#.#.
|
||||
.#.#..#..#.#......#...#.#......
|
||||
....#.......#.##....##.#.#.#..#
|
||||
............#.#.#.....##.......
|
||||
........#...##.#..#......#...##
|
||||
.........#...#...#....#...#.##.
|
||||
..#.....#......#......#.....#..
|
||||
#....#...##..#.#....#.#...#.###
|
||||
.......#..#..#..#.#...#.....#.#
|
||||
...#.#...#......##.....#..#....
|
||||
...#.#.####..##.#..#...........
|
||||
..##..##....#.....####...#....#
|
||||
###.......#...##.#...#...#...#.
|
||||
.##..#.....#..####......#....#.
|
||||
#.....#..#..##..##...#..#..#...
|
||||
.#....#.....#...####..####.....
|
||||
..#....#...#......#........#.#.
|
||||
##.#.......#..#.....#..##..##..
|
||||
.#..#..#.#.#...#....##...#.##.#
|
||||
##...#..#....#.........##......
|
26
2020/day03/Makefile
Normal file
26
2020/day03/Makefile
Normal file
@@ -0,0 +1,26 @@
|
||||
INPUT := INPUT.txt
|
||||
SHELL := /bin/bash
|
||||
CFLAGS := -w
|
||||
TIME := \time -f "\ttime: %E real, %U user, %S sys\n\tcontext-switch:\t%c+%w, page-faults: %F+%R\n"
|
||||
export PATH := .:$(PATH)
|
||||
|
||||
.PHONY: clean all compile deploy ex1 ex2
|
||||
|
||||
all: ex1 ex2
|
||||
|
||||
compile: ex1-c ex2-c
|
||||
|
||||
ex1: ex1-c
|
||||
@$(TIME) ex1.bash < $(INPUT)
|
||||
@$(TIME) ex1-c < $(INPUT)
|
||||
|
||||
ex2: ex2-c
|
||||
@$(TIME) ex2.bash < $(INPUT)
|
||||
@#$(TIME) ex2-sort.bash < $(INPUT)
|
||||
@$(TIME) ex2-c < $(INPUT)
|
||||
|
||||
clean:
|
||||
@rm -f ex1-c ex2-c core
|
||||
|
||||
deploy:
|
||||
@$(MAKE) -C .. deploy
|
12
2020/day03/OUTPUT
Normal file
12
2020/day03/OUTPUT
Normal file
@@ -0,0 +1,12 @@
|
||||
ex1.bash : lines:322 pos=966 found:169
|
||||
time: 0:00.01 real, 0.01 user, 0.00 sys
|
||||
|
||||
ex1-c : lines:322 pos:966 found:169
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
|
||||
ex2.bash : lines=323 res=6847128288
|
||||
time: 0:00.04 real, 0.03 user, 0.00 sys
|
||||
|
||||
ex2-c : lines=323 res=6847128288
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
|
82
2020/day03/README
Normal file
82
2020/day03/README
Normal file
@@ -0,0 +1,82 @@
|
||||
--- Day 3: Toboggan Trajectory ---
|
||||
|
||||
With the toboggan login problems resolved, you set off toward the airport. While travel by toboggan might be easy, it's certainly not safe: there's very minimal steering and the area is covered in trees. You'll need to see which angles will take you near the fewest trees.
|
||||
|
||||
Due to the local geology, trees in this area only grow on exact integer coordinates in a grid. You make a map (your puzzle input) of the open squares (.) and trees (#) you can see. For example:
|
||||
|
||||
..##.......
|
||||
#...#...#..
|
||||
.#....#..#.
|
||||
..#.#...#.#
|
||||
.#...##..#.
|
||||
..#.##.....
|
||||
.#.#.#....#
|
||||
.#........#
|
||||
#.##...#...
|
||||
#...##....#
|
||||
.#..#...#.#
|
||||
|
||||
These aren't the only trees, though; due to something you read about once involving arboreal genetics and biome stability, the same pattern repeats to the right many times:
|
||||
|
||||
..##.........##.........##.........##.........##.........##....... --->
|
||||
#...#...#..#...#...#..#...#...#..#...#...#..#...#...#..#...#...#..
|
||||
.#....#..#..#....#..#..#....#..#..#....#..#..#....#..#..#....#..#.
|
||||
..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#
|
||||
.#...##..#..#...##..#..#...##..#..#...##..#..#...##..#..#...##..#.
|
||||
..#.##.......#.##.......#.##.......#.##.......#.##.......#.##..... --->
|
||||
.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#
|
||||
.#........#.#........#.#........#.#........#.#........#.#........#
|
||||
#.##...#...#.##...#...#.##...#...#.##...#...#.##...#...#.##...#...
|
||||
#...##....##...##....##...##....##...##....##...##....##...##....#
|
||||
.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.# --->
|
||||
|
||||
You start on the open square (.) in the top-left corner and need to reach the bottom (below the bottom-most row on your map).
|
||||
|
||||
The toboggan can only follow a few specific slopes (you opted for a cheaper model that prefers rational numbers); start by counting all the trees you would encounter for the slope right 3, down 1:
|
||||
|
||||
From your starting position at the top-left, check the position that is right 3 and down 1. Then, check the position that is right 3 and down 1 from there, and so on until you go past the bottom of the map.
|
||||
|
||||
The locations you'd check in the above example are marked here with O where there was an open square and X where there was a tree:
|
||||
|
||||
..##.........##.........##.........##.........##.........##....... --->
|
||||
#..O#...#..#...#...#..#...#...#..#...#...#..#...#...#..#...#...#..
|
||||
.#....X..#..#....#..#..#....#..#..#....#..#..#....#..#..#....#..#.
|
||||
..#.#...#O#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#
|
||||
.#...##..#..X...##..#..#...##..#..#...##..#..#...##..#..#...##..#.
|
||||
..#.##.......#.X#.......#.##.......#.##.......#.##.......#.##..... --->
|
||||
.#.#.#....#.#.#.#.O..#.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#
|
||||
.#........#.#........X.#........#.#........#.#........#.#........#
|
||||
#.##...#...#.##...#...#.X#...#...#.##...#...#.##...#...#.##...#...
|
||||
#...##....##...##....##...#X....##...##....##...##....##...##....#
|
||||
.#..#...#.#.#..#...#.#.#..#...X.#.#..#...#.#.#..#...#.#.#..#...#.# --->
|
||||
|
||||
In this example, traversing the map using this slope would cause you to encounter 7 trees.
|
||||
|
||||
Starting at the top-left corner of your map and following a slope of right 3 and down 1, how many trees would you encounter?
|
||||
|
||||
Your puzzle answer was 169.
|
||||
--- Part Two ---
|
||||
|
||||
Time to check the rest of the slopes - you need to minimize the probability of a sudden arboreal stop, after all.
|
||||
|
||||
Determine the number of trees you would encounter if, for each of the following slopes, you start at the top-left corner and traverse the map all the way to the bottom:
|
||||
|
||||
Right 1, down 1.
|
||||
Right 3, down 1. (This is the slope you already checked.)
|
||||
Right 5, down 1.
|
||||
Right 7, down 1.
|
||||
Right 1, down 2.
|
||||
|
||||
In the above example, these slopes would find 2, 7, 3, 4, and 2 tree(s) respectively; multiplied together, these produce the answer 336.
|
||||
|
||||
What do you get if you multiply together the number of trees encountered on each of the listed slopes?
|
||||
|
||||
Your puzzle answer was 7560370818.
|
||||
|
||||
Both parts of this puzzle are complete! They provide two gold stars: **
|
||||
|
||||
At this point, you should return to your Advent calendar and try another puzzle.
|
||||
|
||||
If you still want to see it, you can get your puzzle input.
|
||||
|
||||
You can also [Share] this puzzle.
|
11
2020/day03/TEST.txt
Normal file
11
2020/day03/TEST.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
..##.........##.........##.........##.........##.........##.......
|
||||
#...#...#..#...#...#..#...#...#..#...#...#..#...#...#..#...#...#..
|
||||
.#....#..#..#....#..#..#....#..#..#....#..#..#....#..#..#....#..#.
|
||||
..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#
|
||||
.#...##..#..#...##..#..#...##..#..#...##..#..#...##..#..#...##..#.
|
||||
..#.##.......#.##.......#.##.......#.##.......#.##.......#.##.....
|
||||
.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#
|
||||
.#........#.#........#.#........#.#........#.#........#.#........#
|
||||
#.##...#...#.##...#...#.##...#...#.##...#...#.##...#...#.##...#...
|
||||
#...##....##...##....##...##....##...##....##...##....##...##....#
|
||||
.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#
|
38
2020/day03/ex1-c.c
Normal file
38
2020/day03/ex1-c.c
Normal file
@@ -0,0 +1,38 @@
|
||||
/* ex1-c: Advent2020 game, day 3/game 1
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define XMOVE 3
|
||||
|
||||
int my_strlen(str)
|
||||
char *str;
|
||||
{
|
||||
int i;
|
||||
for (i=0; *str; ++i, ++str)
|
||||
;
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
int main(ac, av)
|
||||
char **av;
|
||||
{
|
||||
|
||||
int col=0, line=0, linelen=0, mod=0, count=0;
|
||||
char str[80];
|
||||
|
||||
scanf("%s", str); /* ignore 1st line */
|
||||
|
||||
while (scanf("%s", str) != EOF) {
|
||||
line++;
|
||||
col+=XMOVE;
|
||||
linelen=my_strlen(str);
|
||||
mod=col%linelen;
|
||||
if (*(str+mod) == '#')
|
||||
count++;
|
||||
}
|
||||
printf ("%s : lines:%d pos:%d found:%d\n", *av, line, col, count);
|
||||
exit (0);
|
||||
}
|
21
2020/day03/ex1.bash
Executable file
21
2020/day03/ex1.bash
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ex1.bash: Advent2020 game, day 3/game 1.
|
||||
|
||||
CMD=${0##*/}
|
||||
|
||||
XMOVE=3 # 3 right
|
||||
|
||||
declare -i xpos=0 ypos=0 count=0 linelen=0 modpos=0
|
||||
|
||||
read -r line # ignore 1st line
|
||||
|
||||
while read -r line; do
|
||||
(( ypos++ ))
|
||||
(( xpos += XMOVE )) # move right
|
||||
(( linelen = ${#line} ))
|
||||
(( modpos = (xpos % linelen) ))
|
||||
[[ ${line:modpos:1} = \# ]] && ((count++))
|
||||
done
|
||||
printf "%s : lines:%d pos=%d found:%d\n" "$CMD" $ypos $xpos $count
|
||||
exit 0
|
56
2020/day03/ex2-c.c
Normal file
56
2020/day03/ex2-c.c
Normal file
@@ -0,0 +1,56 @@
|
||||
/* ex1-c: Advent2020 game, day 3/game 2
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct {
|
||||
int dx;
|
||||
int dy;
|
||||
int pos;
|
||||
int count;
|
||||
} set[] = {
|
||||
{ 1, 1, 0, 0},
|
||||
{ 3, 1, 0, 0},
|
||||
{ 5, 1, 0, 0},
|
||||
{ 7, 1, 0, 0},
|
||||
{ 1, 2, 0, 0},
|
||||
{-1, -1, 0, 0} /* end marker - not necessary */
|
||||
};
|
||||
|
||||
int my_strlen(str)
|
||||
char *str;
|
||||
{
|
||||
int i;
|
||||
for (i=0; *str; ++i, ++str)
|
||||
;
|
||||
return i;
|
||||
}
|
||||
|
||||
int main(ac, av)
|
||||
int ac;
|
||||
char **av;
|
||||
{
|
||||
int line=1, linelen=0, mod=0, i;
|
||||
unsigned long res=1;
|
||||
char str[80];
|
||||
|
||||
scanf("%s", str); /* ignore 1st line */
|
||||
|
||||
while (scanf("%s", str) != EOF) {
|
||||
line++;
|
||||
linelen=my_strlen(str);
|
||||
for (i=0; set[i].dx >= 0; ++i) {
|
||||
if (! (line % set[i].dy )) { /* line ok for this set */
|
||||
set[i].pos += set[i].dx; /* increment set column */
|
||||
mod = set[i].pos % linelen;
|
||||
if ( str[mod] == '#')
|
||||
set[i].count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i=0; set[i].dx != -1; ++i)
|
||||
res*=set[i].count;
|
||||
printf ("%s : lines=%d res=%lu\n", *av, line, res);
|
||||
exit (0);
|
||||
}
|
31
2020/day03/ex2.bash
Executable file
31
2020/day03/ex2.bash
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ex1.bash: Advent2020 game, day 3/game 2.
|
||||
|
||||
CMD=${0##*/}
|
||||
|
||||
XMOVES=(1 3 5 7 1) # moves right
|
||||
YMOVES=(1 1 1 1 2) # moves down
|
||||
declare -i linelen=0 modpos=0 res=1 ypos=1
|
||||
declare -a xpos xcount
|
||||
|
||||
read -r line # ignore 1st line
|
||||
|
||||
while read -r line; do
|
||||
(( ypos++ ))
|
||||
(( linelen = ${#line} ))
|
||||
|
||||
for ((i=0; i<${#XMOVES[@]}; ++i)); do
|
||||
if ((ypos % YMOVES[i] == 0)); then
|
||||
(( xpos[i] += XMOVES[i] )) # move right
|
||||
(( modpos = (xpos[i] % linelen) ))
|
||||
[[ ${line:modpos:1} = \# ]] && ((xcount[i]++))
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
for ((i=0; i<${#XMOVES[@]}; ++i)); do
|
||||
(( res *= xcount[i] ))
|
||||
done
|
||||
printf "%s : lines=%d res=%d\n " "$CMD" $ypos $res
|
||||
exit 0
|
Reference in New Issue
Block a user