Primes whose sum of digits is 25: Difference between revisions

Content added Content deleted
(Added Quackery.)
(→‎{{header|Wren}}: Added stretch goal.)
Line 2,196: Line 2,196:


=={{header|Wren}}==
=={{header|Wren}}==
===Basic===
{{libheader|Wren-math}}
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
{{libheader|Wren-fmt}}
{{libheader|Wren-seq}}
{{libheader|Wren-seq}}
Although do-able, the stretch goal would take too long in Wren so I haven't bothered.
<syntaxhighlight lang="ecmascript">import "/math" for Int
<syntaxhighlight lang="ecmascript">import "/math" for Int
import "/fmt" for Fmt
import "/fmt" for Fmt
Line 2,227: Line 2,227:
2,797 2,887 3,499 3,697 3,769 3,877
2,797 2,887 3,499 3,697 3,769 3,877
3,967 4,597 4,759 4,957 4,993
3,967 4,597 4,759 4,957 4,993
</pre>
===Stretch===
{{trans|Go}}
{{libheader|Wren-gmp}}
Run time is about 35.7 seconds.
<syntaxhighlight lang="ecmascript">import "./gmp" for Mpz
import "./fmt" for Fmt

var countAll // recursive
countAll = Fn.new { |p, rem, res|
if (rem == 0) {
var b = p[-1]
if ("1379".contains(b)) {
var z = Mpz.fromStr(p)
if (z.probPrime(15) > 0) res = res + 1
}
} else {
for (i in 1..rem.min(9)) {
res = countAll.call(p + i.toString, rem - i, res)
}
}
return res
}

var n = countAll.call("", 25, 0)
Fmt.print("There are $,d primes whose digits sum to 25 and include no zeros.", n)</syntaxhighlight>

{{out}}
<pre>
There are 1,525,141 primes whose digits sum to 25 and include no zeros.
</pre>
</pre>