Primes whose sum of digits is 25: Difference between revisions
Content added Content deleted
(Added Wren) |
|||
Line 357: | Line 357: | ||
time = 30 mins |
time = 30 mins |
||
done... |
done... |
||
</pre> |
|||
=={{header|Wren}}== |
|||
{{libheader|Wren-math}} |
|||
{{libheader|Wren-fmt}} |
|||
{{libheader|Wren-fmt}} |
|||
Although do-able, the stretch goal would take too long in Wren so I haven't bothered. |
|||
<lang ecmascript>import "/math" for Int |
|||
import "/fmt" for Fmt |
|||
import "/seq" for Lst |
|||
var sumDigits = Fn.new { |n| |
|||
var sum = 0 |
|||
while (n > 0) { |
|||
sum = sum + (n % 10) |
|||
n = (n/10).floor |
|||
} |
|||
return sum |
|||
} |
|||
var primes = Int.primeSieve(4999).where { |p| p >= 997 } |
|||
var primes25 = [] |
|||
for (p in primes) { |
|||
if (sumDigits.call(p) == 25) primes25.add(p) |
|||
} |
|||
System.print("The %(primes25.count) primes under 5,000 whose digits sum to 25 are:") |
|||
for (chunk in Lst.chunks(primes25, 6)) Fmt.print("$,6d", chunk)</lang> |
|||
{{out}} |
|||
<pre> |
|||
The 17 primes under 5,000 whose digits sum to 25 are: |
|||
997 1,699 1,789 1,879 1,987 2,689 |
|||
2,797 2,887 3,499 3,697 3,769 3,877 |
|||
3,967 4,597 4,759 4,957 4,993 |
|||
</pre> |
</pre> |