RosettaCodeData/Task/Super-d-numbers/CLU/super-d-numbers.clu
2026-04-30 12:34:36 -04:00

45 lines
1.3 KiB
Text

has_consecutive_digits = proc (number: bigint, digit: int) returns (bool)
own zero: bigint := bigint$i2bi(0)
own ten: bigint := bigint$i2bi(10)
consecutive: int := 0
while number > zero do
d: int := bigint$bi2i(number // ten)
number := number / ten
if d = digit
then consecutive := consecutive + 1
else consecutive := 0
end
if consecutive = digit then
return(true)
end
end
return(false)
end has_consecutive_digits
is_super_d_number = proc (number: bigint, d: int) returns (bool)
big_d: bigint := bigint$i2bi(d)
return(has_consecutive_digits(number ** big_d * big_d, d))
end is_super_d_number
super_d_numbers = iter (d, amount: int) yields (bigint)
own one: bigint := bigint$i2bi(1)
n: bigint := one
while amount > 0 do
while ~is_super_d_number(n, d) do n := n + one end
yield(n)
n := n + one
amount := amount - 1
end
end super_d_numbers
start_up = proc ()
po: stream := stream$primary_output()
for d: int in int$from_to(2, 6) do
stream$putl(po, "First 10 super-" || int$unparse(d) || " numbers:")
for n: bigint in super_d_numbers(d, 10) do
stream$puts(po, int$unparse(bigint$bi2i(n)) || " ")
end
stream$putl(po, "\n")
end
end start_up