Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
If your representation means that
a
andb
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?
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
are both represented by:
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.
Fixed
Got the same problem in Haskell with a different case.
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.
This comment is hidden because it contains spoiler information about the solution
Hi @casual dingbat. Which language?
yeah i didn't understand what bang meant
There's no reason that
"()"
has to represent aLeaf
. 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 aLeaf
, and"()"
might represent something likeLeaf :*: Leaf
.Oh ok... Well that's an issue... Can you post your code with a spoiler flag? I couldnĀ“t get similar messages with mine.
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.
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