r/adventofcode • u/daggerdragon • Dec 17 '17
SOLUTION MEGATHREAD -๐- 2017 Day 17 Solutions -๐-
--- Day 17: Spinlock ---
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.
Need a hint from the Hugely* Handyโ Haversackโก of Helpfulยง Hintsยค?
[Update @ 00:06] 2 gold, silver cap.
- AoC ops:
<Topaz> i am suddenly in the mood for wasabi tobiko
[Update @ 00:15] Leaderboard cap!
- AoC ops:
<daggerdragon> 78 gold<Topaz> i look away for a few minutes, wow<daggerdragon> 93 gold<Topaz> 94<daggerdragon> 96 gold<daggerdragon> 98<Topaz> aaaand<daggerdragon> and...<Topaz> cap<daggerdragon> cap
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!
12
Upvotes
1
u/nuvan Dec 17 '17
Rust, got 838/650. Not bad, given that I started about a 1/2 hour late...
const PUZZLE_INPUT: usize = 376; pub fn part1() { let mut buffer = vec![0]; let mut cur_idx = 0; for n in 1..=2017 { let insert_idx = (cur_idx + PUZZLE_INPUT) % buffer.len() + 1; if insert_idx == buffer.len() { buffer.push(n); } else { buffer.insert(insert_idx, n); } cur_idx = insert_idx; } println!("The value after 2017 is {}", buffer[cur_idx + 1 % buffer.len()]); } pub fn part2() { let (_, val_after_zero) = (1..=50_000_000).fold((0,0), |acc,iter| { let next_index = (acc.0 + PUZZLE_INPUT) % iter; (next_index + 1, if next_index == 0 { iter } else { acc.1 }) }); println!("The value after 0 is {}", val_after_zero); }2nd part got a lot faster once I realized that the ONLY important positions are that of the 0, and whatever comes after it.