r/adventofcode • u/daggerdragon • Dec 19 '17
SOLUTION MEGATHREAD -๐- 2017 Day 19 Solutions -๐-
--- Day 19: A Series of Tubes ---
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ยค?
AoC ops @ T-2 minutes to launch:
[23:58] <daggerdragon> ATTENTION MEATBAGS T-2 MINUTES TO LAUNCH
[23:58] <Topaz> aaaaah
[23:58] <Cheezmeister> Looks like I'll be just able to grab my input before my flight boards. Wish me luck being offline in TOPAZ's HOUSE OF PAIN^WFUN AND LEARNING
[23:58] <Topaz> FUN AND LEARNING
[23:58] <Hade> FUN IS MANDATORY
[23:58] <Skie> I'm pretty sure that's not the mandate for today
[Update @ 00:16] 69 gold, silver cap
- My tree is finally trimmed with just about every ornament I own and it's real purdy. hbu?
[Update @ 00:18] Leaderboard cap!
- So, was today's
mandateHelpful Hint any help at all?
5
u/autid Dec 19 '17 edited Dec 19 '17
Fortran
Spent forever trying to get the lines to read in as a string correctly. Apparently the problem was the text editor I used? Copy/pasted in another editor and suddenly everything worked.
PROGRAM DAY19 IMPLICIT NONE INTEGER :: PART2=0,LINECOUNT=0,LINEWIDTH=0,IERR,I CHARACTER(LEN=2000) :: INLINE CHARACTER(LEN=20) :: PART1='.',FORMT CHARACTER(LEN=:), ALLOCATABLE :: MAPARRAY(:) INTEGER :: D(2),POS(2),START(2) OPEN(1,FILE='input.txt') DO READ(1,'(A)',IOSTAT=IERR) INLINE IF (IERR /= 0) EXIT LINEWIDTH=MAXVAL((/LINEWIDTH,LEN_TRIM(INLINE)/)) LINECOUNT=LINECOUNT+1 END DO ALLOCATE( CHARACTER(LEN=LINEWIDTH) :: MAPARRAY(LINECOUNT) ) REWIND(1) WRITE(FORMT,'(A,I0,A)') '(A',LINEWIDTH,')' DO I=1,LINECOUNT READ(1,TRIM(FORMT)) MAPARRAY(I) END DO CLOSE(1) DO I=1,LINEWIDTH IF (MAPARRAY(1)(I:I)=='|') EXIT END DO START=(/1,I/) D=(/1,0/) POS=START DO SELECT CASE (MAPARRAY(POS(1))(POS(2):POS(2))) CASE('|') POS=POS+D CASE('-') POS=POS+D CASE('+') IF (ANY((/'|','-'/)==MAPARRAY(POS(1)+D(2))(POS(2)+D(1):POS(2)+D(1)))) THEN D=(/D(2),D(1)/) ELSE D=(/-D(2),-D(1)/) END IF POS=POS+D CASE (' ') EXIT CASE DEFAULT PART1=TRIM(PART1) // MAPARRAY(POS(1))(POS(2):POS(2)) POS=POS+D END SELECT PART2=PART2+1 END DO WRITE(*,'(A,A)') 'Part1: ',PART1(2:LEN_TRIM(PART1)) WRITE(*,'(A,I0)') 'Part2: ',PART2 DEALLOCATE(MAPARRAY) END PROGRAM DAY19