Last active
July 29, 2019 20:47
-
-
Save DrFrankenstein/7e76f21d35f6de87404077920cf263d7 to your computer and use it in GitHub Desktop.
First AoC problem in Fortran
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PROGRAM AOC1 000010AA | |
IMPLICIT NONE 000020AA | |
C --------DECLARATIONS--------------------------------------------- 000030AA | |
CHARACTER :: C 000040AA | |
INTEGER :: STATUS, FLOOR, STEP 000050AA | |
LOGICAL :: BASEMENT 000060AA | |
C --------STATEMENTS----------------------------------------------- 000070AA | |
BASEMENT = .FALSE. 000080AA | |
FLOOR = 0 000090AA | |
STEP = 0 000100AA | |
DO 000110AA | |
READ (*, '(A1)', IOSTAT=STATUS) C 000120AA | |
C -STATUS -1 IS END OF FILE.- 000130AA | |
IF (STATUS == -1) EXIT 000140AB | |
IF (C == '(') THEN 000150AB | |
FLOOR = FLOOR + 1 000160AA | |
ELSE IF (C == ')') THEN 000170AB | |
FLOOR = FLOOR - 1 000180AA | |
END IF 000190AA | |
IF ((BASEMENT .EQV. .FALSE.) .AND. (FLOOR < 0)) THEN 000200AB | |
WRITE (*,*) 'BASEMENT ENTERED AT', STEP 000210AA | |
BASEMENT = .TRUE. 000220AA | |
END IF 000230AA | |
STEP = STEP + 1 000240AA | |
END DO 000250AA | |
WRITE (*,*) 'AT FLOOR', FLOOR 000260AA | |
END PROGRAM AOC1 000270AA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program aoc1 | |
implicit none | |
character :: c | |
integer :: status, floor, step | |
logical :: basement | |
basement = .false. | |
floor = 0 | |
step = 0 | |
do | |
read (*, '(A1)', iostat=status) c | |
if (status == -1) exit ! end of file | |
if (c == '(') then | |
floor = floor + 1 | |
else if (c == ')') then | |
floor = floor - 1 | |
end if | |
if ((basement .eqv. .false.) .and. (floor < 0)) then | |
write (*,*) 'Basement entered at', step | |
basement = .true. | |
end if | |
step = step + 1 | |
end do | |
write (*,*) 'At floor', floor | |
end program aoc1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment