Compare commits
2 Commits
c1abd8d8f8
...
d938e3a57c
| Author | SHA1 | Date | |
|---|---|---|---|
| d938e3a57c | |||
| e135a6a349 |
@@ -6,3 +6,7 @@ edition = "2021"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
itertools = "0.13.0"
|
itertools = "0.13.0"
|
||||||
regex = "1.11.1"
|
regex = "1.11.1"
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
opt-level = 3
|
||||||
|
|
||||||
|
|||||||
32
src/day14.rs
32
src/day14.rs
@@ -1,8 +1,4 @@
|
|||||||
use std::{
|
use std::fs::read_to_string;
|
||||||
collections::HashSet,
|
|
||||||
fs::read_to_string,
|
|
||||||
io::{self, BufRead},
|
|
||||||
};
|
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
@@ -69,17 +65,16 @@ fn parse(input: &str) -> Vec<((i64, i64), (i64, i64))> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
fn part2(input: &str) -> RiddleResult {
|
fn part2(input: &str) -> i64 {
|
||||||
let width = 101;
|
let width = 101;
|
||||||
let height = 103;
|
let height = 103;
|
||||||
let mut robots = parse(input);
|
let mut robots = parse(input);
|
||||||
let mut seen = HashSet::new();
|
let max_seconds = width * height as i64;
|
||||||
for second in 0.. {
|
for second in 0.. {
|
||||||
if seen.contains(&robots) {
|
if second > max_seconds {
|
||||||
panic!("Loop after {second} rounds, but no christmas tree!");
|
panic!("Seen all combinations but no christmas tree. So sad!");
|
||||||
}
|
}
|
||||||
let mut grid: Grid<u8> = Grid::from_default(101, 103);
|
let mut grid: Grid<u8> = Grid::from_default(101, 103);
|
||||||
seen.insert(robots.clone());
|
|
||||||
robots.iter_mut().for_each(|((px, py), (vx, vy))| {
|
robots.iter_mut().for_each(|((px, py), (vx, vy))| {
|
||||||
*px = (*px + width + *vx) % width;
|
*px = (*px + width + *vx) % width;
|
||||||
*py = (*py + height + *vy) % height;
|
*py = (*py + height + *vy) % height;
|
||||||
@@ -99,20 +94,23 @@ fn part2(input: &str) -> RiddleResult {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if robots.iter().filter(|(s, _)| grid[*s] > 1).count() > robots.len() * 70 / 100 {
|
if robots.iter().filter(|(s, _)| grid[*s] > 1).count() > robots.len() * 70 / 100 {
|
||||||
printr(&robots, width, height);
|
// printr(&robots, width, height);
|
||||||
println!("after {} seconds. Press enter to continue or type 'merry christmas' if you can spot a tree!", second + 1); //+1 because we look at it after they have changed
|
// println!("after {} seconds. Press enter to continue or type 'merry christmas' if you can spot a tree!", second + 1); //+1 because we look at it after they have changed
|
||||||
let stdin = io::stdin();
|
return second + 1;
|
||||||
let line = stdin.lock().lines().next().unwrap().unwrap();
|
// let stdin = io::stdin();
|
||||||
if line.as_str().eq_ignore_ascii_case("merry christmas") {
|
// let line = stdin.lock().lines().next().unwrap().unwrap();
|
||||||
return second + 1;
|
// if line.as_str().eq_ignore_ascii_case("merry christmas") {
|
||||||
}
|
// return second + 1;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
type Robot = ((i64, i64), (i64, i64));
|
type Robot = ((i64, i64), (i64, i64));
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
fn printr(robots: &[Robot], width: i64, height: i64) {
|
fn printr(robots: &[Robot], width: i64, height: i64) {
|
||||||
for y in 0..height {
|
for y in 0..height {
|
||||||
for x in 0..width {
|
for x in 0..width {
|
||||||
|
|||||||
Reference in New Issue
Block a user