[Community Puzzle] Organic Compounds 🔬

Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

IN Organic Compounds By CyberLemonade there are 10 completions, but 19 ratings. What algorithm is this? Why more ratings than completions? Thanks.

The author (and may be approvers too) can vote but their submitted solutions are not counted in completion.
People who have partially finished the puzzle can vote and they are obviously not in completion count.

And it’s a caching problem I guess.
There are more than 10 published solutions, the number of solvers is just wrong (not only for that puzzle).

can someone explain why in the fifth test the compound is valid?

(1) (1)
CH0 CH1(1)CH2(1)CH3
(3) (1)

The very first hydrocarbon has 5 bonds!?!?!? :thinking::roll_eyes:

That’s 5 lines of input, not 5 bonds.

The very first carbon CH2(2) has 4 bonds. 2 bonds with 2 individual H and 2 bonds with the neighboring carbon CH0.

All carbons have 4 bonds … unless … we are going into detail that isn’t necessary for solving this problem.

Doesn’t the first bond on line 2 means that there’s a bond between the first HC in line 1 and the first HC in line 3? If it’s so, the first C in line 1 would have 5 Hs (2 from itself, 2 from the next HC on line 1 and 1 from the first HC on line 3).

Sorry, can’t insert an image to explain.

Thank you for the attention.

You might be ignoring empty spaces.

There’s some empty space before the first (1) on line 2 for example. With that the bond ends up right where it belongs.

Bond #1 on line 2 is between CH0 on 1st line and CH0 on line 3.

One detail you might be confused by is the really stupid CH0 notation. It should have been C on its own and not CH0 or CFe0Mg0Cl0H0Al0Na0Se0Si0

So where you see H0 ignore it, it stands for zero hydrogen atoms.

1 Like

Oh, my… Youre tottaly correct and Im an idiot. I was stripping my input lines. I did it in the beginning, before undestanding that spaces are important for the problem.

Again, thank you very much for your help.

Mauro Crispim

Could community puzzles have better descriptions? I am looking at “Organic Compounds” and there’s this note: “To get a better understanding of organic compounds and condensed formulae, look it up on the web.”

Seriously? I have to learn organic chemistry to solve this puzzle?


I’m necroing this but I think it’s justified since you didn’t get any answer.
I was actually looking for topics about “Organic Compounds” as I can’t get the 8th validator passed.
I just wanted to say that no, you don’t have to learn anything more than what’s already in the puzzle rules.
Go on and try! The puzzle is pretty fun once you get a first naive algorithm :slight_smile:
And if ever you get the 100%, I’d be curious on how you wrote your program!

Thanks for the reply.

I solved it. You should be able to see my solution. I don’t remember the details, sorry.

Actually as I am getting all the numbers through a regex, the CH0 notation is really useful for not having a too complex regex. So I like it that way :slight_smile: Furthermore, I think the “real” notation is not the “real” part of the problem here.

Hi all,
I’m having trouble passing the validator 8, “Cyclic Hydrocarbon with substituents”.
I get all the IDE tests right, and I’m clueless about what went wrong in that validator.
Thanks for your help!

I’ve already written in a similar topic → here but it’s a slightly different subject so I create a new topic here.
As I said in the topic linked above, I can’t pass the Validator 8 for the community puzzle “Organic Compounds” (here).
But my solution passes all the IDE tests and I really can’t say what is going wrong with that validator.
Has anyone some ideas?
Thanks! :slight_smile:

EDIT: solved!
The Test 8 was supposed invalid because the bond near CH3 was 2 instead of 1.
I modified my input to write 1 instead of 2 and I was expecting for my program to return “VALID”.
But it did not! It was still writing “INVALID”, which was incorrect.
My error, I think, is pretty specific to my solution, so I guess it will not help many of you, but I can explain a bit. For each molecule, I was looking for a bond at its left, at its right, at its top and at its bottom, and checking that the sum was exactly 4. It turns out, when I was looking for the bottom bond, I sometimes skipped a line! And for that test 8, by chance, it still worked.

I’d like to follow up on Coding Games and Programming Challenges to Code Better

First I had no idea how to solve this puzzle and felt I was missing a key piece of information. Only after reading the other forum comments regarding this puzzle did I learn that the n of a carbon unit and the number of adjacent bonds must equal 4.

Maybe I could have deduced this from the available information (as quotes below) but it would have been a great help for me if this just was just available as a note that n of a carbon unit and the number of adjacent bonds must equal 4.

The inputs given will have a valid representation, but the bonds might not be matching. For example, a carbon unit with n=1 should have 3 adjacent bonds, one with n=2 should have 2 adjacent bonds, etc.


In carbon units, 0≤n≤4
In bonds, 0<m≤4