This commit is contained in:
Lea 2023-12-11 21:18:32 +01:00
parent b21a95f539
commit 1054ed64d5
Signed by: Lea
GPG key ID: 1BAFFE8347019C42
6 changed files with 265 additions and 0 deletions

8
Cargo.lock generated
View file

@ -30,6 +30,14 @@ version = "0.1.0"
name = "day_10-2" name = "day_10-2"
version = "0.1.0" version = "0.1.0"
[[package]]
name = "day_11-1"
version = "0.1.0"
[[package]]
name = "day_11-2"
version = "0.1.0"
[[package]] [[package]]
name = "day_2-1" name = "day_2-1"
version = "0.1.0" version = "0.1.0"

140
day_11/input.txt Normal file
View file

@ -0,0 +1,140 @@
........................#...............................................#................................#................................#.
....#..............#......................#............#....................................................................#...............
................................#.............................................................#.............................................
.........#.....................................#...................#........................................................................
....................................................#.......................#..............................#................................
..#................................................................................................#................#......................#
.........................................................#.........................#.....#..................................................
..................................#.............................#...............................................#.............#.............
.......#.....#...........................#..............................................................#.............................#.....
......................#...............................#................................................................#....................
............................#.................#........................#.....................................#..............................
....#.................................#...............................................#.....................................................
...............#...........................................................#............................................................#...
..................................#...........................................................#...................#...........#.............
....................................................................................................................................#.......
................................................................#................#..........................#...............................
...#..............#........#.........#.............#........................................................................................
.........................................................#.............#.............#..............#...................#...................
........#...................................................................................................................................
..............................................................................................#.................................#........#..
....................#.......................................#.....................................................#.........................
#..............................#.......#......#...................................#......#..................................................
...........#.......................................#......................................................................#.................
.......................................................................................................................................#....
............................................................................................................................................
.........................#...................................#...............................#..............................................
..................................#.......................................................................#.............#...................
.........................................#...........................#...............................#.........#..........................#.
............#......#............................................#...............................#...................................#.......
.............................#.....................................................#........................................................
....#........................................#...............................#.................................................#............
......................#............................#.....#.........#........................................................................
.........................................................................................................#..................................
.......#........................#................................................#..........................................................
...............................................#..........................#................#..........................................#.....
.#................#.............................................................................................#......#....................
..............................................................................................................................#.............
..........................#........................#.............................................#..........................................
.............#..........................#............................................#..............................#.......................
........#..............................................#.....................#..........................#..................#................
............................................................#.....#..................................................................#......
....................#.........................#..........................#..................#...................#...........................
..............................#...................................................#................#........................................
.........................................#..............................................#..................................................#
.#........#.........................................#.....................................................#.....................#...........
.........................................................#.........................................................#........................
......#...........................#.........................................................................................................
................................................#........................................................................................#..
...................................................................#...............#........................................................
.....................#................................#..............................................................................#......
...........#................................................................................#.....#.........................................
....#........................#............................................#..............................................#..................
................#.......#........................................................#........................................................#.
#...................................................................................................................#.......................
....................#...................#..............#.................................#...................#..............................
.............#....................#.................................................#..................#...................#................
.................................................................................................................#.....................#....
................................................................................#...........................................................
.......................#.............#....................#.................................................................................
.......#.............................................................................................#..............#.......................
...................#.....................................................................................................................#..
......................................................#..................#.......................................................#..........
..........................#..................................................................#..............................................
............#.................................#.........................................#...................#............#..................
.....................#......................................#......................................................#..........#.............
.#.........................................................................#......#...................#.....................................
............................................................................................................................................
................................#...........................................................#...............................................
........................................#..........................#..................................................#.................#...
....#........................................#.....................................................#.............................#..........
..........................................................#.................................................................................
...............#............................................................................................................................
..........#............#............................#.............................#...........................................#......#......
....................................#........................................................#...............#..............................
...........................................#..............................#...............................................................#.
.#...........................#.......................................................................#......................................
.........................................................#...........#....................................#.................................
......#.......#...................#...........................#.......................#.........#..................#........................
............................................................................#.........................................................#.....
.....................#.........................................................................................#........#...................
..........................#.............................................#................#........................................#.........
............................................................................................................................................
....#.....#.....#..................................#.........#.....................#....................#...................................
........................................#.....................................................................................#.............
...............................................................................................#............................................
.......#........................#...........................................#............................................................#..
....................#......#....................#...........................................................................................
.........................................................#...........#..........#.............................#...........#.................
......................................................................................#.....................................................
....................................................................................................#................#..........#.....#.....
............#.........#.....................#...............#..............................................#................................
.......#............................#.......................................................................................................
.......................................................................#......................#................#...................#........
............................................................................................................................................
........................................................................................................................#...................
..........#..........#.......................#.........................................................................................#....
...................................................................#.................#...........#..........................................
........................................#................#..................................................................................
................#....................................................................................................#......................
............................................................................................................................................
.......#....................#.................................................................#...............#.........................#...
.................................#...........#.....#...........................................................................#............
...........#.......................................................#....................#...................................................
........................................#...............................................................................#...................
............................................................................................................................................
.....................................................................................................#......................................
................#.........................................#..................#................................................#.......#.....
....#................................#.............#...................................#.....................#.......#......................
.........................#......................................#...........................................................................
...........................................................................................#.......#........................................
..........#.....................#..............#........................#...................................................................
..#.........................................................................................................................................
....................#.....................................#.......................#.........................................................
..........................#.............#...............................................................................#.........#.........
......................................................................................#.....................................................
.....................................................................#..........................#...........................................
.......#.........#...........................................................#.......................#........#............#............#...
........................#....................................#..............................................................................
.......................................#............................................#....................#.........................#........
..............................................#....................................................................#........................
..............#..................#.....................................#..........................#.........................................
..........................................#..........#..........................#...........................................................
.....#......................................................................................#................#..............................
.....................#................................................................#.......................................#.............
.....................................................................#......................................................................
...........#.....#............................#.....................................................................................#.......
................................#.....#..........................#........#..........................................#....................#.
...........................#.................................................................#........#.......#.............................
#...........................................................................................................................................
........#........................................#...................................#......................................................
.............................................................................................................................#..............
.................................#..............................#........................#.........#........#...............................
............#.....#..........................#.......................#....................................................................#.
........................#........................................................#..........................................................
............................................................#..............#......................................#.........................
...#........................................................................................#...............................................
...........................................................................................................#......................#.........
..........#.......................................................................................#.........................................
......................#................#............................................#.................................................#.....
...........................#.....................#........#...................................................#.............................

8
day_11/part_1/Cargo.toml Normal file
View file

@ -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]

50
day_11/part_1/src/main.rs Normal file
View file

@ -0,0 +1,50 @@
use std::cmp;
fn main() {
let input = include_str!("../../input.txt")
.lines()
.map(|line| line.chars().collect::<Vec<char>>())
.collect::<Vec<Vec<char>>>();
let mut galaxies: Vec<(usize, usize)> = vec![];
let mut double_rows: Vec<usize> = vec![];
let mut double_columns: Vec<usize> = 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}");
}

8
day_11/part_2/Cargo.toml Normal file
View file

@ -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]

51
day_11/part_2/src/main.rs Normal file
View file

@ -0,0 +1,51 @@
use std::cmp;
fn main() {
let input = include_str!("../../input.txt")
.lines()
.map(|line| line.chars().collect::<Vec<char>>())
.collect::<Vec<Vec<char>>>();
let mut galaxies: Vec<(usize, usize)> = vec![];
let mut double_rows: Vec<usize> = vec![];
let mut double_columns: Vec<usize> = 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}");
}