Program recaman
integer :: array(100)
array(1) = 0
do n = 2, 100
  if (array(n-1)-n < 1) then
    array(n) = array(n-1)+n-1
  else
    array(n) = array(n-1)-n+1
  end if
  do i = 1, n-1
    if (array(n) == array(i)) then
      array(n) = array(n-1)+n-1
      exit
    end if
  end do
end do
print *, array
End Program recaman