Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

refactored.

  • Loading branch information...
commit d4612d6e1e0eba539a1445d4340ec473b86a0c70 1 parent 53a6955
Eric Wilson authored
Showing with 7 additions and 12 deletions.
  1. +1 −6 021.hs
  2. +6 −6 022.hs
View
7 021.hs
@@ -1,9 +1,4 @@
-properDivPairs :: (Integral a) => a -> [(a,a)]
-properDivPairs n = takeWhile (\(a, b) -> a <= b) [ (d, quot n d) | d <- [1..quot n 2], mod n d == 0 ]
-
-d :: (Integral a) => a -> a
-d n = divisorSum n - n
- where divisorSum = sum . map (uncurry (+)) . properDivPairs
+import EulerMath.Divisors
hasAmicablePair :: (Integral a) => a -> Bool
hasAmicablePair n = d dn == n && n /= dn
View
12 022.hs
@@ -8,12 +8,6 @@ inputToSortedList = sort . splitOn ','
score :: String -> Int
score = sum . map letToInt
-letToInt :: Char -> Int
-letToInt c =
- if isLetter c
- then ord c - ord 'A' + 1
- else 0
-
weightScores :: [Int] -> Int
weightScores = sum . zipWith (*) [1..]
@@ -23,6 +17,12 @@ euler22 = show . weightScores . map score . inputToSortedList
euler22file :: FilePath -> IO()
euler22file fileName = applyFunctionToFile fileName euler22
+letToInt :: Char -> Int
+letToInt c =
+ if isLetter c
+ then ord c - ord 'A' + 1
+ else 0
+
splitOn :: Char -> String -> [String]
splitOn _ [] = []
splitOn c (s:ss)
Please sign in to comment.
Something went wrong with that request. Please try again.