/* Ascenting primes (Rosetta code) in Picat. http://rosettacode.org/wiki/Ascenting_primes """ Generate and show all primes with strictly ascending decimal digits. Aside: Try solving without peeking at existing solutions. I had a weird idea for generating a prime sieve faster, which needless to say didn't pan out. The solution may be p(r)etty trivial but generating them quickly is at least mildly interesting. Tip: filtering all 7,027,260 primes below 123,456,789 probably won't kill you, but there is at least one significantly better and much faster way, needing a mere 511 odd/prime tests. """ This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import util. main => go. go => DP = [N : S in power_set("123456789"), S != [], N = S.to_int, prime(N)].sort, foreach({P,I} in zip(DP,1..DP.len)) printf("%9d%s",P,cond(I mod 10 == 0,"\n","")) end, nl, println(len=DP.len), nl.