Skip to content

Gapful numbers

editable example

Click the pencil to open this in an editor, change it, and run it in your browser. The same solution is posted on Rosetta Code.

ghul
use IO.Std.write_line
use Collections.LIST
use Ghul.Pipes
gapful_from(start: int, wanted: int) -> LIST[int] is
let found = LIST[int]()
let candidate mut = start
while found.count < wanted do
let digits = candidate.to_string()
let first_last = int.parse(
"{digits[0]}{digits[digits.length - 1]}")
if candidate % first_last == 0 then
found.add(candidate)
fi
candidate = candidate + 1
od
found
si
write_line("first 30 gapful numbers:")
write_line(gapful_from(100, 30) |> join(", "))
write_line("first 15 gapful numbers >= 1,000,000:")
write_line(gapful_from(1000000, 15) |> join(", "))
write_line("first 10 gapful numbers >= 1,000,000,000:")
write_line(gapful_from(1000000000, 10) |> join(", "))