Created
June 11, 2011 04:57
-
-
Save nagat01/1020265 to your computer and use it in GitHub Desktop.
F#: generate all emirp number which digits form descent order
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (* | |
| F# solution of below URL | |
| http://gushwell.ifdef.jp/etude/RisingEmirp.html | |
| *) | |
| let isPrime n = | |
| seq{yield 2;yield![3..2..int<<sqrt<|float n]} | |
| |> Seq.forall(fun d->n%d<>0) | |
| let rec revds a n= if n=0 then a else revds(a*10+n%10)(n/10) | |
| let upNums = List.fold(fun ns d->List.collect(fun n->[n;n*10+d])ns)[0][1..9] | |
| let upEmirp = upNums |> List.filter(fun n-> n>9 && isPrime n && isPrime<|revds 0 n) |> List.sort | |
| upEmirp |> List.iter(printfn"%d") | |
| Console.ReadKey()|>ignore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment