[Community Puzzle] Equivalent Resistance, Circuit Building


Send your feedback or ask for help here!

Created by @anon79121980,validated by @luke-guyton,@Djoums and @stephan2342.
If you have any issues, feel free to ping them.

FWIW, I wouldn’t consider this an easy problem (and I just finished my first ‘very difficult’ problem). Perhaps I’m just not good at parsing, but this has a tedious number of special cases to handle


It’s an easy problem.
The parsing is not hard (just check matching brackets) and I did not find special cases.

1 Like

It’s not that hard if you’re familiar with stacks.

You can use an explicit stack or do it recursively to let the execution stack do the work for you.


I passed all the tests in IDE but got 83% when I submitted my solution. I cannot think of any reason why my solution would fail on 5 pointed star validator. Any hints?


I don’t know.
Maybe your rounding method is false?

whenever you see a balanced expression you must use a stack.
include the parenthesis in the stack…
and believe me, you will spend less time figuring it by yourself than trying to find a solution on github

1 Like

I tend to agree with you, it is not an easy parsing. After more than 10h, I give up.


If you can’t figure out how to use a stack here, here’s an other way :
define the sum function and the inverse of sum of inverses function, substituate the ( and [ in the input string with the names of the corresponding functions and abuse the eval function.


I’m with you, alchemsti. This one is pretty advanced for Easy. I found it challenging. The parsing required is not trivial. Also, my personal inclination is also to promote out of Easy any puzzles that won’t submit simply to a non-recursive solution. Our aces (looking at you, nicola :stuck_out_tongue:) have it well in hand, but recursion can be a tricky concept for beginners.


This was never intended to be a recursive problem. I would have tagged it “recursion” if it were. Perhaps my somewhat limited experience with computer science and data structure theory led me to not see the recursive solution to the problem (which I am not fully certain how that would even work).

In regards to the parsing component of the problem, I am a bit confused, is the issue with having to replace the names of resistors with values or is it the bracketed circuit statement? Either way I can’t really figure out what is difficult about the parsing here, its quite straightforward.

Just an FYI, before approval it was discussed whether this would be easy or medium and the agreement was that it should be easy. Just to reiterate, this does not require recursion and was not meant to be solved recursively when I made this puzzle.

SUBMIT says:
“The following validators differ from the puzzle test cases to prevent hard coded solutions. This is why you can have some fails here even if all of the tests provided in the IDE have been successfully passed.”

it’s only in SUBMIT Test 04 Complex.

But in my code there is no hard link to something there. My code is universal!

I made a guess
that the following syntax was used in the secret test:
( a [ b ] )
And my test passed in SUBMIT successfully!

The question is closed, thanks for your attention.


That hypotheses helped me a lot!
Like other players, I had the 83% success after submission (04 - Complex Validator : KO).
If I may add a complementary hint, I would say :
“Focus on opening and closing parenthesis/brackets while solving sub circuits.”.

1 Like

I’m sorry but I don’t quite understand your hint. What do you mean by “opening and closing brackets”? I failed at the More Complex Validator, despite passing all the test.

For the context, I use an approach where I calculate the lowest sub circuits first, then move on to the upper circuit. e.g. in the example, I use regex to find a sub circuit, I calculate the value, then I replace the sub circuit in the main circuit with its representation.
From this [ ( A B ) [ C A ] ] to [ AB [ C A ] ] then [ AB CA ] and finally ABCA.
So at the end of the code I just need to log the resistor[ABCA] to the console.

( A B ) and [ A B ] are not the same.

1 Like

Indeed they’re not.

As I understand your approach, I think you are right.
You can solve this puzzle using a loop in which, you reduce the circuit’s complexity, sub-circuit after sub-circuit.
The intent of my hint is to remind you to focus on both opening bracket “[” and closing bracket “]” when you reduce a sub-circuit (same with parenthesis).
Have you tried solving this puzzle in a more verbal way, without regex as they can be slightly tricky sometimes.


I kept getting 100% from test cases, but I kept failing one of the validators. It seems that I’m not the only one who had this problem. Because it’s a validator I had no way of debugging. Maybe it might be a good idea to add more Test cases if possible that cover more potential problems.

Though my problem was in my round function, previously it looked something like this:

    if number - math.floor(number) >= 0.5 then
        return math.ceil(number * 10)/10 
        return math.floor(number * 10)/10

In the case of number being 0.05:
0.05 - 0 >= 0.5 (false)

This would make it round down, rather then up.

If you’re struggling I would recommend checking your round function for a similar problem.

1 Like