solution: day20
This commit is contained in:
parent
0000035064
commit
000003606b
|
@ -394,9 +394,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "ipnet"
|
||||
version = "2.5.1"
|
||||
version = "2.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f88c5561171189e69df9d98bcf18fd5f9558300f7ea7b801eb8a0fd748bd8745"
|
||||
checksum = "11b0d96e660696543b251e58030cf9787df56da39dab19ad60eae7353040917e"
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
|
@ -716,9 +716,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.149"
|
||||
version = "1.0.150"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "256b9932320c590e707b94576e3cc1f7c9024d0ee6612dfbcf1cb106cbe8e055"
|
||||
checksum = "e326c9ec8042f1b5da33252c8a37e9ffbd2c9bef0155215b6e6c80c790e05f91"
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
pub fn part_one(input: &str) -> Option<u32> {
|
||||
let limit = input.parse::<usize>().unwrap() / 10;
|
||||
let elves = 1_000_000;
|
||||
let mut delivered = vec![0; elves];
|
||||
for i in 1..elves {
|
||||
for j in (i..elves).step_by(i) {
|
||||
delivered[j] += i;
|
||||
}
|
||||
}
|
||||
|
||||
Some(
|
||||
delivered
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|(_, &x)| x > limit)
|
||||
.unwrap()
|
||||
.0 as u32,
|
||||
)
|
||||
}
|
||||
pub fn part_two(input: &str) -> Option<u32> {
|
||||
let limit = input.parse().unwrap();
|
||||
let elves = 1_000_000;
|
||||
let mut delivered = vec![0; elves];
|
||||
for i in 1..elves {
|
||||
for j in (i..elves).step_by(i).take(50) {
|
||||
delivered[j] += i * 11;
|
||||
}
|
||||
}
|
||||
|
||||
Some(
|
||||
delivered
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|(_, &x)| x > limit)
|
||||
.unwrap()
|
||||
.0 as u32,
|
||||
)
|
||||
}
|
||||
fn main() {
|
||||
let input = &aoc::read_file("inputs", 20);
|
||||
aoc::solve!(1, part_one, input);
|
||||
aoc::solve!(2, part_two, input);
|
||||
}
|
Loading…
Reference in New Issue