-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheuler041.hs
27 lines (24 loc) · 861 Bytes
/
euler041.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
-- We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once. For example, 2143 is a 4-digit pandigital and is also prime.
--
-- What is the largest n-digit pandigital prime that exists?
import Data.List
import Prime
main :: IO ()
main = print answer
-- Pull out the largest prime; I think that the last will always be the largest, but you could do maximum
-- if I am wrong here
answer :: Integer
answer = last perms
-- Go through all the permutations of all lists of numbers [1..n] where n is prime and > 2
-- pull out the prime permutations
-- Slow but tolerable, just
perms :: [Integer]
perms =
[c | a <- ['3','5'..'9']
, b <- permute ['1'..a]
, let c = read b::Integer
, prime c
]
where
permute "" = [""]
permute str = [(x:xs)| x <- str, xs <- permute (delete x str)]