Rebol3 Code Examplex
Nice primes
Rebol [
title: "Rosetta code: Nice primes"
file: %Nice_primes.r3
url: https://rosettacode.org/wiki/Nice_primes
]
nice-prime?: function/with [
"Returns true if n and its iterated digit-sum are both prime"
n [integer!]
][
all [prime? n prime? sum-digits n]
][
sum-digits: function [n][
s: 0
foreach d (form n) [s: s + (d - #"0")]
either s < 10 [s] [sum-digits s]
]
]
prin "Nice primes between 500 and 1000: "
probe new-line/skip collect [
for n 500 1000 1 [if nice-prime? n [keep n]]
] true 10Output:
Nice primes between 500 and 1000: [
509 547 563 569 587 599 601 617 619 641
653 659 673 677 691 709 727 743 761 797
821 839 853 857 887 907 911 929 941 947
977 983 997
]