1. WANG Yanjin
  2. euler.py

Commits

WANG Yanjin  committed b0e9a2b

rough p38 solution

  • Participants
  • Parent commits 5fe9da0
  • Branches default

Comments (0)

Files changed (1)

File euler.hs

View file
         isPrimeR n = all isPrime (map (\y -> read y :: Int) (init $ tails (show n)))
         isPrimeL n = all isPrime (map (\y -> read y :: Int) (tail $ inits (show n)))
 
-p38 = map (\y -> perms y "123456789") [9,8..1] --, isPand x]
+p38 = head $ [x | x <- (concatMap (\y -> perms y "123456789") [9,8..1]), isPand x]
     where
-        perms n xs = trace (show n) $ reverse . sort $ concatMap permutations (filter (\y -> length y == n) (subsequences xs))
+        perms n xs = reverse . sort $ concatMap permutations (filter (\y -> length y == n) (subsequences xs))
         mt x = takeWhile (\sx -> (not (elem '0' sx)) && (Set.size (Set.fromList sx) == length sx)) [show (x*n) | n <- [1..9]]
         isOk s = (length s == 9) && (Set.fromList s == Set.fromList "123456789")
         isPand x = (length mtx > 1) && (any (\n -> isOk (concat (take n mtx))) [2..length mtx])
             where
-                mtx = mt x
+                mtx = mt (read x :: Int)
 -- solutions end