Commits

WANG Yanjin committed 221e419

solve p34

Comments (0)

Files changed (2)

 import Data.Time.Calendar (Day, addDays, fromGregorian, diffDays, toGregorian)
 import Data.Time.Calendar.WeekDate (toWeekDate)
 
---import Data.Map (Map, fromList, insert, findWithDefault)
---import qualified Data.Map as M
+import Data.Map (Map) -- fromList, insert, findWithDefault)
+import qualified Data.Map as Map
 
 import Data.Set (Set, (\\), size)
 import qualified Data.Set as Set
 
+import qualified Data.Maybe as Maybe
+
 import Control.Applicative ((<*>), (<$>))
 
 import Debug.Trace (trace)
     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 )
+        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
 
+p34 = sum [x | x <- [10..mx], isCurious x]
+    where
+        mx = product [1..9] * 7
+        pall = map (\n -> (n, product [1..n])) [0..9]
+        isCurious x = (sum . (map (\n -> Maybe.fromJust (lookup n pall))) $ numsOfInteger x) == x
 
 -- solutions end
 
 
     args <- getArgs
     let n = read (args !! 0) :: Int
-        xxx = p33
+        xxx = p34
     print $ xxx
 
     t2 <- getCPUTime
     print('Sum: ', _sum)
 
 if __name__ == '__main__':
-	print(p33())
+	print(p34())
 	print("Seconds:", time.clock() - start)