Numbers with prime digits whose sum is 13: Difference between revisions

(→‎Python: add)
(→‎OCaml: add)
Line 1,303:
23323 23332 25222 32233 32323 32332 33223 33232 33322
52222 222223 222232 222322 223222 232222 322222 </pre>
 
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">let seq_prime_digits_13 =
let digits = [2; 3; 5; 7] in
let rec loop ds cs ns () =
match cs with
| [] -> if ns = [] then Seq.Nil else loop digits (List.rev ns) [] ()
| (n, r) :: cs' ->
match ds with
| d :: ds' when d < r -> loop ds' cs ((n * 10 + d, r - d) :: ns) ()
| d :: ds' when d = r -> Seq.Cons (n * 10 + d, loop ds' cs ns)
| _ -> loop digits cs' ns ()
in loop digits [0, 13] []
 
let () =
Seq.iter (Printf.printf " %u") seq_prime_digits_13 |> print_newline</syntaxhighlight>
{{out}}
<pre> 337 355 373 535 553 733 2227 2272 2335 2353 2533 2722 3235 3253 3325 3352 3523 3532 5233 5323 5332 7222 22225 22252 22333 22522 23233 23323 23332 25222 32233 32323 32332 33223 33232 33322 52222 222223 222232 222322 223222 232222 322222</pre>
 
=={{header|Pascal}}==
Line 1,870 ⟶ 1,888:
<syntaxhighlight lang="python">src, dst = [(13, 0)], []
while src:
(r, n), *src = src.pop(0)
for d in 2, 3, 5, 7:
if d > r:
559

edits