15
1
Kirchhoff's law says that when you sum up all the currents (positive for the currents going to a junction, and negative for current leaving a junction), you will always get as result 0.
Look at the following diagram:
Using Kirchhoff's law, you can see that i1 + i4 - i2 - i3 = 0, so i1 + i4 = i2 + i3.
Given two lists, one with all the currents entering the junction and one with all the currents leaving the junction except one, output the last one.
Testcases:
[1, 2, 3], [1, 2] = 3
[4, 5, 6], [7, 8] = 0
[5, 7, 3, 4, 5, 2], [8, 4, 5, 2, 1] = 6
The second list always has one item less than the first list. The output cannot be negative. Smallest program wins.
1The puzzle would have been better if you actual gave resistor and current values. This Q seems like you have introduced the law just as a namesake. (The Q could have easily been stated without the law) – ghosts_in_the_code – 2016-02-07T11:51:49.917
5Kirchoff's current law – Luis Mendo – 2016-02-07T13:35:03.800
Related. – Stewie Griffin – 2016-02-08T08:07:08.440
Can you specify is we can just create a function that returns the result or actually print/return the result. – tpvasconcelos – 2017-05-03T17:43:19.377