-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
393 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "day-03" | ||
version = "0.1.0" | ||
authors = ["Michal Baumgartner <[email protected]>"] | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,323 @@ | ||
.##.............##......#.....# | ||
.#.#................#.......... | ||
...#..#.##..#.#......#.#.#.#..# | ||
..#......#........#..#..#.#.#.. | ||
.......#....#..#..#.......#.... | ||
..#..#..##.#...#........#.###.. | ||
..#...#..#.....#.##....#....... | ||
....#..###.#......#.##..#...##. | ||
..#..........#.##.#...#........ | ||
#...#............##....#..##... | ||
.......##....#.....##..#.#..#.# | ||
..#..#..#...#....#....#....#... | ||
.#...#.##........#####........# | ||
..#..#......#.....##...#....... | ||
....#......##....#.#....#.#..## | ||
#.#.##....##..#.........#.###.. | ||
##..###..#..#.......###.......# | ||
...#.#......#.........#....#... | ||
.....#..........#.....##..#.#.. | ||
....##......#.#..#....#.#...... | ||
..#.....#..##.......##......#.. | ||
.........##.##.#..##........... | ||
....#...#.....#....#.#.###....# | ||
.##.#..#...##..#.......#......# | ||
##..#..#..####..#.#..#...#..... | ||
..###..#..#..#.###..#....#.##.. | ||
......#...###.#.#.....#........ | ||
.....#...#.#...#.......#.....#. | ||
#........#..##...........#..#.. | ||
.#.##.##...#.....#.#....#..#... | ||
..##.##....#.....#....#....##.. | ||
#.........##...##..#.....#..#.. | ||
........#.####....#...##.....#. | ||
.#.#...#..#..#.#......##.....#. | ||
..#..........##..#.#.#....#...# | ||
#.......#...#...#.....#.##.#... | ||
..#.....#..#.....####.#..#.#.## | ||
...#.#..#...#.....#...#.#.#.#.# | ||
.#..##....##.....#..#....###... | ||
....#......##.#.#.....#......#. | ||
..#.#...#......#.....##.......# | ||
..#...###...#..#.#...#..#.....# | ||
#..............#.....#....##..# | ||
.#...#.......#.............#... | ||
..###....#.##........#.#....... | ||
#.##.......#..#............###. | ||
#...#..##.#.#............###### | ||
..##..#....#.#.###...#..##.##.. | ||
.#...#.###.#....#...#....#...#. | ||
#...#.......#...........#...##. | ||
##.#......#####.............#.. | ||
....#..#......##..#..........#. | ||
#.....#.....#.#.......#...#...# | ||
....#...#.#..##........#.#..##. | ||
..##.....##............#.#.###. | ||
#.........#........#..###...... | ||
............#.................. | ||
.#.###...####...#.#..#......#.. | ||
...##.###.#....##.#..####..#.## | ||
..#####.#.##...#.#...##.##....# | ||
........##...#...#....##.....## | ||
#...........###...#.#...##.#... | ||
##......#...#.......###........ | ||
..#..#.##.#..###....#..#.###.#. | ||
...#.#.#...#....#.##..#...#.... | ||
........#.##...##.#.....##...## | ||
.#..........##..#..#..#.#...#.. | ||
#.#...#.##.#....#.##..#........ | ||
.#.#.#....##..##.####.....###.. | ||
..#....##....#..#..#..##....... | ||
..##...#.......#...##.#....#... | ||
...####.#.#...........#.#...#.. | ||
....####.....#.#.....#....##.## | ||
..#.....#.#.............##....# | ||
#.#....#####.##..####.#...#.#.. | ||
#.#....#.##.#.#.##..#.#...#.... | ||
......#.......#.......#.....#.. | ||
..#.....#....###.###..#..#..#.. | ||
#..#....##.###...##.....#...... | ||
..#..#...#..#.##..........#.... | ||
...#.#.#......#....#.##..#..##. | ||
....##.#....#..#...##....###... | ||
##.#.###.....#..#.#.#..#.....## | ||
##..#.#........#...#..#.#...... | ||
....#.#.......##.#...........#. | ||
.......##...#...#...#.....#.... | ||
.....#....#..#..###.#...#...... | ||
............#.#..#......#.#.... | ||
...##..#.##....##..##.#......#. | ||
#.#.#......#.#.....#.#.#..#.#.# | ||
...###..........#..#..#.##..... | ||
......#......#......###..##.... | ||
#...##...#....#....#..#...#.#.. | ||
.......#..#......##.......#.... | ||
...#..#..#.....#.....#......##. | ||
..#....###..........##..#...#.. | ||
..........#..#.#...#......#..#. | ||
#...#....#.##.........#.#.#...# | ||
.#.#.#...#.#...#.#..#..#....#.# | ||
#.##....#..#.........#.##.##..# | ||
..#.#..##.#....#.###.#...#....# | ||
.#.......#...#.#.........#....# | ||
.......#...#..........#.#..#... | ||
...#.....##..#....#...###...#.# | ||
#....##.##..........#.......#.. | ||
.##..##......#...#....#.##....# | ||
....#.....##...##.#..#......... | ||
...#.#..##.#.#..#.......#....#. | ||
.#...#.#.#.#..#..#.##.......#.. | ||
..#..##...#.#..#.......#.#####. | ||
.......#.#...........#....#.#.. | ||
.#.###..........#...#..#...#... | ||
..#.#............##......##.... | ||
...##..#...###...##....#.#.##.. | ||
....#.##...#..#.#.#...........# | ||
....#..#....##.....#.##.#.....# | ||
..##......##.#.........#....#.# | ||
###...#...#..#.#...#........... | ||
.####.....#.....#.#....#..#.... | ||
.#....#..#..#..#...##.....###.# | ||
#....##.#....#.##..#......##..# | ||
.........#..#.#.....#.#....##.# | ||
.....#.#...#....#.#...#....#..# | ||
.#...#.#.....#.#......#.#...... | ||
#....##.......#.............#.. | ||
#..#...#........##..#..#......# | ||
####..##.#..##..#.........####. | ||
.#.##..#.#..#.#.#.##...#..#.#.# | ||
.##.#..#............#......#... | ||
###....#.##....#..#...#........ | ||
.....#..###..........#..#...... | ||
.##..##.....#..##....#...#..... | ||
#...##...........#..#...###..#. | ||
#..##....#...#.##.##....#...... | ||
...#...#..#.#.......##.......## | ||
....#.....#..#...#.........#.#. | ||
.#...##.#......#.#..#..#...##.. | ||
...##...##.##...##...#..#...... | ||
#..##.#..#..#............#...#. | ||
..#.....#.........#........#.#. | ||
#.#...#...#......#.#......#.... | ||
.##.....##.#.#....#.##...##.#.. | ||
.##..##.#.#....#.##............ | ||
.#.##.....##.#...#...###....#.. | ||
.#..............#.#....###.###. | ||
....#..#...#.#.#..........#.#.# | ||
.#.#..#.#.#...###..#...##...... | ||
.#.#.....###......#..........#. | ||
........#.##...............#.#. | ||
...#.#.#......#..#..##........# | ||
..#.##......#.......#..#......# | ||
...#...#...#...#..#..#........# | ||
..#....#.....#....#..##........ | ||
.....#..#...##....#......##.... | ||
...##..##..#..........##....#.# | ||
..#....#..#...#.##..#.....##... | ||
###...#.#....#........#.......# | ||
......#...#..#....###.........# | ||
..###.#...#...#...#.#..###.#... | ||
.##.#.......#.#..#..#......#.#. | ||
...##...........#.#..#.#..#.... | ||
.......#.....####.#.....#...#.# | ||
......##......##.#.#.#...#.#..# | ||
..###.#####..#....#.#...#..##.. | ||
.....#..#......#........#...... | ||
#..##....#.#.##....#....#...... | ||
.#....#.##.####.##..#..#......# | ||
#...##...#.#...##.#.##.##...#.. | ||
........#.#........#.#...#..#.. | ||
.#....###..#......#.##.###..#.. | ||
.#..#..#..#..#...#.#.........## | ||
....#...#..#..............#.... | ||
........#...##.....#.......#... | ||
..#......#.#..#.#..#.#.#...###. | ||
....#...####....###....#......# | ||
#...#.#...................#.##. | ||
..#.#.###...#....##....##...... | ||
#..##..#.........#....#....#### | ||
.#....###...#.#...#......#...#. | ||
......#..#.#..#.##...#.#.#..#.. | ||
.#...#.#.....#..##......#..#... | ||
##.#..##.....##.#.#.......##... | ||
.##.##.##..#...#.#.##.##....... | ||
.#.#......#.....#...#.#..#..... | ||
...#...........#..#.##..##..#.. | ||
.....#...##......#........#.#.. | ||
....#..............##.........# | ||
..####.#....##..##......##.#.#. | ||
.#.#..#...#..........#...###..# | ||
....#.#.##.....###.#..#.##..... | ||
.......##.#.#..#...#...##.#.... | ||
...#.##.....#....#...#...#..... | ||
##.#.##..#..#.#.....#.#..#..... | ||
..#..##........#....###..#..#.. | ||
..#.........##.....#......#...# | ||
...##..........##......#.#.#... | ||
#.....#..#..#......#......#.... | ||
.##...#..##....#.......##..#.#. | ||
.#...##...##......####.##.#.... | ||
.....#.........#.#.####......#. | ||
...#.....#.#.........##..#..... | ||
##.#.###.#..#.#..#............# | ||
...##..#.#....#....#..#........ | ||
..#.###......#...#.#.....#...#. | ||
....##.##..#.....#...#.#.#....# | ||
.......#.#..#...........#.#.... | ||
.#.#..##.#.......#.#..#.....### | ||
...#.#.....#.#..#.##..#...#.#.. | ||
...#......##....#.............. | ||
......#...#.................... | ||
..#........#...##.##.#..#.#.#.. | ||
.#.###.#.##..##..#....##....#.. | ||
.....#..#.#...#.#..#..#.......# | ||
..........#.##.#..##..####..... | ||
............#.#......#......... | ||
.#....#..#......#.....##....... | ||
.....#........#.....##.#..#.#.. | ||
#..#.##...#.#.....#...#.####... | ||
......#...#....#.##..##.#...#.. | ||
.#.#.##......##....#.#....#.##. | ||
#.#.#....#.###....##....##..... | ||
.##..#...#.##......#..#..#...## | ||
...#....###....#...........#.#. | ||
#.#.##.##...##....#....##.#...# | ||
.#.#######.......#......#...... | ||
#......#...#.#.#.###....#.##..# | ||
......##..#..##.........##.#.## | ||
....##...#.#....##.....#.....#. | ||
..#.#........##........#.#..##. | ||
.....#..#.##.....#.....#..#.#.. | ||
.#..............#.......#...... | ||
.............#..#..........#... | ||
.#..#.##....##.#..#...##....... | ||
...........#..#.......#.#....#. | ||
.#..#..........##...#.#.#...#.. | ||
......#....#..###....#......#.. | ||
.#...#...##..#..#..##..#..#.#.. | ||
#.#.........#....#..........##. | ||
...##..#..##...#....##...##.##. | ||
..#....#.####.........#.....##. | ||
.....#.#...#.#...#.##.#...##..# | ||
#...#.....#..#.......#...#..#.. | ||
..#.......#..##.#.....#....#... | ||
.#.....#..##.#.....#...#.#...#. | ||
.....#.##..........##....#...#. | ||
...#....#...#........##...#...# | ||
....##...#....#..........#..... | ||
...#....##..#..####..##.#...#.# | ||
#...###.###..#....##.#......... | ||
.#.......#......#.........#.... | ||
..#..##..#.........##.......... | ||
#......#.#.##...#...#####...... | ||
......#.....####......#....#... | ||
.........#..#..#...#....#.#.... | ||
....#........#...##....#....... | ||
...##.#...#..........#....#.... | ||
........#.......#.##..#..#...#. | ||
....#..##...........#.....#..#. | ||
#....#...............#.#....#.. | ||
.#........#....#.#...#.......#. | ||
#.......##..........#.......#.. | ||
...#....#...##.#..#.......#.... | ||
#..#.##...#.#...#...#...#....#. | ||
###...#...#....#....#....#...#. | ||
##......#.#.......#....#..#.... | ||
......#......#....#.#.#..###..# | ||
.#.#.##.....#..#..........#.... | ||
##...#.#.#..##....#.....#.#.... | ||
#.##...#...#.#...####..#....... | ||
.....##..#.#.#....#..##..#.#... | ||
....###.#.........##.....#..... | ||
......##...........#........#.# | ||
.#.........##.................. | ||
.........##...#.............#.# | ||
......##...#...#.........#..##. | ||
#..#.......#..##.......###..... | ||
....#.#.....#............##.... | ||
.....#..#......#....#.....##... | ||
##......##...................#. | ||
#....#............#.#.###.##... | ||
.#.....#........#.....#...#.... | ||
......##.......######......##.. | ||
.#....##....#..###....#.......# | ||
..............##.#..#.......#.# | ||
.#..#..........#..#.##......... | ||
......##.#..#......#.#....##.#. | ||
#.....#.##...#.....#...#..#...# | ||
.#....#..##.....#.....#.#.#.... | ||
..#......#.##..#.........#.#.#. | ||
.#..##...#...#.....#..#..#.#..# | ||
#.#.##.##.................#.#.# | ||
.#..#.#..##.#.......#.......##. | ||
#...#...#..##...#...##...#...#. | ||
....#......#..#...#.....##..#.. | ||
..............##......#...#.#.. | ||
..##..#.......#..#..###.#.#.... | ||
.#..#..#...#.......#...#...##.# | ||
.#...#.......###..#.##.###..... | ||
##.#...#......#.....#..#....... | ||
##....##............#.....#..#. | ||
.....#...##......##.....#....## | ||
#...##..#....#..##....###.#...# | ||
.....#..#.#.....#.##..##....#.. | ||
.#.....#.#........#...#.#...... | ||
......#....#.#........#.#...... | ||
.##..#...............###...##.# | ||
.......###.#.#......###.....#.. | ||
.......#..##...#....#.##..#.##. | ||
..#.......##.......#.....#....# | ||
.#......#....#..##..#.#.#..##.. | ||
###......#...#..#.............# | ||
.#....#..#.#......##........... | ||
.#....#.##.....#..#.......#..## | ||
....#...#...#..#.....#..##..#.# | ||
#.#.#.......##.#..#.#....#..... | ||
##.#.......#...#...#.#......##. | ||
#....#.#...........#######..... | ||
...#.#.##.#......##..###....... | ||
..#.#....#..#.................# | ||
........#..##..#.....#....#.##. | ||
...#.#..#..#..#..............## | ||
.##.......###.#......#....#..## | ||
..##.##.#......#....#..#...#..# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
..##.........##.........##.........##.........##.........##....... | ||
#...#...#..#...#...#..#...#...#..#...#...#..#...#...#..#...#...#.. | ||
.#....#..#..#....#..#..#....#..#..#....#..#..#....#..#..#....#..#. | ||
..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.# | ||
.#...##..#..#...##..#..#...##..#..#...##..#..#...##..#..#...##..#. | ||
..#.##.......#.##.......#.##.......#.##.......#.##.......#.##..... | ||
.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....# | ||
.#........#.#........#.#........#.#........#.#........#.#........# | ||
#.##...#...#.##...#...#.##...#...#.##...#...#.##...#...#.##...#... | ||
#...##....##...##....##...##....##...##....##...##....##...##....# | ||
.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#![feature(bool_to_option)] | ||
|
||
use std::{error::Error, fs::File, io::BufReader, iter, io::prelude::*}; | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
let file = File::open("input/input1.txt")?; | ||
let reader = BufReader::new(file); | ||
let tree_char = '#'; | ||
|
||
let tree_count = reader.lines().skip(1).enumerate().filter_map(|(idx, line)| { | ||
let row = line.ok()?; | ||
let offset = ((idx+1) * 3) % row.len(); | ||
|
||
(row.chars().nth(offset)? == tree_char).then_some(()) | ||
}).count(); | ||
|
||
println!("Part 1: {}", tree_count); | ||
|
||
let file = File::open("input/input1.txt")?; | ||
let reader = BufReader::new(file); | ||
|
||
let offset_bases: Vec<(usize, usize)> = vec![(1, 1), (1, 3), (1, 5), (1, 7), (2, 1)]; | ||
let mut matches: Vec<usize> = iter::repeat(0).take(offset_bases.len()).collect(); | ||
|
||
for (idx, line) in reader.lines().skip(1).enumerate() { | ||
let row = line?; | ||
let row_len = row.len(); | ||
let current_row = idx + 1; // since we skip the first row | ||
|
||
for (offset_idx, (row_peek, column_peek)) in offset_bases.iter().enumerate() { | ||
if current_row % row_peek != 0 { continue; } | ||
let offset = ((current_row / row_peek) * column_peek) % row_len; | ||
|
||
if row.chars().nth(offset).unwrap() == tree_char { | ||
matches[offset_idx] += 1; | ||
} | ||
} | ||
} | ||
|
||
println!("Part 2: {:#?}", matches); | ||
println!("Part 2: {}", matches.iter().fold(1, |a, b| a * b)); | ||
|
||
Ok(()) | ||
} |