Permalink
Browse files

solved #26

  • Loading branch information...
1 parent 0329b7f commit 483d82c85cbf95a25cd9742600944d9fec0321b0 Eric Wilson committed Feb 19, 2011
Showing with 22 additions and 0 deletions.
  1. +21 −0 026.hs
  2. +1 −0 README
View
21 026.hs
@@ -0,0 +1,21 @@
+import Data.List
+import Data.Maybe
+
+timesMod :: Int -> Int -> Int -> Int
+timesMod modulus n m = mod (n*m) modulus
+
+remainders :: Int -> [Int]
+remainders denom = iterate (nextRemainder $ denom) 1
+ where nextRemainder denom remain = timesMod denom remain 10
+
+oneCycle :: [Int] -> [Int] -> [Int]
+oneCycle previous (x:xs) =
+ if elem x previous
+ then dropWhile (/=x) previous
+ else oneCycle (previous ++ [x]) xs
+
+euler26 :: Int -> Int
+euler26 n = 1 + (fromJust $ elemIndex (maximum cycles) cycles)
+ where
+ cycles = map digitCycle [1..n]
+ digitCycle n = length $ oneCycle [] (remainders n)
View
1 README
@@ -27,5 +27,6 @@ Here's the current status: (No status listed if no code is checked in.)
#22: SOLVED
#24: SOLVED
#25: SOLVED
+#26: SOLVED
#28: SOLVED
#67: SOLVED

0 comments on commit 483d82c

Please sign in to comment.