Last active
May 23, 2019 02:10
-
-
Save cmditch/890eb1498421be8a3ea5a955999e2f70 to your computer and use it in GitHub Desktop.
What I have so far... but doesn't quite work
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Codewars.Kata.SqIntoSq where | |
import Debug.Trace | |
decompose :: Integer -> Maybe [Integer] | |
decompose num = decomposer (num^2) (num-1) | |
decomposer :: Integer -> Integer -> Maybe [Integer] | |
decomposer total num = | |
case (num, squareSum list == total) of | |
(_, True) -> Just list | |
(0, _) -> Nothing | |
(num', False) -> decomposer total (num' - 1) | |
where | |
list = trace (show list') $ list' -- debug help | |
list' = foldr reducer [] [1..num] | |
squareSum = sum . fmap (^2) | |
reducer n acc = | |
if squareSum acc > total then | |
reducer n (tail acc) | |
else | |
n : acc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment