Foo
Ruby
code posted
created at 04 May 16:04
Edit
|
Back
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
require("csim") # The circuit here should simulate a level-triggered D flip-flop D = SwitchBank.new C = Pulser.new N = NotGate.new A1, A2 = AndGate.many(2) NR1, NR2 = NorGate.many(2) Q = LED.new(" Q") Qnot = LED.new(" ~Q") D.join(N) N.join(A1) D.join(A2) C.join(A1) C.join(A2) A1.join(NR1) A2.join(NR2) NR1.join(NR2) NR2.join(NR1) LED.shush(true) NR1.join(Q) NR2.join(Qnot) LED.shush(false) vals = [ true, false, false, true, false ] 10.times do 3.times do dval = vals.shift vals.push(dval) print "Input: ", dval, "\n" D.value = dval end print "=== TIC ===\n" C.pulse end |
637 Bytes in 3 ms with coderay