day14 both parts
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
aoc_2018::tasks::day13::task1();
|
// aoc_2018::tasks::day14::task1();
|
||||||
// aoc_2018::tasks::day09::task2();
|
aoc_2018::tasks::day14::task2();
|
||||||
}
|
}
|
||||||
|
|||||||
55
src/tasks/day14.rs
Normal file
55
src/tasks/day14.rs
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
pub fn task1() {
|
||||||
|
let input: usize = 509671;
|
||||||
|
|
||||||
|
let mut scores = vec![3, 7];
|
||||||
|
let mut recipes = vec![0, 1];
|
||||||
|
|
||||||
|
while scores.len() < input + 10 {
|
||||||
|
let mut score: usize = recipes.iter().map(|recipe| scores[*recipe]).sum();
|
||||||
|
if score >= 10 {
|
||||||
|
scores.push(1);
|
||||||
|
score -= 10;
|
||||||
|
}
|
||||||
|
scores.push(score);
|
||||||
|
|
||||||
|
for recipe in recipes.iter_mut() {
|
||||||
|
*recipe = (*recipe + 1 + scores[*recipe]) % scores.len();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let result = scores[input..input + 10]
|
||||||
|
.iter()
|
||||||
|
.map(|s| s.to_string())
|
||||||
|
.collect::<String>();
|
||||||
|
println!("Last 10 for {}: {}", input, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn task2() {
|
||||||
|
let input = vec![5, 0, 9, 6, 7, 1];
|
||||||
|
|
||||||
|
let mut scores = vec![3, 7];
|
||||||
|
let mut recipes = vec![0, 1];
|
||||||
|
|
||||||
|
while scores.len() < 7
|
||||||
|
|| scores[scores.len() - 6..] != input[..]
|
||||||
|
&& scores[scores.len() - 7..scores.len() - 1] != input[..]
|
||||||
|
{
|
||||||
|
let mut score: usize = recipes.iter().map(|recipe| scores[*recipe]).sum();
|
||||||
|
if score >= 10 {
|
||||||
|
scores.push(1);
|
||||||
|
score -= 10;
|
||||||
|
}
|
||||||
|
scores.push(score);
|
||||||
|
|
||||||
|
for recipe in recipes.iter_mut() {
|
||||||
|
*recipe = (*recipe + 1 + scores[*recipe]) % scores.len();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if scores[scores.len() - 6..] != input[..] {
|
||||||
|
println!("{}", scores.len() - 7)
|
||||||
|
} else {
|
||||||
|
println!("{}", scores.len() - 8)
|
||||||
|
}
|
||||||
|
// 20227890 too high
|
||||||
|
}
|
||||||
@@ -11,3 +11,4 @@ pub mod day10;
|
|||||||
pub mod day11;
|
pub mod day11;
|
||||||
pub mod day12;
|
pub mod day12;
|
||||||
pub mod day13;
|
pub mod day13;
|
||||||
|
pub mod day14;
|
||||||
|
|||||||
Reference in New Issue
Block a user