diff --git a/068.hs b/068.hs index 6d7935a..e4fd0d6 100644 --- a/068.hs +++ b/068.hs @@ -29,18 +29,17 @@ import Debug.Trace -- For testing -gonSize = 3 -magic = 9 +-- gonSize = 3 +-- magic = 9 --- gonSize = 5 --- magic = 16 +gonSize = 5 data Choice = Choice [Int] safeIndex s l i = if (length l Bool -testPartialGon c = +testPartialGon :: Int -> Choice -> Bool +testPartialGon magic c = let n = nbChoices c nbLines = if n<2*gonSize then (n-1) `div` 2 else gonSize @@ -82,31 +81,28 @@ testLine c val n = in (==val) . sum . map (at c) $ line -allTests :: [Choice] -allTests = testWith (Choice []) (Choice [1..2*gonSize]) +allTests :: [(Int,Choice)] +allTests = concatMap (\s -> testWith s (Choice []) (Choice [n,n-1..1]) ) [6..3*((gonSize*2)-1)] + where + n=2*gonSize -testWith :: Choice -- choosen +testWith :: Int -- Sum to verify + -> Choice -- choosen -> Choice -- left choices - -> [Choice] -- successful choices -testWith c lc = - if testPartialGon c + -> [(Int,Choice)] -- successful choices +testWith magic c lc = + if testPartialGon magic c then if nbChoices lc == 0 - then [c] + then [(magic,c)] else concat $ loop newTest lc else [] where len = nbChoices c newTest x = if len>=3 && (len `rem` 2 == 1) && x