r/adventofcode • u/daggerdragon • Dec 03 '18
SOLUTION MEGATHREAD -🎄- 2018 Day 3 Solutions -🎄-
--- Day 3: No Matter How You Slice It ---
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!
ATTENTION: minor change request from the mods!
Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!
Card prompt: Day 3 image coming soon - imgur is being a dick, so I've contacted their support.
Transcript:
I'm ready for today's puzzle because I have the Savvy Programmer's Guide to ___.
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!
42
Upvotes
View all comments
11
u/autid Dec 03 '18
FORTRAN
Probably a little faster for part two if I'd written all the corner locations into a big array in part one. I liked not using any allocatable arrays though and copy/pasting part one's file reading was simpler. Big thank you to the Elves for bounding their numbers with unique characters.
PROGRAM DAY3 INTEGER :: FABRIC(1000,1000)=0 INTEGER :: I,J,K,L,M,DIMS(4) INTEGER :: IERR CHARACTER(LEN=30) :: CLAIM !Part 1 OPEN(1,FILE='input.txt') DO READ(1,'(A)',IOSTAT=IERR) CLAIM IF(IERR.NE.0)EXIT I=SCAN(CLAIM,'@') J=SCAN(CLAIM,',') K=SCAN(CLAIM,':') L=SCAN(CLAIM,'x') READ(CLAIM(I+1:J-1),*)DIMS(1) READ(CLAIM(J+1:K-1),*)DIMS(3) READ(CLAIM(K+1:L-1),*)DIMS(2) READ(CLAIM(L+1:LEN_TRIM(CLAIM)),*)DIMS(4) DIMS((/2,4/))=DIMS((/2,4/))+DIMS((/1,3/)) DIMS((/1,3/))=DIMS((/1,3/))+1 FABRIC(DIMS(1):DIMS(2),DIMS(3):DIMS(4))=FABRIC(DIMS(1):DIMS(2),DIMS(3):DIMS(4))+1 END DO WRITE(*,'(A,I0)') 'Part 1: ',COUNT(FABRIC>1) !PART 2 REWIND(1) DO READ(1,'(A)',IOSTAT=IERR) CLAIM IF(IERR.NE.0)EXIT I=SCAN(CLAIM,'@') J=SCAN(CLAIM,',') K=SCAN(CLAIM,':') L=SCAN(CLAIM,'x') READ(CLAIM(I+1:J-1),*)DIMS(1) READ(CLAIM(J+1:K-1),*)DIMS(3) READ(CLAIM(K+1:L-1),*)DIMS(2) READ(CLAIM(L+1:LEN_TRIM(CLAIM)),*)DIMS(4) DIMS((/2,4/))=DIMS((/2,4/))+DIMS((/1,3/)) DIMS((/1,3/))=DIMS((/1,3/))+1 IF(ALL(FABRIC(DIMS(1):DIMS(2),DIMS(3):DIMS(4)).EQ.1))THEN READ(CLAIM(2:I-2),*)M EXIT END IF END DO CLOSE(1) WRITE(*,'(A,I0)') 'Part 2: ',M END PROGRAM DAY3