[Community Puzzle] Equivalent Resistance, Circuit Building

I enjoyed this a lot. Thanks for creating this puzzle.

Understanding parsing and stacks can help here, but I solved it without the use of stacks and no recursion either. I used regular expressions for help with parsing and start from within and replace my way out. This might be a hint for someone less experienced.

It might be in the harder end of easy if not familiar with text parsing.

1 Like

well it s kinda difficult

I’m surprised so many people claim they wouldn’t think of using recursion for this one, or wouldn’t know how to do it using recursion; it was literally the first thing I thought of. Make a function that calculates series resistance and one that calculates parallel resistance; have them call each other when they encounter a “(” resp. “[”. Works well except for validator 3 (Combined Validator) for some reason which I obviously can’t find without knowing the validator’s input.

Generally it’s a fine puzzle, but I agree with those who say it needs more tests. It can’t be the goal having all test pass just to fail a single validator. Very frustrating.

Validator 3 has input similar to this:

3
D 32
E 20
F 48
[ [ F E ] ( F D ) ]

You can try it as a custom test case.
Expected answer is 12

2 Likes

That helped find my problem, many thanks!

Yes, it might be good to add a test like this. :sweat_smile:

That’s just what I did to have a 207 characters-long solution in less than 30 minutes…
So I wouldn’t consider it as a “hard” problem :smiley:

Gosh, thank you so much

Thank you for this approach with the stacks. I think it would had taken me years to resolve this puzzle without your suggestion ! :slight_smile:

1 Like

Okay I know this website is pretty snobby when it comes to solutions but seriously how do I solve this efficiently?

I have tried to iterate through the string and adding up the sum of the elements as they appear in their encapsulated parentheses or brackets. Whoever i get stuck on the logic here and limitations of a linear iteration. Same problem with stack.
Any hints or suggestions?

Not sure how you get the impression of this website of being snobby, while many have offered help nicely in the previous posts in this thread.
And about the hints or suggestions for you: read the previous posts, and some of the ideas in those posts can be implemented in a linear iteration.

3 Likes

The validators are really well done, covering all sorts of circuits. Hard to find out a working solution, i must admitt, but well done ! I may have put a “more complex validator” like example in test case, but anyway, forum and chat helped me. Thanks !

This task really not hard if you choose right tools. I did it in simple cycle with primitive parsing and no stacks. Solving one small part and returning the rest of equation until one value remains. Not optimal solution, but works.

Thank you for the validators. I failed the last one because I assumed the names would only contain capital letters.

Nice puzzle!
It is interesting that in clojure, () is list and [] is vector, I can use a protocol to dispatch a recursive function. no need to use regex or searching/matching string. :wink:

Hello 5DN1L (or anyone else),
Would mind telling me how I failed validator 2 but not anything else? I was failing 2, 3, and 4 but after a bit of testing I got 3 and 4 right but somehow not 2. Equivalent resistance - Pastebin.com

Rounding issue. The unrounded answer is x.x5 so the final answer should be rounded up, but your final answer does not round it up.

1 Like

I feel like the puzzle should mention if we should round up or down when it’s at x.x5
Anyway thanks.

This was a very nice puzzle !

I solved it using regex, each “pass” looking for something to compute until the solution appears.

Im having dificulty only on test case 4 “Complex” Ive tried solving it by hand and still cant get the expected result.
My code and my solution by handf give me the answer of 8.1 but the game expect a 2.4, can someone please help me find whats wrong?

{‘Alfa’: 1.0, ‘Bravo’: 1.0, ‘Charlie’: 12.0, ‘Delta’: 4.0, ‘Echo’: 2.0, ‘Foxtrot’: 10.0, ‘Golf’: 8.0}
( Alfa [ Charlie Delta ( Bravo [ Echo ( Foxtrot Golf ) ] ) ] )
( 1 [ 12 4 ( 1 [ 2 ( 10 8 ) ] ) ] )
( 1 [ 12 4 ( 1 [ 2 18 ] ) ] )
( 1 [ 12 4 ( 1 1.8 ) ] )
( 1 [ 12 4 2.8 ] )
( 1 7.15 )
8.15

I think the problem is when you transform [12 4 2.8] in 7.15. The result should be less than 2.8.