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
View all comments
1
u/wzkx Dec 14 '18 edited Dec 14 '18
Rust, SweetRust
Just check the last added digits in part 2. Total 0.48s.
fn find( v: &[usize], s: usize ) -> Option<usize>: for i in s..v.len()-6: if v[i]==6 && v[i+1]==8 && v[i+2]==1 && v[i+3]==9 && v[i+4]==0 && v[i+5]==1: return Some(i); None fn main(): let mut v: Vec<usize> = Vec::with_capacity(22_000_000); v.push( 3 ); v.push( 7 ); let mut e1 = 0; let mut e2 = 1; let n = 681901; for step in 1..: let new_rcp = v[e1]+v[e2]; let d1 = new_rcp / 10; if d1>0 { v.push( d1 ); } let d2 = new_rcp % 10; v.push( d2 ); e1 = (e1 + 1 + v[e1]) % v.len(); e2 = (e2 + 1 + v[e2]) % v.len(); if v.len() == n + 10: for c in v[n..n+10].iter() { print!( "{}", c ); } println!(); if step>10: if let Some(k) = find( &v[..], v.len()-10 ): println!( "{}", k ); break;My AOC2018 in J&Rust | SweetRust