aboutsummaryrefslogtreecommitdiff
path: root/2020
diff options
context:
space:
mode:
Diffstat (limited to '2020')
-rw-r--r--2020/.gitignore1
-rw-r--r--2020/day03/Cargo.lock7
-rw-r--r--2020/day03/Cargo.toml8
-rw-r--r--2020/day03/input0.txt323
-rw-r--r--2020/day03/src/main.rs74
-rw-r--r--2020/day03/test0.txt11
6 files changed, 424 insertions, 0 deletions
diff --git a/2020/.gitignore b/2020/.gitignore
new file mode 100644
index 0000000..2f7896d
--- /dev/null
+++ b/2020/.gitignore
@@ -0,0 +1 @@
+target/
diff --git a/2020/day03/Cargo.lock b/2020/day03/Cargo.lock
new file mode 100644
index 0000000..21c74cb
--- /dev/null
+++ b/2020/day03/Cargo.lock
@@ -0,0 +1,7 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "day03"
+version = "0.1.0"
diff --git a/2020/day03/Cargo.toml b/2020/day03/Cargo.toml
new file mode 100644
index 0000000..2804bab
--- /dev/null
+++ b/2020/day03/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+name = "day03"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
diff --git a/2020/day03/input0.txt b/2020/day03/input0.txt
new file mode 100644
index 0000000..077fb5f
--- /dev/null
+++ b/2020/day03/input0.txt
@@ -0,0 +1,323 @@
+...#.....#.......##......#.....
+...#..................#........
+....##....#.......#............
+.........#.......#.......#.....
+..#..............#.........#..#
+.....#.........#....#....#....#
+....##..........#.#.##.........
+...#....##...#...#...#.#..#....
+...#.......###..........#......
+.........#.....#....#...#.#....
+.#...###..#..##..#.........###.
+#.#...#..........###...#....#..
+#....#.#..#..........#.......#.
+.#..#........##.#..............
+............#..#.#............#
+.............#..........#......
+...#.......#...............#...
+.#...#..#..#............#..#...
+....##.##..................#.##
+#......#...#..##....#.....#...#
+#..#..........##....#...###....
+##......#.##.#......#..#......#
+....#...#.......##.##...#.#..#.
+##.#...#....#...#...#........#.
+........#..#.....#....#.......#
+.#......#......#..............#
+.#.....#..#..#..#..#..#....#..#
+.......#.....#.................
+.#......#...#..#..#...#...#....
+.........#..#..#.........#.....
+.....#.........#.#..........#..
+#......#....#....##....#.#.#...
+................##.#...........
+.....##.....#............#.#...
+...........#...#.#..##...#.....
+.......#....##.......#..#....#.
+.##......##....#....####.##..#.
+.....#.##.....#...#....##......
+.............#....#......#....#
+#.#.#.###........#.#....#.#....
+.##...........#................
+#..#..#...##..##.##...#..#.#...
+..#......##..#.#......#..#.#.#.
+.....#..............#......#...
+#.#..##.##...#............##...
+.#......#.............#........
+........##....#......#..#......
+##.........##....#..........#..
+..#..#....#.........##....#..#.
+........#..#..#........#...#...
+#.........#......##.#...#.##...
+.##.............#..###....#.##.
+.##.#....#.......#.............
+#..##.#.........#..##.#......##
+....#..#.......................
+.#.#.........#...............#.
+....#......#.#..##..#...#.#..#.
+#....##...##..#.......##.....##
+....##...##...#....#.....#..#..
+.#......#.#.#.#......##..#..#..
+.....##..#..#.....#.....#...##.
+....###................#..#.#..
+.....#..#..#.#..........#..#...
+...#.....#............#........
+#.............#...#..#.....#..#
+#........#.....#.#..#......#...
+...#.##.....#.#..#.........#..#
+.......##...#..#.#....##.......
+..................#..##..#.#.#.
+..#......#..#..#.....#...#.#...
+.#.......#.....#.#....#.#......
+##..#.#....#.###..#...#.......#
+.......................#.......
+..###..........#..##.##.#...##.
+.....#...#....###.........#..#.
+..#.....#....###...............
+....#.......#........#....#..#.
+......#................#.#...##
+#.....#.......#..#..........##.
+#.#....##.........#.....#.#....
+#.#.#...#............####.##..#
+.....#....####........#...#..#.
+....##........#.#..............
+.#......#..#..##......#....#.##
+..#....#.#........#..#....#....
+.#...#.##...#.#.....#.....#...#
+..........#................###.
+.....#..........##..#..........
+.....#..................#...#..
+#......##....#.#...#..#.......#
+..#......##....#......#.#...#..
+###.#..###.#.#..#...#....#.....
+#.....#.#...#.##...#........#..
+#..........................#...
+.#.#.....#.#.#.......##.#.#....
+.#....#..##......#....#........
+.#.......#.##......#.#..#......
+............#.....#....##.##...
+....##........##......#........
+....#......##....##.....#......
+..#.#.....#......#...#.#.......
+.###.........#...#........#....
+......#.#...##.....##..##..#...
+...#...#.#......#..##..#.......
+.##....#.#........#.#..........
+#....#.#......#......#.#.#.....
+#.....#.....#................##
+...........#....#...#...#......
+..........##..##..#...##.......
+.##......#.......#..#.#..##....
+..........##....#....#..#.#....
+...............#......#.....##.
+.#...#....................#..#.
+.............###...............
+.####..............#...#.......
+....#...#.#...#...#....#.......
+.......#.#.....................
+...............................
+#..#.........##.......#.#.#....
+....##...#...........#......#..
+........##...#......#..........
+....#.#.....#..#......#........
+#..#................#..#.##....
+.#........#.......#.........##.
+#...........#...#...#......#.#.
+..#.#.#..........##.##...#...#.
+..#...#.##...#.#...........#...
+##...........##...##...##......
+....#....##...#......#..#.....#
+#..#.#.#..#...#...#....#.......
+............#.....#....#....#.#
+....##.....#.........#......#..
+.....##.......#...#...#.###....
+...##......##..###.#.#....#....
+#.#.#.#..#.#.........#...#...##
+..#..........#.................
+....##....#....................
+###.#...............##...##.#..
+....#.......##.#..#.#..........
+............##..#.......##.....
+#...#.........#..#..#..#...#...
+..#......##..#.#...##.#.......#
+......#................#...#...
+......#..###............#.#....
+..#.#...###...#..#...#......##.
+...#.##...##............#......
+#...##........#.#..#.......#...
+#..#.....#..#.##...............
+..#.....#.#....#.........#.....
+.............#....#..#...#.##..
+..#.#.....................##.#.
+........#.......#..#.#.........
+##..............#.....#.......#
+.#.##...###....#.....#..##.#...
+#..#...#..#......#..........###
+#...........#..#...#....#....#.
+....#..#.......##......#......#
+#...#.#...............##...#...
+...##.#..##.......##..#........
+...........##..........#.......
+..#....#..##...#......#.#......
+.#.#....#.#.#...#.#............
+.#.#..#...##.......#.#.........
+...#...#.............#.######..
+##.#........###.......#....#.#.
+.#....#.....#.#........#......#
+..#.#.........#..........##.#..
+.#....#.#..............#......#
+.....#..##.........#..##..#....
+........#..#....#.......#.....#
+#.#.......#.....#.##.#...#....#
+...#...##...#....#.....#....#.#
+#..##....#..........#..#.......
+.......#.#.....#...#.#.#.....##
+#...#...#..#......##.#..#......
+...#.......#....#...........#.#
+##.......#####.#.........#..#..
+....#.#...................##...
+......#..##............#.......
+#.........#....#####.#.#..#.#..
+..#......#.#.##............#...
+..#...#.....#.#....#......#....
+.#...#....#....#.#.#......#.#..
+..#.##.....#..........#...#.#..
+.......#...#.............#...#.
+.#.........#.....#.#........##.
+#....#..#..........##.......##.
+...#....#.#.........#.......###
+......#....#.#......#.......#..
+.....#...#...#.#...##..#.#.....
+#.........##..#...##..#.#....#.
+...#......#.#......##.....#....
+.#####.....#.#.#.#...###.##....
+..#................#.#...#.#...
+#.......##...#.........##..#...
+..#.....#....##............#...
+#............##...............#
+..#..#.................#.......
+...............#..#.......##...
+..##..#....#...##..........#..#
+#...###....##.#.......#.....#..
+..........#.........#..#......#
+##....#.....#...##.......#.....
+..#..#.......#.................
+..#..##......#.........#......#
+...........##.#..#......#.#..#.
+..#...##...##......#...#...#.#.
+.#..#.....#.........#..........
+#..##...#............#..#.#....
+..#...#...##.#........#....#.#.
+......##..###.#....#........#..
+.....#..#....##...##..........#
+................#.#.#.....#..#.
+#.##...#......#.#..#.......###.
+.......#.#..#..#......#..##..#.
+.##...#...#....#....#.......#..
+......#..#....#.#.###.....#.#.#
+#....#.#...#......#.#.....#..#.
+.......#.#...#.#.#............#
+#.....#..#...#.................
+.....#..........#..#.#..#.#....
+.........#......#.#.........###
+..#.###........#....##.#.......
+.#.......#.#......#........#..#
+............#........#.....#...
+......#......#....#.#....#.....
+.#.......#.....#.##.#..#...#..#
+##.....#...#..........##..#...#
+.#........#....#...#....##.#...
+...#.#.......#.#....#.#...#...#
+........#.#.....#.##...#.#.#...
+...........#....#..#.........#.
+......#.#..#..##...#.......#...
+...#....#..#..#.##...........##
+.#..#.#.#......#....##...#.....
+......#..#........#...##.......
+.............#...##.#.....#...#
+....#...............##......#.#
+.#...........#.........###.##.#
+....##........##...#.##.....#..
+#......##........#...........#.
+###.#.................#.....#..
+.....##..#.........#......##.#.
+#.#.......##.#..#...#...#......
+...#.#..##.....#....##.....#.#.
+...##..#...#........#.#..#..#..
+...........#....#...#...##.....
+##.......#...#.#.##...##..#.#..
+#....#.#..##...................
+.#...................#.#..#....
+#.....#..........#..#...#...#..
+...#..#............#.#.........
+............#..##.....##......#
+#....#.........#.#..#..........
+...#.#................#....#.#.
+..#..#...#...#.#.#...#.#.#.....
+..#.......#.............##..#.#
+#........#.#.###.#...#..#.###..
+.......#......#..#.....####...#
+..##....#..#...................
+....##.#....#......#.#..#..#..#
+#...........##...#.#.##..###...
+##.##......#...........#....#..
+.#....#....#..#..#...##...#....
+...##.#.#......#...............
+.....##.##...#...........#.....
+....#...#.#.........##.#....#.#
+#..#...........#......#........
+..#..#.....#....#.##.......#..#
+..#.......##.....##.......#...#
+.#.##.#..#...............#....#
+.........#...........#.........
+..........##......#.#..........
+..#........###....#..#...#...#.
+....#.#...#.....#..#....#......
+..##...##...#..#..##......##..#
+..#..#......#....#....#...#..##
+...#...............#..#........
+....##..#...#......#........#..
+###.....##.......#.............
+.#.#.##........##..#...#.......
+.....###............#..#..#....
+.#....##.#...####........#.....
+............#.#.....##....#.#..
+....#..........#...#...........
+........#.#...#..##...........#
+#.......#..#.......###...#....#
+#....#..#......#.....#...##.#..
+..#.............#.#.###...##..#
+.#.#....#...#.....#...#.......#
+.##.#..#.........#..#......#...
+#....#...#......#.....#.....#..
+...........#....#.......##...#.
+#.#..##....#....#.#.......#.#..
+..............#.#..##.##.......
+....#........#......#....#.#...
+......#.....................#..
+#..##...##.....#.........#.....
+#.....#.....#....#...#.....#...
+........###...........#...#....
+............#.....#...##....#..
+.......#.......#...#.#...##....
+..#.#..#....#...#...#....#.....
+..........#.#....#....###....#.
+.##...#......###..#............
+...#...#........#....#....##...
+##.....#.##...#.#...........#.#
+..........#.#....#...##.#...#..
+..#....#.#...#...#....#.###....
+......#.##..#..#.........#.###.
+#.#.#.....#.....##.......#.....
+...#..#..#....#.#....#....#....
+##..#.#................#......#
+.....#...#..#......#..####.....
+.....##.....#....####......#...
+..........##..###.#....#.....##
+###...#.......#......##...#....
+.......##...#...#..#.##.#....##
+.....##.....##...##.....#..#..#
+......#.#.....#...#....#...#...
+..##........#...#..............
+..#........#.##.........#...#..
+#....#....#................#...
diff --git a/2020/day03/src/main.rs b/2020/day03/src/main.rs
new file mode 100644
index 0000000..6e74f74
--- /dev/null
+++ b/2020/day03/src/main.rs
@@ -0,0 +1,74 @@
+fn slide(lines: Vec<Vec<char>>, vx: i32, vy: i32) -> i32 {
+ let mut x: i32 = 0;
+ let mut y: i32 = 0;
+ let mut hits: i32 = 0;
+ loop {
+ if lines[y as usize][x as usize] == '#' {
+ hits += 1;
+ }
+ x += vx;
+ y += vy;
+ if y as usize >= lines.len() {
+ break;
+ }
+ if x as usize >= lines[y as usize].len() {
+ x -= lines[y as usize].len() as i32;
+ }
+ }
+ hits
+}
+
+fn slide_everywhere(lines: Vec<Vec<char>>) -> i32 {
+ let mut hits: i32 = 1;
+ for (vx, vy) in vec![(1, 1), (3, 1), (5, 1), (7, 1), (1, 2)] {
+ hits *= slide(lines.clone(), vx, vy);
+ }
+ hits
+}
+
+fn main() {
+ let lines: Vec<Vec<char>> = include_str!("../input0.txt")
+ .trim()
+ .split("\n")
+ .map(|s| s.chars().collect())
+ .collect();
+ let hits = slide(lines.clone(), 3, 1);
+ println!("hits: {}", hits);
+ let hits_everything = slide_everywhere(lines.clone());
+ println!("hits on the five paths: {}", hits_everything);
+}
+
+#[cfg(test)]
+mod tests {
+ use crate::*;
+
+ #[test]
+ fn small_input() {
+ let lines: Vec<Vec<char>> = include_str!("../test0.txt")
+ .trim()
+ .split("\n")
+ .map(|s| s.chars().collect())
+ .collect();
+ assert_eq!(slide(lines, 3, 1), 7);
+ }
+
+ #[test]
+ fn big_input() {
+ let lines: Vec<Vec<char>> = include_str!("../input0.txt")
+ .trim()
+ .split("\n")
+ .map(|s| s.chars().collect())
+ .collect();
+ assert_eq!(slide(lines, 3, 1), 220);
+ }
+
+ #[test]
+ fn small_input_all_slopes() {
+ let lines: Vec<Vec<char>> = include_str!("../test0.txt")
+ .trim()
+ .split("\n")
+ .map(|s| s.chars().collect())
+ .collect();
+ assert_eq!(slide_everywhere(lines), 336);
+ }
+}
diff --git a/2020/day03/test0.txt b/2020/day03/test0.txt
new file mode 100644
index 0000000..7e88cdc
--- /dev/null
+++ b/2020/day03/test0.txt
@@ -0,0 +1,11 @@
+..##.......
+#...#...#..
+.#....#..#.
+..#.#...#.#
+.#...##..#.
+..#.##.....
+.#.#.#....#
+.#........#
+#.##...#...
+#...##....#
+.#..#...#.#