RosettaCodeData/Task/Increasing-gaps-between-consecutive-Niven-numbers/BASIC256/increasing-gaps-between-consecutive-niven-numbers.basic
2023-07-01 13:44:08 -04:00

38 lines
820 B
Text

function digit_sum(n, sum)
# devuelve la suma de los dígitos de n dada la suma de los dígitos de n - 1
sum ++
while (n > 0 and n mod 10 = 0)
sum -= 9
n = int(n / 10)
end while
return sum
end function
function divisible(n, d)
if ((d mod 1) = 0) and ((n mod 1) = 1) then
return 0
end if
return (n mod d = 0)
end function
global sum
sum = 0
gap = 0 : niven = 0 : niven_index = 0
gap_index = 0
previous = 1
print "Gap index Gap Niven index Niven number"
print "--------- --- ----------- ------------"
for niven = 1 to 1000000
sum = digit_sum(niven, sum)
if divisible(niven, sum) then
if (niven > previous + gap) then
gap_index += 1
gap = niven - previous
print gap_index, gap, niven_index, previous
end if
previous = niven
niven_index ++
end if
next niven
end