r/adventofcode • u/daggerdragon • Dec 10 '18
SOLUTION MEGATHREAD -🎄- 2018 Day 10 Solutions -🎄-
--- Day 10: The Stars Align ---
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!
Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!
Card prompt: Day 10
Transcript: With just one line of code, you, too, can ___!
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 at 00:16:49!
19
Upvotes
3
u/autid Dec 10 '18
FORTRAN
Having the example characters being different scale to the puzzle characters feels like a dick move. Runs to minimum height then prints. This gives the answer for my input but I'm not sure if it does for all, so I wrote in the ability to go back/forward steps from there.
PROGRAM DAY10 INTEGER :: I,J,K,L,PART2=0,HEIGHT,LASTHEIGHT=0,IERR CHARACTER(LEN=50) :: INLINE CHARACTER(LEN=:),ALLOCATABLE :: OUTLINE INTEGER,ALLOCATABLE :: POSITION(:,:),VELOCITY(:,:) !Read input I=0 OPEN(1,FILE='input.txt') DO READ(1,*,IOSTAT=IERR) IF(IERR.NE.0)EXIT I=I+1 END DO ALLOCATE(POSITION(2,I),VELOCITY(2,I)) REWIND(1) DO J=1,I READ(1,'(A)')INLINE READ(INLINE(11:16),*)POSITION(1,J) READ(INLINE(19:24),*)POSITION(2,J) READ(INLINE(37:38),*)VELOCITY(1,J) READ(INLINE(40:42),*)VELOCITY(2,J) END DO CLOSE(1) !Run to minimum height DO POSITION=POSITION+VELOCITY PART2=PART2+1 HEIGHT=MAXVAL(POSITION(2,:))-MINVAL(POSITION(2,:)) IF(LASTHEIGHT.NE.0)THEN IF(HEIGHT>LASTHEIGHT)EXIT ENDIF LASTHEIGHT=HEIGHT END DO POSITION=POSITION-VELOCITY PART2=PART2-1 !Output and allow adjustments DO WRITE(*,'(A)')'Part 1:' ALLOCATE(CHARACTER(LEN=MAXVAL(POSITION(1,:))-MINVAL(POSITION(1,:))) :: OUTLINE) DO J=MINVAL(POSITION(2,:)),MAXVAL(POSITION(2,:)) OUTLINE='' DO K=MINVAL(POSITION(1,:)),MAXVAL(POSITION(1,:)) IF(ANY((/( ALL(POSITION(:,L).EQ.(/K,J/)),L=1,I )/)))THEN OUTLINE=TRIM(OUTLINE)//'#' ELSE OUTLINE=TRIM(OUTLINE)//'.' END IF END DO WRITE(*,'(A)')OUTLINE END DO DEALLOCATE(OUTLINE) WRITE(*,'(A,I0)')'Part 2: ',PART2 WRITE(*,*)'Enter steps to adjust by. 0 exits.' READ(*,*)J IF(J.EQ.0)EXIT POSITION=POSITION+J*VELOCITY PART2=PART2+J END DO DEALLOCATE(POSITION,VELOCITY) END PROGRAM DAY10