Commits

WANG Yanjin committed dfcba30

solve p32

Comments (0)

Files changed (2)

 
 p31 = count [200, 100, 50, 20, 10, 5, 2, 1] 200
 
+--p32 = sum $ map (\x -> (fst x)*(snd x)) [(x, y) | x <- [10..99], y <- [100..999], isPandigital x y]
+p32 = sum . Set.toList $ Set.fromList [x*y | x <- [1..99], y <- [div 1000 x..div 9999 x], isPandigital x y]
+    where
+        isPandigital :: Int -> Int -> Bool
+        isPandigital x y = (sum (map (length . show) [x, y, z]) == 9) && (Set.fromList (show x ++ show y ++ show z)) == (Set.fromList "123456789")
+            where z = x * y
+
 -- solutions end
 
 
 
     args <- getArgs
     let n = read (args !! 0) :: Int
-        xxx = p31
+        xxx = p32
     print $ xxx
 
     t2 <- getCPUTime
-    putStrLn $ show (div (t2 - t1) (10^9)) ++ " ms"
+    putStrLn $ show (div (t2 - t1) (10^9)) ++ " ms"
                         print(i, j, k)
                         r.append(k)
     sr = set(r)
+    print(sr)
     print(sum(sr))
 
 
     print('Sum: ', _sum)
 
 if __name__ == '__main__':
-	print(p31())
+	print(p32())
 	print("Seconds:", time.clock() - start)