diff --git a/Cargo.lock b/Cargo.lock index cb365ca..9739af8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,6 +30,14 @@ version = "0.1.0" name = "day_10-2" version = "0.1.0" +[[package]] +name = "day_11-1" +version = "0.1.0" + +[[package]] +name = "day_11-2" +version = "0.1.0" + [[package]] name = "day_2-1" version = "0.1.0" diff --git a/day_11/input.txt b/day_11/input.txt new file mode 100644 index 0000000..c8ea1d6 --- /dev/null +++ b/day_11/input.txt @@ -0,0 +1,140 @@ +........................#...............................................#................................#................................#. +....#..............#......................#............#....................................................................#............... +................................#.............................................................#............................................. +.........#.....................................#...................#........................................................................ +....................................................#.......................#..............................#................................ +..#................................................................................................#................#......................# +.........................................................#.........................#.....#.................................................. +..................................#.............................#...............................................#.............#............. +.......#.....#...........................#..............................................................#.............................#..... +......................#...............................#................................................................#.................... +............................#.................#........................#.....................................#.............................. +....#.................................#...............................................#..................................................... +...............#...........................................................#............................................................#... +..................................#...........................................................#...................#...........#............. +....................................................................................................................................#....... +................................................................#................#..........................#............................... +...#..............#........#.........#.............#........................................................................................ +.........................................................#.............#.............#..............#...................#................... +........#................................................................................................................................... +..............................................................................................#.................................#........#.. +....................#.......................................#.....................................................#......................... +#..............................#.......#......#...................................#......#.................................................. +...........#.......................................#......................................................................#................. +.......................................................................................................................................#.... +............................................................................................................................................ +.........................#...................................#...............................#.............................................. +..................................#.......................................................................#.............#................... +.........................................#...........................#...............................#.........#..........................#. +............#......#............................................#...............................#...................................#....... +.............................#.....................................................#........................................................ +....#........................................#...............................#.................................................#............ +......................#............................#.....#.........#........................................................................ +.........................................................................................................#.................................. +.......#........................#................................................#.......................................................... +...............................................#..........................#................#..........................................#..... +.#................#.............................................................................................#......#.................... +..............................................................................................................................#............. +..........................#........................#.............................................#.......................................... +.............#..........................#............................................#..............................#....................... +........#..............................................#.....................#..........................#..................#................ +............................................................#.....#..................................................................#...... +....................#.........................#..........................#..................#...................#........................... +..............................#...................................................#................#........................................ +.........................................#..............................................#..................................................# +.#........#.........................................#.....................................................#.....................#........... +.........................................................#.........................................................#........................ +......#...........................#......................................................................................................... +................................................#........................................................................................#.. +...................................................................#...............#........................................................ +.....................#................................#..............................................................................#...... +...........#................................................................................#.....#......................................... +....#........................#............................................#..............................................#.................. +................#.......#........................................................#........................................................#. +#...................................................................................................................#....................... +....................#...................#..............#.................................#...................#.............................. +.............#....................#.................................................#..................#...................#................ +.................................................................................................................#.....................#.... +................................................................................#........................................................... +.......................#.............#....................#................................................................................. +.......#.............................................................................................#..............#....................... +...................#.....................................................................................................................#.. +......................................................#..................#.......................................................#.......... +..........................#..................................................................#.............................................. +............#.................................#.........................................#...................#............#.................. +.....................#......................................#......................................................#..........#............. +.#.........................................................................#......#...................#..................................... +............................................................................................................................................ +................................#...........................................................#............................................... +........................................#..........................#..................................................#.................#... +....#........................................#.....................................................#.............................#.......... +..........................................................#................................................................................. +...............#............................................................................................................................ +..........#............#............................#.............................#...........................................#......#...... +....................................#........................................................#...............#.............................. +...........................................#..............................#...............................................................#. +.#...........................#.......................................................................#...................................... +.........................................................#...........#....................................#................................. +......#.......#...................#...........................#.......................#.........#..................#........................ +............................................................................#.........................................................#..... +.....................#.........................................................................................#........#................... +..........................#.............................................#................#........................................#......... +............................................................................................................................................ +....#.....#.....#..................................#.........#.....................#....................#................................... +........................................#.....................................................................................#............. +...............................................................................................#............................................ +.......#........................#...........................................#............................................................#.. +....................#......#....................#........................................................................................... +.........................................................#...........#..........#.............................#...........#................. +......................................................................................#..................................................... +....................................................................................................#................#..........#.....#..... +............#.........#.....................#...............#..............................................#................................ +.......#............................#....................................................................................................... +.......................................................................#......................#................#...................#........ +............................................................................................................................................ +........................................................................................................................#................... +..........#..........#.......................#.........................................................................................#.... +...................................................................#.................#...........#.......................................... +........................................#................#.................................................................................. +................#....................................................................................................#...................... +............................................................................................................................................ +.......#....................#.................................................................#...............#.........................#... +.................................#...........#.....#...........................................................................#............ +...........#.......................................................#....................#................................................... +........................................#...............................................................................#................... +............................................................................................................................................ +.....................................................................................................#...................................... +................#.........................................#..................#................................................#.......#..... +....#................................#.............#...................................#.....................#.......#...................... +.........................#......................................#........................................................................... +...........................................................................................#.......#........................................ +..........#.....................#..............#........................#................................................................... +..#......................................................................................................................................... +....................#.....................................#.......................#......................................................... +..........................#.............#...............................................................................#.........#......... +......................................................................................#..................................................... +.....................................................................#..........................#........................................... +.......#.........#...........................................................#.......................#........#............#............#... +........................#....................................#.............................................................................. +.......................................#............................................#....................#.........................#........ +..............................................#....................................................................#........................ +..............#..................#.....................................#..........................#......................................... +..........................................#..........#..........................#........................................................... +.....#......................................................................................#................#.............................. +.....................#................................................................#.......................................#............. +.....................................................................#...................................................................... +...........#.....#............................#.....................................................................................#....... +................................#.....#..........................#........#..........................................#....................#. +...........................#.................................................................#........#.......#............................. +#........................................................................................................................................... +........#........................................#...................................#...................................................... +.............................................................................................................................#.............. +.................................#..............................#........................#.........#........#............................... +............#.....#..........................#.......................#....................................................................#. +........................#........................................................#.......................................................... +............................................................#..............#......................................#......................... +...#........................................................................................#............................................... +...........................................................................................................#......................#......... +..........#.......................................................................................#......................................... +......................#................#............................................#.................................................#..... +...........................#.....................#........#...................................................#............................. diff --git a/day_11/part_1/Cargo.toml b/day_11/part_1/Cargo.toml new file mode 100644 index 0000000..53b1270 --- /dev/null +++ b/day_11/part_1/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "day_11-1" +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/day_11/part_1/src/main.rs b/day_11/part_1/src/main.rs new file mode 100644 index 0000000..0172c19 --- /dev/null +++ b/day_11/part_1/src/main.rs @@ -0,0 +1,50 @@ +use std::cmp; + +fn main() { + let input = include_str!("../../input.txt") + .lines() + .map(|line| line.chars().collect::>()) + .collect::>>(); + + let mut galaxies: Vec<(usize, usize)> = vec![]; + let mut double_rows: Vec = vec![]; + let mut double_columns: Vec = vec![]; + + for (i, line) in input.iter().enumerate() { + if !line.contains(&'#') { + double_rows.push(i); + } + } + + 'deez: for i in 0..input[0].len() { + for row in &input { + if row[i] == '#' { + continue 'deez; + } + } + double_columns.push(i); + } + + for (i, line) in input.iter().enumerate() { + for (j, c) in line.iter().enumerate() { + if c == &'#' { + galaxies.push((i, j)); + } + } + } + + let mut result = 0; + for (i, galaxy_1) in galaxies.iter().enumerate() { + for galaxy_2 in galaxies.iter().skip(i + 1) { + for x in cmp::min(galaxy_1.0, galaxy_2.0)+1..=cmp::max(galaxy_1.0, galaxy_2.0) { + result += 1 * if double_rows.contains(&x) { 2 } else { 1 }; + } + + for y in cmp::min(galaxy_1.1, galaxy_2.1)+1..=cmp::max(galaxy_1.1, galaxy_2.1) { + result += 1 * if double_columns.contains(&y) { 2 } else { 1 }; + } + } + } + + println!("Result: {result}"); +} diff --git a/day_11/part_2/Cargo.toml b/day_11/part_2/Cargo.toml new file mode 100644 index 0000000..20da4f5 --- /dev/null +++ b/day_11/part_2/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "day_11-2" +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/day_11/part_2/src/main.rs b/day_11/part_2/src/main.rs new file mode 100644 index 0000000..12f9b42 --- /dev/null +++ b/day_11/part_2/src/main.rs @@ -0,0 +1,51 @@ +use std::cmp; + +fn main() { + let input = include_str!("../../input.txt") + .lines() + .map(|line| line.chars().collect::>()) + .collect::>>(); + + let mut galaxies: Vec<(usize, usize)> = vec![]; + let mut double_rows: Vec = vec![]; + let mut double_columns: Vec = vec![]; + + for (i, line) in input.iter().enumerate() { + if !line.contains(&'#') { + double_rows.push(i); + } + } + + 'deez: for i in 0..input[0].len() { + for row in &input { + if row[i] == '#' { + continue 'deez; + } + } + double_columns.push(i); + } + + for (i, line) in input.iter().enumerate() { + for (j, c) in line.iter().enumerate() { + if c == &'#' { + galaxies.push((i, j)); + } + } + } + + // already used the correct approach in part 1 :3 + let mut result: i64 = 0; + for (i, galaxy_1) in galaxies.iter().enumerate() { + for galaxy_2 in galaxies.iter().skip(i + 1) { + for x in cmp::min(galaxy_1.0, galaxy_2.0)+1..=cmp::max(galaxy_1.0, galaxy_2.0) { + result += 1 * if double_rows.contains(&x) { 1000000 } else { 1 }; + } + + for y in cmp::min(galaxy_1.1, galaxy_2.1)+1..=cmp::max(galaxy_1.1, galaxy_2.1) { + result += 1 * if double_columns.contains(&y) { 1000000 } else { 1 }; + } + } + } + + println!("Result: {result}"); +}