generated from blizzardfinnegan/advent-of-code
Include Day02 instructions, and start day03
This commit is contained in:
parent
5877f43639
commit
bbd96a8435
6 changed files with 503 additions and 0 deletions
28
day02/part2Instructions.txt
Normal file
28
day02/part2Instructions.txt
Normal file
|
@ -0,0 +1,28 @@
|
|||
--- Part Two ---
|
||||
|
||||
While it appears you validated the passwords correctly, they don't seem
|
||||
to be what the Official Toboggan Corporate Authentication System is
|
||||
expecting.
|
||||
|
||||
The shopkeeper suddenly realizes that he just accidentally explained
|
||||
the password policy rules from his old job at the sled rental place
|
||||
down the street! The Official Toboggan Corporate Policy actually works
|
||||
a little differently.
|
||||
|
||||
Each policy actually describes two positions in the password, where 1
|
||||
means the first character, 2 means the second character, and so on. (Be
|
||||
careful; Toboggan Corporate Policies have no concept of "index zero"!)
|
||||
Exactly one of these positions must contain the given letter. Other
|
||||
occurrences of the letter are irrelevant for the purposes of policy
|
||||
enforcement.
|
||||
|
||||
Given the same example list from above:
|
||||
* 1-3 a: abcde is valid: position 1 contains a and position 3 does
|
||||
not.
|
||||
* 1-3 b: cdefg is invalid: neither position 1 nor position 3 contains
|
||||
b.
|
||||
* 2-9 c: ccccccccc is invalid: both position 2 and position 9 contain
|
||||
c.
|
||||
|
||||
How many passwords are valid according to the new interpretation of the
|
||||
policies?
|
14
day03/CMakeLists.txt
Normal file
14
day03/CMakeLists.txt
Normal file
|
@ -0,0 +1,14 @@
|
|||
#Minimum CMake version
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
|
||||
#Export compile commands for ccls Language Server
|
||||
SET(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
#Specify C standard as ANSI
|
||||
SET(C_STANDARD 90)
|
||||
|
||||
#Specify project name, and that C is language
|
||||
PROJECT(day03 C)
|
||||
|
||||
#Part 1 Executable
|
||||
ADD_EXECUTABLE(Part1 src/part1.c)
|
||||
#Part 2 Executable
|
||||
#ADD_EXECUTABLE(Part2 src/part2.c)
|
324
day03/data/input.txt
Normal file
324
day03/data/input.txt
Normal file
|
@ -0,0 +1,324 @@
|
|||
.#..........#......#..#.....#..
|
||||
....#.............#.#....#..#..
|
||||
.....##...###....#..#.......#..
|
||||
.#....#..#......#........#.....
|
||||
.#.........###.#..........##...
|
||||
...............##........#.....
|
||||
#..#..........#..##..#....#.#..
|
||||
....#.##....#..#...#.#....#....
|
||||
...###...#............#.#......
|
||||
#.........#..#...............#.
|
||||
#.#...........#...............#
|
||||
..#.#......#..###.#...#..##....
|
||||
.....#..#..#..#............#...
|
||||
......#.......#.....#....##....
|
||||
#......#...#.......#.#.#.......
|
||||
...........##.#.............#..
|
||||
.#.........#..#.####...........
|
||||
..#...........#....##..........
|
||||
#...........#.......#..#.#.....
|
||||
.....##...#.....#..##..#..#....
|
||||
#.#..........................#.
|
||||
##.....#..........#.......##..#
|
||||
....#..#............#.#.#......
|
||||
.......#.......#..#............
|
||||
...#.#..........#..#.....#.....
|
||||
.....#...##..##.....##........#
|
||||
.#.....#........##............#
|
||||
..#....#.#...#.....#.##........
|
||||
........##.....#......##...##..
|
||||
......#..................#.....
|
||||
..##......##.....##...##.......
|
||||
......#..#...##......##........
|
||||
.#..#..#.#.....................
|
||||
.#....#.#...#....#.......##...#
|
||||
.####.#..##...#.#.#....#...#...
|
||||
.#....#.....#...#..#.........##
|
||||
...........#.#####.#.#..##..#..
|
||||
.#......##...#..###.#.#....#...
|
||||
...#.....#........#..###...#...
|
||||
.......#................##.#...
|
||||
.##...#.#..................#...
|
||||
..#........#....#..........#..#
|
||||
..#.........#..................
|
||||
...#.#..........#.#..##........
|
||||
...#.##..........##...........#
|
||||
...........#..#........#.......
|
||||
.#....#.#...........#....#.##..
|
||||
.#...#..#............#....#.#..
|
||||
...#..#...#.........####.#.#...
|
||||
..#...#...........###..#...##.#
|
||||
......##...#.#.#....##....#....
|
||||
#..#.#.....##....#.......#...#.
|
||||
.#.....#.....#..#..##..........
|
||||
................#.#.#...##.....
|
||||
.#.....#............#......#...
|
||||
...#...#..#.#....######.....#..
|
||||
..#..........##......##.....#..
|
||||
......#..#.##...#.#............
|
||||
....#.......#..#...#..#.#......
|
||||
#......##.#..#........#.....#..
|
||||
..#.........#..#.........#.....
|
||||
..#.........##.......#.#.#..##.
|
||||
...#....##.................#.#.
|
||||
...#........##.#.......#.##..##
|
||||
....#.#...#...#....#...........
|
||||
.........#....##........#......
|
||||
...#........#..#.......#...#...
|
||||
#.......#....#...#...........#.
|
||||
.......#......#...##...........
|
||||
.#.#......##.#.......#..#...#..
|
||||
.#.....##.#...#......#..#......
|
||||
........#.............#.#..#..#
|
||||
#...........#....#.....#.##.#.#
|
||||
................#...#........##
|
||||
#..#.##..#.....#...##.#........
|
||||
#.....#.#..##......#.#..#..###.
|
||||
....#...#.....#................
|
||||
......#...#..##...........#....
|
||||
......#.........##.#...#......#
|
||||
#...#.#.....#..#.#..#..#......#
|
||||
...#.#..#..#.#........###.#....
|
||||
..#...#.......#.#.......#......
|
||||
...#....#.....#.......#......#.
|
||||
#...........#....#..#..#.......
|
||||
..........##......##.........##
|
||||
##............#..#.#...#..#.#..
|
||||
..#.##....##...##..#...#.......
|
||||
............##.##..###..#..#...
|
||||
......#....##...##.........#...
|
||||
......#..#.#......####..#......
|
||||
..............#....#..#..##....
|
||||
...#.#..#...##.#.......#.#.....
|
||||
...#.#....#.......#..#..#..##..
|
||||
..........#.........#..........
|
||||
...#.....#............#.....##.
|
||||
....#.#......................#.
|
||||
.........#...#.#...#...........
|
||||
...#........#..##.....#...#.#..
|
||||
......##.....#.#..#...###.#...#
|
||||
#....#..#.#.....#...#..........
|
||||
.#.##.###.........#..##.#....#.
|
||||
#.........#....#........#...#..
|
||||
...........#...............#..#
|
||||
###....................#....#..
|
||||
.................#....#.....#..
|
||||
..........#.........#.......#..
|
||||
........#..#....#.....##.......
|
||||
#...##.#...#.#.#............#..
|
||||
....#.........##.#.#..#...###..
|
||||
.##..............#...#.....##.#
|
||||
###...#..................#...#.
|
||||
.....#..#...#..#...#...........
|
||||
.#.................#...#..#..#.
|
||||
.#.........###...#.##......###.
|
||||
.####............#......#..#...
|
||||
....#........#..#.#....#..##..#
|
||||
..#....#.#...#.#.....##....#...
|
||||
..###..#..#....##....#..#..#...
|
||||
...#.#.....#.#....#.....#......
|
||||
.....#..........#.#............
|
||||
.......#...........#.#..#..#...
|
||||
......##........#.....#.......#
|
||||
..#.#.....##............#..##..
|
||||
....#.#........#...........##..
|
||||
#......#..##........#.....#....
|
||||
#...#...###..............##....
|
||||
#..#........#........#.....##.#
|
||||
......##.####........#..#....#.
|
||||
...##..#.##.....#...#...#..#...
|
||||
#..............###.##..##......
|
||||
......................#.....#..
|
||||
.........#.#.......#...##.#....
|
||||
....#......#..........###..#...
|
||||
#...####.#.................#..#
|
||||
##.#....#....#.....##..#....#.#
|
||||
..#.....#..##.........#.#..#.#.
|
||||
.....#.....#...................
|
||||
#....##.#.........###....#.....
|
||||
#........#.#.......#.#.........
|
||||
.##.#...#.....#...#.......##.##
|
||||
#..#.............#.............
|
||||
..........#.........####.......
|
||||
..##..............#..#.#.......
|
||||
..#.#.....#........#......##...
|
||||
#.#.......#.#................#.
|
||||
.#...#........#....##....#.##..
|
||||
.#..#...#...#......#.#.........
|
||||
......##............#.........#
|
||||
.#....#.#.#.........#..#..##...
|
||||
#....#......#.......###........
|
||||
.......#........##..#...#..###.
|
||||
#.##..........#..###..#..#.#...
|
||||
.#..#....#..........#.#.##.....
|
||||
#..#...#.#...#..#..#.#...#.....
|
||||
.........#...#.#............#..
|
||||
#..#.............#......##.##..
|
||||
...##.......#..................
|
||||
....#......#...#.....#......#..
|
||||
.....##..#......#....#....#....
|
||||
....#...#...#...#.....#........
|
||||
.#....#........##....#..#.#...#
|
||||
#.......#..#......#......#...#.
|
||||
..............#......#......#..
|
||||
#......#..##...#........#....#.
|
||||
#..#..#..#.....#..#........#...
|
||||
#...#.....#...#..........#...##
|
||||
........#.......#...#.....#.#..
|
||||
...................##.......#..
|
||||
.#......#........#.##..#....#..
|
||||
.....#.....#...#..#..#......#..
|
||||
........##.#..##.........#....#
|
||||
.........#.......#.............
|
||||
............#.###.###..#.#.....
|
||||
.............#....#...........#
|
||||
..#.....#.#..##.##........#....
|
||||
...#....#....#.........#.....#.
|
||||
.#............#......#.........
|
||||
..#.#..........##.##......#.#..
|
||||
....#.........................#
|
||||
..........##...................
|
||||
#.......#.#..............#...#.
|
||||
...##..#..##...##.#..#.#.#.....
|
||||
...########.#..##....#.........
|
||||
##.#........##.....#........#..
|
||||
#.#.....#........#..#....#...#.
|
||||
..#............#.......###.##.#
|
||||
#.#............................
|
||||
...#.#.#....#..........#..#....
|
||||
..###.#.....#.#..#.............
|
||||
#........#..........#.#..#.....
|
||||
...........#..#....#.........#.
|
||||
..#............#.....#.#.......
|
||||
#.#............#..#.....#.#.#..
|
||||
...#...#.......................
|
||||
.#.#.#...##.............#..#..#
|
||||
..#.........#..#.....##....##..
|
||||
.#...#............#.......#..##
|
||||
....#..#.#.#...####............
|
||||
#.......#....#..##....##....#..
|
||||
.....##.#....#.#..#.......#....
|
||||
...........#.......#....##.#.##
|
||||
..........#...#....##...#.#....
|
||||
..#.............#.............#
|
||||
....#..#.....#....#.#..###.#...
|
||||
.......#.##.#......#...##...#.#
|
||||
.#..#.#..#.#.......#....###.#..
|
||||
#..........##...##.........##..
|
||||
##..#......##.#.####.#.....#...
|
||||
....#.#...#........#..##..#.#..
|
||||
.#.............................
|
||||
.##..#.#...##.....#....#.....#.
|
||||
..##.........#......#.........#
|
||||
.#.#........#...#.#.#....##....
|
||||
.#.................##.........#
|
||||
...#...............#....#......
|
||||
..#...#..#..........###..#...##
|
||||
..........#..#..........##..#..
|
||||
...#.............#.##.#...#....
|
||||
...#...........#...............
|
||||
......#.........##.#...#...#...
|
||||
...#.#........#..#.....#..#...#
|
||||
#.#...#....##...#.....#....#...
|
||||
#.#.#..#.....#.........#.......
|
||||
##...........#..####...........
|
||||
#..........#........###...#..#.
|
||||
#..#.......#....#......###.....
|
||||
..#.....#......#.###......##...
|
||||
...#.##..#............#...#....
|
||||
.##........#.....#.............
|
||||
#....#.##..#...........##.#.#..
|
||||
..#.....#.#....#.......#......#
|
||||
#..#.......#............#......
|
||||
#.......##....#...#..#.........
|
||||
.................#..##.........
|
||||
..............#..#..#.##.......
|
||||
#.#.......................#..#.
|
||||
..#..##...........#....#..#..#.
|
||||
...#....#.......#.......#....#.
|
||||
.....#.#..#.#.....#.........#.#
|
||||
..#.#.........#.....#..........
|
||||
...#.#.#.......#.#.......#.#..#
|
||||
...##...#.#.#.....#.....##....#
|
||||
##.......#.#.#.#.......#...##..
|
||||
....#.#...........#......#.....
|
||||
.#.....#........####...........
|
||||
#......#........#.....#..#..#..
|
||||
..#..#......#...##.......#....#
|
||||
#........#..........#.....#.#..
|
||||
.#...........#.....#.....#.....
|
||||
..........#..#...#....#....##..
|
||||
.....#.#..........#.....##..#..
|
||||
......#.........##.............
|
||||
..#..#.....##......##........#.
|
||||
.#.#.#.#..#.#..#.......#.......
|
||||
#.#...####.#.#....#.#........#.
|
||||
....#...#.....#......#..##.....
|
||||
##.........#.........#..#.#..#.
|
||||
..#.#........#.#........#.##...
|
||||
#....#......#...#....#.........
|
||||
.##.............###....###.#...
|
||||
..##.#.......#...#..#......#...
|
||||
.....#.##..................#...
|
||||
.....#.#...#..#................
|
||||
........#..#..#...........#.#.#
|
||||
....#.###.....#..#.#.....##..##
|
||||
....##.#.........#..##.........
|
||||
.##........#......#..###..#.##.
|
||||
.........##...............#.##.
|
||||
..#...............#.#...#..#.#.
|
||||
....#....##.....#...#..#.....#.
|
||||
#...#.....................#....
|
||||
.....#.#............#...##.#.#.
|
||||
...#......#.......#........##.#
|
||||
.#.#..#.#....#.##.......##....#
|
||||
.........#...#..##.........#...
|
||||
.#...#..#....................#.
|
||||
.......#...#........#.#..#.#.##
|
||||
.#.............#......#..#.#...
|
||||
............##.........#....#.#
|
||||
#.........##..##...............
|
||||
.#.#....#.#..#..........##.....
|
||||
..###...#..#.#.......#..#...##.
|
||||
.....#....#.#............##.#..
|
||||
##.....#.#..#..#...............
|
||||
...##...#......#....#..#..#....
|
||||
.............#....#..#..##...##
|
||||
#.......#............#....##..#
|
||||
..#.##.....#.......#....#....#.
|
||||
..........#...#.............###
|
||||
..#....#.#..................#..
|
||||
#.#...#..#...........#.........
|
||||
....##..#..##..#..........#....
|
||||
#...#...#.#....#.##...#.......#
|
||||
#......##.#...##..#.....#......
|
||||
....#.......#.#............#...
|
||||
#....#...........###...........
|
||||
#..#...#...#......#.#..#.......
|
||||
...............................
|
||||
#........##.............#.#....
|
||||
.............#........#....#.##
|
||||
........##.####.....##..#......
|
||||
#.#.#.#.......##....##.....#...
|
||||
.......#..##..#...#............
|
||||
..........#...#....#..#.#.#.##.
|
||||
...#........##....#...#........
|
||||
#..#.##....#....#........#.....
|
||||
.##...#.....##...#.............
|
||||
.#...#..#.#.....#.##.....#.....
|
||||
...........#.............#...#.
|
||||
.#..#................#...#..#..
|
||||
#..........#......##..##....#..
|
||||
####..#...........#.#....#.....
|
||||
..#.#.##..#...##........#....##
|
||||
.#.......##........#.....#.....
|
||||
............#................#.
|
||||
.#...#...#.....#.#....#.##..#..
|
||||
..#.............#.#....#.#.....
|
||||
..............#...........#....
|
||||
..............#........#....#..
|
||||
..........##........#..#...#...
|
||||
...#.#....#.#....#..#.....#...#
|
||||
..#......#...........#..#..#.#.
|
||||
.....##.....#.####....#........
|
||||
|
11
day03/data/testInput.txt
Normal file
11
day03/data/testInput.txt
Normal file
|
@ -0,0 +1,11 @@
|
|||
..##.......
|
||||
#...#...#..
|
||||
.#....#..#.
|
||||
..#.#...#.#
|
||||
.#...##..#.
|
||||
..#.##.....
|
||||
.#.#.#....#
|
||||
.#........#
|
||||
#.##...#...
|
||||
#...##....#
|
||||
.#..#...#.#
|
67
day03/part1Instructions.txt
Normal file
67
day03/part1Instructions.txt
Normal file
|
@ -0,0 +1,67 @@
|
|||
--- 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?
|
59
day03/src/part1.c
Normal file
59
day03/src/part1.c
Normal file
|
@ -0,0 +1,59 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/* Convert file into C structs for easier parsing */
|
||||
void file_import(char * filename){
|
||||
/* pointer to file */
|
||||
FILE * file_pointer;
|
||||
char intermediate_string[40];
|
||||
char second_string[40];
|
||||
char * line_get = second_string;
|
||||
|
||||
/* Open file based on filename variable */
|
||||
file_pointer = fopen(filename, "r");
|
||||
|
||||
/* Fail safely if invalid file name */
|
||||
if (file_pointer == NULL) {
|
||||
printf("no such file.");
|
||||
exit(2);
|
||||
} else {
|
||||
printf("File successfully loaded.\n");
|
||||
}
|
||||
|
||||
line_get = fgets(intermediate_string, sizeof(intermediate_string), file_pointer);
|
||||
/* Read until the end of the file */
|
||||
while( !(feof(file_pointer)) ){
|
||||
|
||||
/* Loop back */
|
||||
line_get = fgets(intermediate_string, sizeof(intermediate_string), file_pointer);
|
||||
}
|
||||
|
||||
/* Close file when complete */
|
||||
fclose(file_pointer);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
/* Final return value */
|
||||
int final_value = 0;
|
||||
/* Array index value */
|
||||
int array_index = 0;
|
||||
/* File name importing data from */
|
||||
char * filename;
|
||||
|
||||
|
||||
/* Check argument values, look for filename as first argument
|
||||
* Fallback to test input if argument not provided */
|
||||
if(argc >= 2){
|
||||
filename = argv[1];
|
||||
} else {
|
||||
filename = "../data/testInput.txt";
|
||||
}
|
||||
|
||||
/* Generate expandable array */
|
||||
|
||||
|
||||
/* Print final calculation */
|
||||
printf("Final value: %d\n",final_value);
|
||||
return(0);
|
||||
}
|
Loading…
Add table
Reference in a new issue