Disarium numbers: Difference between revisions
Content added Content deleted
(Added FutureBasic solution) |
(add OCaml) |
||
Line 1,294: | Line 1,294: | ||
<pre>0 1 2 3 4 5 6 7 8 9 89 135 175 518 598 1306 1676 2427 2646798</pre> |
<pre>0 1 2 3 4 5 6 7 8 9 89 135 175 518 598 1306 1676 2427 2646798</pre> |
||
=={{header|OCaml}}== |
|||
<syntaxhighlight lang="ocaml">let pow x = |
|||
let rec aux acc b = function |
|||
| 1 -> acc * b |
|||
| 0 -> acc |
|||
| y -> aux (if y land 1 = 0 then acc else acc * b) (b * b) (y lsr 1) |
|||
in |
|||
aux 1 x |
|||
let is_disarium n = |
|||
let rec aux x = |
|||
if x < 10 |
|||
then x, 2 |
|||
else let n, l = aux (x / 10) in n + pow (x mod 10) l, succ l |
|||
in |
|||
n = fst (aux n) |
|||
let () = |
|||
Seq.(ints 0 |> filter is_disarium |> take 19 |> map string_of_int) |
|||
|> List.of_seq |> String.concat " " |> print_endline</syntaxhighlight> |
|||
{{out}} |
|||
<pre>0 1 2 3 4 5 6 7 8 9 89 135 175 518 598 1306 1676 2427 2646798</pre> |
|||
=={{header|Perl}}== |
=={{header|Perl}}== |