Skip to content

Instantly share code, notes, and snippets.

@angus-g
Created December 1, 2019 07:40
Show Gist options
  • Save angus-g/f8c39a5090c6f6b4f09eb7a69692205d to your computer and use it in GitHub Desktop.
Save angus-g/f8c39a5090c6f6b4f09eb7a69692205d to your computer and use it in GitHub Desktop.
advent of code day 1
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