Commits

WANG Yanjin committed 5fe9da0

try p38

Comments (0)

Files changed (2)

 import System.Environment (getArgs)
 import System.CPUTime (getCPUTime)
 
-import Data.List (iterate, concat, all, maximum, nub, group, subsequences, maximumBy, elemIndex, tails, transpose, sort, null, inits)
+import Data.List (iterate, concat, all, maximum, nub, group, subsequences, permutations, maximumBy, elemIndex, tails, transpose, sort, null, inits)
 import Data.Char (digitToInt, ord, intToDigit)
 import Data.Bits (testBit, shiftR)
 
         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]
+    where
+        perms n xs = trace (show n) $ 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
 -- solutions end
 
 
 
     args <- getArgs
     let n = read (args !! 0) :: Int
-        xxx = p37
+        xxx = p38
     print $ xxx
 
     t2 <- getCPUTime
     print('Sum: ', _sum)
 
 if __name__ == '__main__':
-	print(p37())
+	print(p38())
 	print("Seconds:", time.clock() - start)