
Hey everyone, Let me know if this is not the right place for this, but I am curious if someone could take a look at my code and maybe share some feedback / how a more experienced haskeller would approach this problem. New to Haskell, pretty experienced with imperative languages. I have solved the following problem in Haskell:
Given a non-empty array, return true if there is a place to split the array so that the sum of the numbers on one side is equal to the sum of the numbers on the other side.
canBalance([1, 1, 1, 2, 1]) -> true canBalance([2, 1, 1, 2, 1]) -> false canBalance([10, 10]) -> true
Here is my code (my solution uses `can_split_even` not `canBalance`) ``` can_split_even :: (Num a) => (Eq a) => [a] -> Bool can_split_even xs = True `elem` is_even_at_each_spot where is_even_at_each_spot :: [Bool] is_even_at_each_spot = map (is_split xs) [1 .. (length xs - 1)] where is_split :: (Num a) => (Eq a) => [a] -> Int -> Bool is_split xs index = sum (take index xs) == sum (drop index xs) ``` Thanks so much! -- Jake Vossen Colorado School of Mines, Class of 2022 B.S. Computer Science PGP: 08CD 67DA FE3A 0AE7 B946 6AC3 B812 7052 D9E3 817B https://jake.vossen.dev