Ad
  • Custom User Avatar

    If your representation means that a and b are encoded as the same thing, that means you need to change your representation!

    It seems that you're representing trees as nested parentheses, where something like (()()) might represent a tree with two subtrees, each represented by (). But that's not necessarily a good representation: don't tie yourself to the notion that the string of parentheses has to look anything like the tree it represents.

    I'm not sure how much I can say as a hint without giving away an answer, but maybe this might help. The four simplest strings of parens I can think of are the following:

    ""
    "()"
    "()()"
    "(())"
    

    Whatever mapping you choose, these will have to map to unique and distinct trees. Why not pick the four simplest possible trees, and see if you can spot a pattern?

  • Custom User Avatar

    I have the same problem.
    With the condition that "" is a valid tree, I decide to make it a minimal tree (so that this definition would work recursively.)
    This has a problem, because that means the tree

    a = Leaf :*: (Leaf :*: Leaf)
    b = (Leaf :*: Leaf) :*: Leaf
    

    are both represented by:

    a' = (()) -- a tree with one subtree
    b' = (())
    a' == b' = True
    

    If I choose "" to represent Leaf, information are lost: I can no longer tell whether a subtree is on the left or on the right if there's only one subtree.

    What could be a better way to model trees?
    Thank you.

  • Custom User Avatar
  • Custom User Avatar

    Got the same problem in Haskell with a different case.

    Falsifiable (after 18 tests):
      (17,457,139242075232141312)
    expected: (97932708193302048,3,5)
     but got: (97932708193302041,3,5)
    
  • Custom User Avatar

    Ok. There are 20 users that solved the kata in Haskell.
    I've seen another issue that akar-O raised for the Haskell version. Let me check if we can solve it.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Hi @casual dingbat. Which language?

  • Default User Avatar

    yeah i didn't understand what bang meant

  • Custom User Avatar

    There's no reason that "()" has to represent a Leaf. You can decide on your own mapping when answering the question, as long as it forms a bijection any mapping is valid. I think most representations would have "" represent a Leaf, and "()" might represent something like Leaf :*: Leaf.

  • Custom User Avatar

    Oh ok... Well that's an issue... Can you post your code with a spoiler flag? I couldnĀ“t get similar messages with mine.

  • Custom User Avatar

    I don't know if it's a real problem with the tests. Apparently they fail because ghc expects your function to return an Integer but it returns an Int. Try to fix that.

  • Custom User Avatar

    Hi. Please say which language and provide an example of test log. See here how to format your post: https://docs.codewars.com/references/markdown/#code-block