1. WANG Yanjin
  2. euler.py

Commits

WANG Yanjin  committed b804a3b

solve p35

  • Participants
  • Parent commits 221e419
  • Branches default

Comments (0)

Files changed (2)

File euler.hs

View file
  • Ignore whitespace
         pall = map (\n -> (n, product [1..n])) [0..9]
         isCurious x = (sum . (map (\n -> Maybe.fromJust (lookup n pall))) $ numsOfInteger x) == x
 
+p35 = length $ [x | x <- p1m, isCircular x]
+    where
+        p1m = takeWhile (<1000000) primesSA
+        circulars :: Int -> [Int]
+        circulars n = take (length (show n)) (iterate (\y -> read (tail (show y) ++ [head (show y)]) :: Int) n)
+        isCircular :: Int -> Bool
+        isCircular 2 = True
+        isCircular 5 = True
+        isCircular n | any (\c -> elem c "024568") (show n) = False
+                     | otherwise = all (\p -> elem p p1m) (circulars n)
+
 -- solutions end
 
 
 
     args <- getArgs
     let n = read (args !! 0) :: Int
-        xxx = p34
+        xxx = p35
     print $ xxx
 
     t2 <- getCPUTime

File euler.py

View file
  • Ignore whitespace
     print('Sum: ', _sum)
 
 if __name__ == '__main__':
-	print(p34())
+	print(p35())
 	print("Seconds:", time.clock() - start)