Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 41 lines (33 sloc) 1.349 kb
30808a3 added function for constant difference diagonals
Eric Wilson authored
1 import Data.List
80bbd4b Refactored 11 to use Io module
Eric Wilson authored
2 import EulerUtil.Io
30808a3 added function for constant difference diagonals
Eric Wilson authored
3
1d645ff Solved #11
Eric Wilson authored
4 findMaxInRow :: (Integral a) => [a] -> a
5 findMaxInRow = head . foldl next [0,0,0,0]
81e0661 added max function
Eric Wilson authored
6 where next (oldMax: old: olds) new = max oldMax (old * new * product olds) : olds ++ [new]
1506143 added constant sum diagonal function
Eric Wilson authored
7
1d645ff Solved #11
Eric Wilson authored
8 findRowMaxInArray :: (Integral a) => [[a]] -> a
9 findRowMaxInArray = maximum . map findMaxInRow
10
11 findMax :: (Integral a) => [[a]] -> a
12 findMax = maximum . map findRowMaxInArray . findArrays
13 where findArrays array = map ($ array) [id, transpose, constSumDiags, constDiffDiags]
1506143 added constant sum diagonal function
Eric Wilson authored
14
15 constSumDiags :: [[a]] -> [[a]]
16 constSumDiags array = map (diagSum array) [0..n]
30808a3 added function for constant difference diagonals
Eric Wilson authored
17 where
18 diagSum (row:rows) idx
19 | idx < 0 = []
20 | idx >= length row = diagSum rows (idx - 1)
21 | otherwise = row !! idx : diagSum rows (idx - 1)
22 diagSum [] _ = []
80bbd4b Refactored 11 to use Io module
Eric Wilson authored
23 n = (length $ head array) + (length array) - 2
30808a3 added function for constant difference diagonals
Eric Wilson authored
24
25 constDiffDiags :: [[a]] -> [[a]]
26 constDiffDiags array = map (diagDiff array) [m..n]
27 where
28 diagDiff (row:rows) idx
29 | idx < 0 = diagDiff rows (idx + 1)
30 | idx >= length row = []
31 | otherwise = row !! idx : diagDiff rows (idx + 1)
32 diagDiff [] _ = []
33 m = ((-1) * length array) + 1
1d645ff Solved #11
Eric Wilson authored
34 n = (length $ head array) - 1
35
80bbd4b Refactored 11 to use Io module
Eric Wilson authored
36 euler11 :: String -> String
37 euler11 = show . findMax . stringToIntArray
38
39 euler11file :: FilePath -> IO()
40 euler11file fileName = applyFunctionToFile fileName euler11
Something went wrong with that request. Please try again.