Created
December 1, 2019 07:40
-
-
Save angus-g/f8c39a5090c6f6b4f09eb7a69692205d to your computer and use it in GitHub Desktop.
advent of code day 1
This file contains hidden or 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 day1 | |
implicit none | |
integer :: stat, m, s, s2 | |
s = 0 | |
s2 = 0 | |
open(1, file="day1.in", iostat=stat) | |
do | |
read(1, *, iostat=stat) m | |
if (stat /= 0) exit | |
s = s + (m / 3) - 2 | |
s2 = s2 + launch(m) | |
end do | |
print *, s, s2 | |
close(1) | |
contains | |
recursive function launch(m) result(res) | |
integer, intent(in) :: m | |
integer :: res, x | |
x = m/3 - 2 | |
if (x < 0) then | |
res = 0 | |
else | |
res = x + launch(x) | |
end if | |
end function launch | |
end program day1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment