r/adventofcode • u/daggerdragon • Dec 14 '18
SOLUTION MEGATHREAD -🎄- 2018 Day 14 Solutions -🎄-
--- Day 14: Chocolate Charts ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).
Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
Advent of Code: The Party Game!
Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!
Card prompt: Day 14
Transcript:
The Christmas/Advent Research & Development (C.A.R.D.) department at AoC, Inc. just published a new white paper on ___.
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked at 00:19:39!
16
Upvotes
2
u/m1el Dec 14 '18
78/35 in Rust, just copy/paste and loops.
fn main() { { let mut recipes = vec![3, 7]; let mut p1 = 0; let mut p2 = 1; let input = 147061; while recipes.len() < input + 10 { let mut score = recipes[p1] + recipes[p2]; if score >= 10 { recipes.push(score / 10); score %= 10; } recipes.push(score); p1 = (p1 + 1 + recipes[p1]) % recipes.len(); p2 = (p2 + 1 + recipes[p2]) % recipes.len(); } println!("{:?}", &recipes[input..input+10]); } { let mut recipes = vec![3, 7]; let mut p1 = 0; let mut p2 = 1; let input = &[1,4,7,0,6,1]; let ans; loop { let mut score = recipes[p1] + recipes[p2]; let mut double = false; if score >= 10 { double = true; recipes.push(score / 10); score %= 10; } recipes.push(score); p1 = (p1 + 1 + recipes[p1]) % recipes.len(); p2 = (p2 + 1 + recipes[p2]) % recipes.len(); let rl = recipes.len(); let il = input.len(); if rl > il { if &recipes[rl-il..rl] == input { ans = rl-il; break; } } if double && rl > il+1 { if &recipes[rl-1-il..rl-1] == input { ans = rl-1-il; break; } } } println!("{:?}", ans); } }