Ad
  • Custom User Avatar

    Hi, I'm the original author of this Kata (Ruby version). Author of the haskell version didn't understand this Kata properly, and indeed added a DFS version instead of BFS.

    I have learned haskell to fix this. I added a BFS solution and a correct buildTree (thanks to @nickie for providing one). Please take a look again.

    Thanks,
    Karol

  • Custom User Avatar

    Your partials array is getting reconstructed and destroyed every time the last case of explosiveSum' is reached. Move partials and explosiveSum' into the where clause of explosiveSum, so partials will only be created once.

  • Default User Avatar

    Are you keeping a map of partial solutions?

  • Default User Avatar

    For clarity in dicussion. The following is the list in, the tree created, and the tree by levels result. Either buildTree needs to be fixed or the expectation that treeByLevels is the inverse of buildTree needs to change.

    testIn = [2, 8, 9, 1, 3, 4, 5] -- becomes the following tree
    testTree = Just (TreeNode (Just (TreeNode (Just (TreeNode Nothing Nothing 9))
                                              (Just (TreeNode Nothing Nothing 1)) 8))
                              (Just (TreeNode (Just (TreeNode Nothing Nothing 4))
                                              (Just (TreeNode Nothing Nothing 5)) 3)) 2)
    -- which, by levels is
    byLevelsResult = [2,8,3,9,1,4,5]