Numbers divisible by their individual digits, but not by the product of their digits.: Difference between revisions

Content added Content deleted
(→‎OCaml: add)
Line 8: Line 8:
=={{header|11l}}==
=={{header|11l}}==
{{trans|Python}}
{{trans|Python}}

<syntaxhighlight lang="11l">F p(n)
<syntaxhighlight lang="11l">F p(n)
‘True if n is divisible by each of its digits,
‘True if n is divisible by each of its digits,
Line 356: Line 355:
<pre>22 33 44 48 55 66 77 88 99 122 124 126 155 162 168 184 222 244 248 264 288 324 333 336 366 396 412 424 444 448 488 515 555
<pre>22 33 44 48 55 66 77 88 99 122 124 126 155 162 168 184 222 244 248 264 288 324 333 336 366 396 412 424 444 448 488 515 555
636 648 666 728 777 784 824 848 864 888 936 999</pre>
636 648 666 728 777 784 824 848 864 888 936 999</pre>
=={{header|Arturo}}==


=={{header|Arturo}}==
<syntaxhighlight lang="rebol">valid?: function [n][
<syntaxhighlight lang="rebol">valid?: function [n][
digs: digits n
digs: digits n
Line 1,279: Line 1,278:
424 444 448 488 515 555 636 648 666
424 444 448 488 515 555 636 648 666
728 777 784 824 848 864 888 936 999</pre>
728 777 784 824 848 864 888 936 999</pre>

=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">let test b x =
let rec loop m n =
if n < b
then x mod n = 0 && x mod (m * n) > 0
else let d = n mod b in d > 0 && x mod d = 0 && loop (m * d) (n / b)
in loop 1 x

let () =
Seq.ints 1 |> Seq.take 999 |> Seq.filter (test 10)
|> Seq.iter (Printf.printf " %u") |> print_newline</syntaxhighlight>
{{out}}
<pre> 22 33 44 48 55 66 77 88 99 122 124 126 155 162 168 184 222 244 248 264 288 324 333 336 366 396 412 424 444 448 488 515 555 636 648 666 728 777 784 824 848 864 888 936 999</pre>


=={{header|Pascal}}==
=={{header|Pascal}}==
Line 1,566: Line 1,579:


=={{header|Quackery}}==
=={{header|Quackery}}==

<syntaxhighlight lang="quackery"> [ dup 0 = iff
<syntaxhighlight lang="quackery"> [ dup 0 = iff
[ 2drop false ] done
[ 2drop false ] done
Line 1,596: Line 1,608:


=={{header|Raku}}==
=={{header|Raku}}==

<syntaxhighlight lang="raku" line>say "{+$_} matching numbers:\n{.batch(10)».fmt('%3d').join: "\n"}" given
<syntaxhighlight lang="raku" line>say "{+$_} matching numbers:\n{.batch(10)».fmt('%3d').join: "\n"}" given
(^1000).grep: -> $n { $n.contains(0) ?? False !! all |($n.comb).map($n %% *), $n % [*] $n.comb };</syntaxhighlight>
(^1000).grep: -> $n { $n.contains(0) ?? False !! all |($n.comb).map($n %% *), $n % [*] $n.comb };</syntaxhighlight>