https://www.codingame.com/training/easy/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.
https://www.codingame.com/training/easy/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.
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
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 ) 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.
Thanks,
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.ā.
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.
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
else
return math.floor(number * 10)/10
end
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.