Maybe somebody has already thought of this in another thread, but here's my proposal for a Dwarf Fortress calculator: DvE Gates (i.e. "Dwarf vs Elephant") Now, I'm not a CompSci and I'm not a Logician, but with this setup, I think you can recycle your output to become an input in the next calculation.
The basic premise is to open a elephant cage and have an unarmed dwarf walk past the cage to reach the output lever. If the elephant is alive, the dwarf won't make it. If the elephant is killed by drowning or magma -- your preference -- then the dwarf saunters past the elephantine corpse. If you are worried about the possibility of the dwarf getting a lucky shot against the elephant and slaying it, you can increase your confidence level by increasing the number of caged elephants. (Not that I've ever caged an elephant...) The second dwarf's hallway is always flooded to start, as a delaying tactic to let the first dwarf complete his logic tasks.
For all 4 logic gates, the A and B levers are the input. Set the "Pull the Lever" tasks as input, and Dwarf1 ("1") will try to pull them. The A and B levers open/close doors that are either set in parallel, or series. (You could skip the levers and just set the A/B doors as forbidden/open if you want to simplify the set up, or have dwarves from another part of the calculator set the input levers. The "Go" lever releases both Dwarf1 and Dwarf2 from behind their respective doors. Dwarf1 is free to try to reach the C (or E) lever beyond the doors, but is limited by the logic doors, A and B. Dwarf2 is trying to reach the output lever at the bottom right of the calculator by getting past the delay flood and the possible elephant released from its cage ("!").
======================================
For the OR gate, add "Pull the Lever" tasks to A and B per your input, then every other lever gets a "Pull the Lever" task set: Go,C,Z(already pulled once),C2(already pulled once),E
The Go lever opens the doors in front of both Dwarves, releasing them to try to pull all the other levers. Dwarf1 pulls the A and B levers as appropriate, and if either door is opened, Dwarf1 saunters down to lever C to open the floodgate and drown/boil the elephant(s) in the next hallway.
Meanwhile, Dwarf2 pulls the Z lever and waits for the floodgate to close and the floodwaters to recede, which is just a delaying tactic. (Note the judiciously placed channels to keep from drowning/boiling Dwarf2 from either floodgate.) Next Dwarf2 pulls the C2 lever, which closes the first floodgate that Dwarf1 may or may not have opened. Then Dwarf2 pulls the E lever which opens the cage ("!") to a live or dead elephant. If Dwarf2 makes it past the elephant, Dwarf2 pulls the output lever.
OR (kill the E, let D live)
code:
#~####
#~##2#
#~##D(Go)
#~#Zó#
#~##_#
#~~X~#
#~#Z~#
#~##~#
#~##~#
#~##óC2
#~##òE
#~##~#
#~##_#
#A###~X..#
#Go#òD.##C#!E
#1òD.#...ò#.#
####òD.####ò output lever
#B###
A+, B+ ==> A and B doors both open, D1 floods cage from C lever, D2 unfloods cage, opens cage, walks past corpse. Output true.
A+, B- ==> A door opens, D1 floods cage from C lever, D2 unfloods cage, opens cage, walks past corpse. Output true.
A-, B+ ==> B door opens, D1 floods cage from C lever, D2 unfloods cage, opens cage, walks past corpse. Output true.
A-, B- ==> A and B doors closed, elephant cage never flooded, D2 opens cage, D2 is stomped tragically. Output stays false.(Now that I've described it in a simplified(!) manner, there's two pieces tht need to be added. The cage release lever also needs to open a door that allows access to the output lever. Otherwise there's the possibility that D2 will be taskes to Pull the output lever first, before opening the cage. And I think I may need a second unflooding delay. After Dwarf1 completes his logic, he needs to wait for Dwarf2 to pull the output lever or not, and then once enough time has passed, Dwarf1 would pull the "go" lever on the next calculation.)
======================================
Here's the AND gate, same set up, just with the A/B doors in series, not parallel.
AND (kill the E, let D live)
code:
#~####
#~##2#
#~##D(Go)
#~#Zó#
#~##_#
#~~X~#
#~#Z~#
#~##~#
#~##~#
#~##óC2
#~##òE
#~##~#
#~##_#
######~X..#
#Go##A#A##C#!E
#1òD.òòDD.ò#.#
######B#B###ò output lever
A+, B+ ==> A and B doors both open, D1 floods cage from C lever, D2 unfloods cage, opens cage, walks past corpse. Output true.
A+, B- ==> only A door opens, elephant cage never flooded, D2 opens cage, D2 is stomped tragically. Output stays false.
A-, B+ ==> only B door opens, elephant cage never flooded, D2 opens cage, D2 is stomped tragically. Output stays false.
A-, B- ==> neither A/B door opens, elephant cage never flooded, D2 opens cage, D2 is stomped tragically. Output stays false.
======================================
For the NOR and NAND gates, we can skip the elephant flooding and have Dwarf1 try to pull the cage lever ("E") directly. Both dwarves are again released by the "go" lever and Dwarf2 is must wait for the delaying flood to recede after pulling lever Z. Dwarf1 goes through doors A or B, if at all, and tries to release the elephant cage ("!"). Dwarf2 must pull lever C to open Door C to get to the output lever.
NOR (release the E, kill the D)
code:
#~####
#~##2#
#~##D(Go)
#~#Zó#
#~##_#
#~~X~#
###Z~#
#~#
#~#
#~#
#òC
#~#
#_#
#####A### #.#
#Go#òD.##E#!E
#1òD.#...ò#.#
###òD.####DC
##B### #ò# output lever
A+, B+ ==> A and B doors both open, D1 opens cage, D2 is stomped tragically. Output stays false.
A+, B- ==> A door opens, D1 opens cage, D2 is stomped tragically. Output stays false.
A-, B+ ==> B door opens, D1 opens cage, D2 is stomped tragically. Output stays false.
A-, B- ==> neither A/B door opens, elephant cage never opened, D2 walks past cage. Output is true.
======================================
NAND (release the E, kill the D)
code:
#~####
#~##2#
#~##D(Go)
#~#Zó#
#~##_#
#~~X~#
###Z~#
#~#
#~#
#~#
#òC
#~#
#_#
######### #.#
#Go##A#A##E#!E
#1òD.òòDD.ò#.#
#####B#B####DC
###### #ò# output lever
A+, B+ ==> A and B doors both open, D1 opens cage, D2 is stomped tragically. Output stays false.
A+, B- ==> only A door opens, elephant cage never opened, D2 walks past cage. Output is true.
A-, B+ ==> only B door opens, elephant cage never opened, D2 walks past cage. Output is true.
A-, B- ==> neither A/B door opens, elephant cage never opened, D2 walks past cage. Output is true.
======================================
And I guess I ought to mention the NOT gate, because it might be easier to implement a NOT(NOR(A,B)) than an OR(A,B). (I'm sure I messed up the logic syntax, but you get the idea...)
A NOT gate is a corridor with the caged elephant, and no A/B door logic. If cage is opened (input=TRUE), then Dwarf2 dies (output=FALSE).
Ok, now that I've typed all this in. Where did I screw up?
(EDIT: I got the [code] tags in wrong place)
[ January 14, 2007: Message edited by: qwip ]