# [Community Puzzle] Organic Compounds đź”¬

Coding Games and Programming Challenges to Code Better

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?

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

The very first hydrocarbon has 5 bonds!?!?!?

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â€¦ You`re tottaly correct and I`m 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?

3 Likes

Hey,
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
And if ever you get the 100%, Iâ€™d be curious on how you wrote your program!

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 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.

Hello,
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!

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.

and

In carbon units, 0â‰¤nâ‰¤4
In bonds, 0<mâ‰¤4

1 Like