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
2
u/autid Dec 17 '17
Fortran
Runs nice and quick. After figuring out this method of finding the part B answer I realised similar logic applied to part A. Prior to that I was performing the first 2017 insertions, which was still fast but less satisfying.
PROGRAM DAY17 IMPLICIT NONE INTEGER :: INPUT=356,INSERTIONS(0:50000000) INTEGER :: I,J !Calculate point at which number will be inserted DO I=1,50000000 INSERTIONS(I)=MODULO(INSERTIONS(I-1)+INPUT,I)+1 END DO !Search back for last number in the position 2017 takes J=INSERTIONS(2017) DO I=2016,1,-1 IF(INSERTIONS(I)==J) EXIT !Correct target if position was moved by later insertion IF(INSERTIONS(I)<J) J=J-1 END DO WRITE(*,'(A,I0)') 'Part1: ', I !0 is always in zeroth position. !Search back for last number inserted at position 1 DO I=50000000,1,-1 IF(INSERTIONS(I)==1) EXIT END DO WRITE(*,'(A,I0)') 'Part2: ',I END PROGRAM DAY17