-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathp032.hs
More file actions
27 lines (21 loc) · 715 Bytes
/
p032.hs
File metadata and controls
27 lines (21 loc) · 715 Bytes
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
{-
- Solution to Project Euler problem 32
- Copyright (c) Project Nayuki. All rights reserved.
-
- https://www.nayuki.io/page/project-euler-solutions
- https://github.com/nayuki/Project-Euler-solutions
-}
import Data.List (sort)
import qualified EulerLib
main = putStrLn (show ans)
ans = sum [n | n <- [1..9999], hasPandigitalProduct n]
hasPandigitalProduct :: Int -> Bool
hasPandigitalProduct n = or [pandigital ((digits n) ++ (digits i) ++ (digits (div n i)))
| i <- [1..(EulerLib.sqrt n)+1], mod n i == 0]
digits :: Int -> [Int]
digits 0 = [0]
digits n = digits' n where
digits' 0 = []
digits' n = (digits' (div n 10)) ++ [mod n 10]
pandigital :: [Int] -> Bool
pandigital d = (sort d) == [1..9]