Jump to content

Gapful numbers: Difference between revisions

add OCaml
(add OCaml)
Line 2,418:
First 10 gapful numbers ⩾ 1000000000:
1000000000 1000000001 1000000005 1000000008 1000000010 1000000016 1000000020 1000000027 1000000030 1000000032</pre>
 
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">let rec first_digit x =
if x < 10 then x else first_digit (x / 10)
 
let is_gapful x =
x mod (10 * first_digit x + x mod 10) = 0
 
let fmt_seq x n =
Seq.(ints x |> filter is_gapful |> take n |> map string_of_int)
|> List.of_seq |> String.concat ", "
 
let () =
let fmt (x, n) =
Printf.printf "\nFirst %u gapful numbers from %u:\n%s\n" n x (fmt_seq x n)
in
List.iter fmt [100, 30; 1000000, 15; 1000000000, 10]</syntaxhighlight>
{{out}}
<pre>
First 30 gapful numbers from 100:
100, 105, 108, 110, 120, 121, 130, 132, 135, 140, 143, 150, 154, 160, 165, 170, 176, 180, 187, 190, 192, 195, 198, 200, 220, 225, 231, 240, 242, 253
 
First 15 gapful numbers from 1000000:
1000000, 1000005, 1000008, 1000010, 1000016, 1000020, 1000021, 1000030, 1000032, 1000034, 1000035, 1000040, 1000050, 1000060, 1000065
 
First 10 gapful numbers from 1000000000:
1000000000, 1000000001, 1000000005, 1000000008, 1000000010, 1000000016, 1000000020, 1000000027, 1000000030, 1000000032
</pre>
 
=={{header|Pascal}}==
559

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.