diff --git a/day11/input.txt b/day11/input.txt index a0bda53..e89d7f7 100644 --- a/day11/input.txt +++ b/day11/input.txt @@ -1,10 +1,140 @@ -...#...... -.......#.. -#......... -.......... -......#... -.#........ -.........# -.......... -.......#.. -#...#..... \ No newline at end of file +.......#.....#.....................#.............#.................#.........................#.............................................. +#.....................#.......#.................................................................................#.......#................... +.......................................................................#.........................#..................................#....... +................................................................#..............#..............................................#............. +.........................................#............................................................#....................................# +.................#..................................................#....................................................................... +...........................#...............................................................................#................................ +....#.......#...........................................#..........................#.............................#.......................... +....................#.............#........#................................................................................................ +...................................................#...................................................#...................#................ +.........................#........................................#..................................................#...................... +......#..........#...........................................#...........#............#..................................................... +......................................#..........................................#.........................#.....................#.......... +.#...................#..................................#.......................................#........................................... +............#.................................#.....................#....................................................................... +............................................................................................................................................ +..............................#.....................................................................................#..................#.... +....................................................................................#........#......#....................................... +.........................#.........................#............#...........................................#............................... +.#......#.....#.......................#.................#........................................................#.....#.................... +...........................................................................#.................................................#.............. +...............................................#.......................................#...............#..........................#......... +......................#..................#.................................................................................................. +..........................................................................................................................#................. +......#...........................#.........................................................#........................#...................... +..............................................................................................................................#............. +..#.......................#.................#............................................................................................#.. +..................#....................................................#................#................................................... +....................................................#.....#....................#............................................................ +...............................#............................................................................................................ +..............................................#...............#..........................................................#...........#...... +.#.........#........................#..................................................................#.................................... +..........................................................................#.......................#........................................# +...................#......................................................................#................................................. +.............................................................................................................................#.............. +.....#...................................................................................................................................... +........................................................#........................#.......................................................... +.............................#...............#.....................#.....#............#..................#..............................#... +............................................................................................#......#...........#............................ +.........................#........#...................................................................................#..................... +...........................................................................................................................................# +.....................................................#.....#.................................................................#.............. +#.........................................................................................................#.......................#......... +................#...........................................................#.....................#......................................... +..............................#..............#...................................#.......#...........................#...................... +........#................#.........#............................#............................................#.............#.........#...... +............................................................................................................................................ +.......................................................#...............#.............................#...........................#.......... +.............#.................................#............................................................................................ +............................................................................................................................................ +..#.............................................................................#...........................................#...........#... +............................................................................................................................................ +......................................#..........................................................#................#......................... +............................#................#......#......................#...........#.................................................... +............................................................................................................................................ +....................................................................................................#................#..........#........... +.#............#...................#...............................#........................................#.............................#.. +.........#...............................................................#.................................................................. +.......................#....................#........#...........................................#.......................................... +............................................................#.....................................................#......................... +..............................#.......................................................................#...................#.......#......... +............#.......................#...................#............................#...................................................... +...................................................#......................................#..............................................#.. +.#................#...................................................#........................#............................................ +......#....................................................................#................................#............................... +...............................#....................................................................................#....................... +.........................#.....................#......#.............................................#.................................#..... +............................................................................................................................................ +...............#.....................#....................................................#................................................. +..................................................................................................................#......................... +....#......#.....................................#..............................#............................#............#.....#........... +....................#.............................................#....................#.........#.......................................#.. +.........................................................#..............#.............................#..................................... +............................#...........#...........................................................................#....................... +............................................................................................................................................ +#..................................#...............................................................#..........#............................. +.......#......................................................................................#.................................#.......#... +.....................#....................#...............................#.....#......................................#.................... +................................#..........................#......#....................#..........................#......................... +..............#...................................#........................................................................#...............# +....#....................................................................................................#.................................. +.......................#.................................................................................................................... +......................................#................................#..................#................................................. +.....................................................#............................................#...............................#......... +............................................................................................................................................ +............................................................................................................................................ +....#.................#..................................#.........................#..........................#............................. +.............#........................................................................................#..................#.................. +......................................#............................................................................#........................ +.........#....................................................#.........#............................................................#...... +.............................................................................................#.............................................. +.............................#...........#............................................................................#..................... +#..................#................................................#....................#.......................................#.........# +...................................................................................................#......#................................. +...........#.............................................#...........................#...................................................... +....................................#....................................................................................................... +..................................................#..........#.........#......................#.....................#....................... +.#......#....................................#..............................................................#............................... +.............................#.............................................#................................................................ +.......................#...............................................................................#....................#............... +....................................................#.....................................#...........................................#..... +................#.....................#..................#.................................................................................# +...#.....#..........................................................#................#...................................................... +.............................................#...............#................................#......#...................................... +...............................#...............................................#............................................................ +.............................................................................................................................#.........#.... +.....................#................................................#.................................................#................... +...............#.........................#.......................#..................#....................................................... +.....#......................................................................................................#.......................#....... +....................................#.................#.........................#..................#........................................ +........................................................................................................................................#... +.........#..............#.....................................#........................................#.....................#.............. +...............................................#...................#........................................................................ +......................................#.............#..................................#.....#.......................#...................... +............#.....#...............................................................................#......................................... +...#...................................................................................................................................#.... +.......................#.........................#.......................................................................................... +.........................................................#...........#.........................#........#..........#.............#.......... +............................#..............#....................#........................................................#.................. +.......#.................................................................#................#................................................. +.................#..................................................................................#........................#...........#.. +...................................................#.......#................................................................................ +.........................................#......................................#......................................#.................... +....................................#...........................................................................#........................... +..............................#.............................................................#...........#.......................#......#.... +.........#...............................................#..............#................................................................... +........................#....................#.....................................#........................................................ +#........................................................................................................................................... +............................#......................................................................#.......#................................ +......................................#..................................................................................................... +.....#............#.........................................#..........................#..........................................#......... +...........................................#......................#..............................................#.......................... +..............#..............................................................................#............................#.............#... +..#......#...........................................#..............................#..................#.....#.............................. +....................#..........#.....#...............................#...................................................................... +............................................................................................................................................ +.................................................#.......................................................................................... +.............#..........#...............................#...............#.............#..........#.........#........#....................... +............................................#................#.................#............................................................ +....................................#....................................................................................#.............#.... \ No newline at end of file diff --git a/day11/src/main.rs b/day11/src/main.rs index 17fb63d..2c1423b 100644 --- a/day11/src/main.rs +++ b/day11/src/main.rs @@ -6,38 +6,48 @@ fn main() { .map(|x| x.chars().collect::>()) .collect(); - let mut rotate: Vec> = vec![]; + let mut y_expand: Vec = vec![]; + for line in &input { + if line.iter().all(|char| char == &'.') { + y_expand.push(1); + } else { + y_expand.push(0); + } + } + + let mut x_expand: Vec = vec![]; for j in 0..input[0].len() { - let mut tmp: Vec = vec![]; + let mut is_empty = true; for i in 0..input.len() { - tmp.push(input[i][j]); + if input[i][j] != '.' { + is_empty = false; + } } - - if tmp.iter().all(|x| x == &'.') { - rotate.push(tmp.clone()); + if is_empty { + x_expand.push(1); + } else { + x_expand.push(0); } - rotate.push(tmp); } + // println!("{:?}", x_expand); - let mut expanded: Vec> = vec![]; - for j in 0..rotate[0].len() { - let mut tmp: Vec = vec![]; - for i in 0..rotate.len() { - tmp.push(rotate[i][j]); + let mut galaxies: Vec<(i64, i64)> = vec![]; + + let mut y_offset: i64 = 0; + + for (i, line) in input.iter().enumerate() { + if y_expand[i] == 1 { + y_offset += 1000000 - 1; } - if tmp.iter().all(|x| x == &'.') { - expanded.push(tmp.clone()); - } - expanded.push(tmp); - } + let mut x_offset: i64 = 0; - let mut galaxies: Vec<(i32, i32)> = vec![]; - - for (i, line) in expanded.iter().enumerate() { for (j, char) in line.iter().enumerate() { + if x_expand[j] == 1 { + x_offset += 1000000 - 1; + } if char == &'#' { - galaxies.push((i as i32,j as i32)); + galaxies.push((i as i64 + y_offset, j as i64 + x_offset)); } } } @@ -52,4 +62,60 @@ fn main() { println!("{:?}", dist_total); -} \ No newline at end of file +} + +// use std::fs; + +// fn main() { +// let input = fs::read_to_string("input.txt").unwrap(); +// let input: Vec<_> = input.split('\n') +// .map(|x| x.chars().collect::>()) +// .collect(); + +// let mut rotate: Vec> = vec![]; +// for j in 0..input[0].len() { +// let mut tmp: Vec = vec![]; +// for i in 0..input.len() { +// tmp.push(input[i][j]); +// } + +// if tmp.iter().all(|x| x == &'.') { +// rotate.push(tmp.clone()); +// } +// rotate.push(tmp); +// } + + +// let mut expanded: Vec> = vec![]; +// for j in 0..rotate[0].len() { +// let mut tmp: Vec = vec![]; +// for i in 0..rotate.len() { +// tmp.push(rotate[i][j]); +// } +// if tmp.iter().all(|x| x == &'.') { +// expanded.push(tmp.clone()); +// } +// expanded.push(tmp); +// } + +// let mut galaxies: Vec<(i32, i32)> = vec![]; + +// for (i, line) in expanded.iter().enumerate() { +// for (j, char) in line.iter().enumerate() { +// if char == &'#' { +// galaxies.push((i as i32,j as i32)); +// } +// } +// } + +// let dist_total = galaxies.clone().into_iter().enumerate() +// .fold(0, |mut acc, (i, gal)| { +// for next in &galaxies[i + 1..] { +// acc += gal.0.abs_diff(next.0) + gal.1.abs_diff(next.1); +// } +// acc +// }); + +// println!("{:?}", dist_total); + +// } \ No newline at end of file