Commits

WANG Yanjin committed a5c1c06

solve p33

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
 
+p33 :: Int
+p33 = snd $ foldr (\x y -> lct ((fst x)*(fst y)) ((snd x)*(snd y))) (1,1) [(x, y) | x <- [10..98], y <- [x+1..99], isCurious x y]
+    where
+        lct m n = ((div m (gcd n m)), (div n (gcd n m)))
+        isCurious :: Int -> Int -> Bool
+        isCurious x y = mx == dy && (lct dx my == lct x y )
+            where
+                mx = mod x 10
+                dx = div x 10
+                my = mod y 10
+                dy = div y 10
+
+
 -- solutions end
 
 
 
     args <- getArgs
     let n = read (args !! 0) :: Int
-        xxx = p32
+        xxx = p33
     print $ xxx
 
     t2 <- getCPUTime
     print('Sum: ', _sum)
 
 if __name__ == '__main__':
-	print(p32())
+	print(p33())
 	print("Seconds:", time.clock() - start)