# [Community Puzzle] if then else

https://www.codingame.com/training/easy/if-then-else

Created by @java_coffee_cup,validated by @never-again,@therealbeef and @MJS.
If you have any issues, feel free to ping them.

Does anyone have a hint on what the Optional S Validator might roughly be doing? I just canâ€™t think of any way how the S can be anything but ignorable noise but apparently, there is some edge case where the S matters (guessing based on the name of the validator).

Just ignore the Ss, really.

1 Like

Great puzzle!! I had a lot of fun solving it.
I think the difficulty level should be set to medium, for me the puzzle was quite difficult compared to other puzzles at the same difficulty level.
Also, the success rates in the community are pretty low which shows that the puzzle is more difficult than the other puzzles at the same difficulty level.

The way I solved the puzzle:
I implemented a tree structure and figured out how to calculate the number of combinations.

2 Likes

Thanks your comments. After many people tried hands on it now it has evidence showing it is relatively more difficult. Iâ€™m not sure is it a good idea to move puzzles around as desired.

Difficulty is in the eye of the beholders.
Before getting enough feedback from the general community, the difficulty level assigned is just an estimate. Sometimes I cannot predict what difficulty can be faced by coders because I already know some solutions and I know the coding part is not difficult.

At the same time, I cannot predict what innovative approaches can be invented by coders. Your â€śTreeâ€ť approach is something I did not think of. Very creative. Well done.

2 Likes

first in rust
i stored all the reserved keyword including the S in a vector.
replace every S by 1.

loop
replace consecutive cells of the form : â€śif x else y endifâ€ť by x+y. and every two consecutive
numbers x, y by one cell : x*y.
break when the length of the vector <= 1
end loop

the length of the vector is the answer

This is another deceptively tricky â€śeasyâ€ť puzzle in that it seems simple at first but the more your think about it you can slip down a path of complexity that makes it seem harder than it actually is. Some of the published solutions are quite complex and I think they have done it the hard way. The best solutions are quite simple and either use recursion or a stack. I started with recursion but started slipping down the complexity rabbit hole. I then stopped and came up with a simple stack solution. Once you see how simple it can be you realize why itâ€™s classified as â€śeasyâ€ť.

1 Like

A good account of your experience, including how to understand â€śSimpleâ€ť and â€śDifficultâ€ť, how to drive into a wrong way and pull back, how to progress to make a much better result.

So we should never laugh at someone who wrote 30 lines in the Descent puzzle but still could not solve it. We were all newbies at some point of time.

1 Like

This puzzle was really interesting, what we use to solve it is categorized as easy and understand what we need to do is easy too. The problem is that even if we understand its structure, it can be tricky to implement a solution if we donâ€™t have the right reasoning! I had less problems to solve some medium problems!
I suppose that it is more medium than easy (as we can see with the success rate) but it was a really good problem! Thanks for it x)

1 Like

Nice puzzle, I came up with a C++ recursive solution that passes all the tests.
But validators 3, 4 and 6 fail and I have to admit I have no idea whyâ€¦
Do you have any clue ?

The very low success rate (2X%) so far indicates that this simple puzzle is not simple to the majority. So I moved it from Easy to Medium.

Having a problem with validator 3? This is the easiest test.

Review your assumptions about statement â€śSâ€ť. Only trust the rules explicitly told in the statement. Keep high alert on any untold â€ścommon senseâ€ť rules which could be false assumptions.