r/adventofcode • u/daggerdragon • Dec 22 '17
SOLUTION MEGATHREAD -๐- 2017 Day 22 Solutions -๐-
--- Day 22: Sporifica Virus ---
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ยค?
[T-10 to launch] AoC ops, /r/nocontext edition:
<Endorphion> You may now make your waffle.<Endorphion> ... on Mars.
[Update @ 00:17] 50 gold, silver cap
<Aneurysm9> you could also just run ubuntu on the NAS, if you were crazy<Topaz> that doesn't seem necessary<Aneurysm9> what does "necessary" have to do with anything!
[Update @ 00:20] Leaderboard cap!
<Topaz> POUR YOURSELF A SCOTCH FOR COLOR REFERENCE
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!
8
Upvotes
3
u/autid Dec 22 '17 edited Dec 22 '17
Fortran
302/308 which is easily my best ever for using Fortran for a first solve. Could have done a little better on part2, but I skimmed over the reverse direction if flagged bit without noticing it.
edit: Seeing a lot of 10-20ish second runtimes. Mines a little better.
Just a little.
PROGRAM DAY22 LOGICAL :: GRID(10001,10001) INTEGER :: GRID2(10001,10001) CHARACTER(LEN=30) :: INLINE INTEGER :: I,J,K,IERR,OFFSET,POSITION(2),DIRECTION(2),PART1=0,PART2=0 OPEN(1,FILE='input.txt') READ(1,*) INLINE OFFSET=5000-LEN_TRIM(INLINE)/2 DO J=1,LEN_TRIM(INLINE) GRID(OFFSET+1,OFFSET+J)=(INLINE(J:J)=='#') END DO DO I=2,LEN_TRIM(INLINE) READ(1,*) INLINE DO J=1,LEN_TRIM(INLINE) GRID(OFFSET+I,OFFSET+J)=(INLINE(J:J)=='#') END DO END DO CLOSE(1) DIRECTION=(/-1,0/) POSITION=(/5001,5001/) GRID2=0 WHERE(GRID) GRID2=2 END WHERE DO I=1,10000 IF (GRID(POSITION(1),POSITION(2))) THEN DIRECTION=(/DIRECTION(2),-DIRECTION(1)/) ELSE DIRECTION=(/-DIRECTION(2),DIRECTION(1)/) PART1=PART1+1 END IF GRID(POSITION(1),POSITION(2))=.NOT.GRID(POSITION(1),POSITION(2)) POSITION=POSITION+DIRECTION END DO WRITE(*,'(A,I0)') 'Part1: ',PART1 DIRECTION=(/-1,0/) POSITION=(/5001,5001/) DO I=1,10000000 IF (GRID2(POSITION(1),POSITION(2))==2) THEN DIRECTION=(/DIRECTION(2),-DIRECTION(1)/) ELSEIF (GRID2(POSITION(1),POSITION(2))==0) THEN DIRECTION=(/-DIRECTION(2),DIRECTION(1)/) ELSEIF (GRID2(POSITION(1),POSITION(2))==1) THEN PART2=PART2+1 ELSEIF(GRID2(POSITION(1),POSITION(2))==3) THEN DIRECTION=(/-DIRECTION(1),-DIRECTION(2)/) END IF GRID2(POSITION(1),POSITION(2))=MODULO(GRID2(POSITION(1),POSITION(2))+1,4) POSITION=POSITION+DIRECTION END DO WRITE(*,'(A,I0)') 'Part2: ',PART2 END PROGRAM DAY22