Resistance calculator: Difference between revisions

Content added Content deleted
No edit summary
Line 169: Line 169:
@b.setVoltage @voltage
@b.setVoltage @voltage


build = (voltage, s) ->
build = (s) ->
stack = []
stack = []
for word in s.split ' '
for word in s.split ' '
Line 175: Line 175:
else if word == '*' then stack.push new Parallel stack.pop(), stack.pop()
else if word == '*' then stack.push new Parallel stack.pop(), stack.pop()
else stack.push new Resistor parseFloat word
else stack.push new Resistor parseFloat word
node = stack.pop()
stack.pop()
node.setVoltage voltage
node


node = build 18.0, "10 2 + 6 * 8 + 6 * 4 + 8 * 4 + 8 * 6 +"
node = build "10 2 + 6 * 8 + 6 * 4 + 8 * 4 + 8 * 6 +"
node.setVoltage 18.0
print " Ohm Volt Ampere Watt Network tree"
print " Ohm Volt Ampere Watt Network tree"
node.report ""
node.report ""