Good idea. I've made another branch off my user page:
http://dwarffortresswiki.org/index.php/User:Larix/MPL/6I fiddled with the possibilities. I'm not sure using this logic to power your RAM would be a good idea:
This is a read-/writeable one-bit memory cell under this logic. The basic interactions just don't lend themselves to this application; it can be done, but it's hilariously overcomplicated.
The cart in the northeast is pushed south to read the state of the memory without changing it. It is pushed straight west to set memory to one, and pushed north to set memory to zero. In order to set the cell to zero, it must _first_ be set to one - setting to zero if already zero otherwise bugs up.
On the other hand, binary incrementers built under this logic are easy to build and fast (recovery time of 45 steps when switching to "one", just under sixty when switching to "zero". Counter loops are similarly easy to build, although not as fast (~130 steps per iteration reliably). To demonstrate, i built a bunch of connected loops and a stack of twenty incrementers. The construction can trivially multiply several numbers. It's not a real option for multiplication, since it works by incrementation, making it abysmally slow; in addition, "setting" it to a specific value is insanely complicated, i just went and etched the desired factors into the stone - i.e. i _built_ the desired calculation. To get different factors, it would be necessary to dig some new holes and erase/engrave a few track bits. Since the calculation performs at ~2600 per year (a calculation with a result of 2600 takes a year to finish; one for 1 000 000 takes 400 years), the time spent "entering" the equation is not a real factor, though.
Video of the machine in action:
http://mkv25.net/dfma/movie-2663-multiplicationbyloopedincrementI calculated 1x1x1x1x2x3x4x5x6x7 with it, i.e. the result was 7!, but it wasn't actually programmed as a factorial. It takes ten factors ranging to eleven each (a zero _does_ give the proper zero product, unneeded factors must be set to one), the actual product is the numbers of turns carts took through the last-factor loop; for display, that loop is connected to the incrementer. It calculated the number correctly, but of course i had mis-engraved a single tile, so there was a little mess at the end; fortunately, it was salvageable and the fixed machine calculated 6x7 and then stopped properly.
To calculate 7!, it took 21 months game-time.
It's not really a calculator, but could probably be used to control program loops and branches.
Optimisation update: i got the loop to a minimum return time of precisely 100 steps (if loaded with same-weight carts) during continuation. The end-of-loop routines slow the overall counting speed down a bit, but not much when the loops are fairly long.
The incrementer, however, is impressively speedy. It can take a new input every forty steps. It can even be run by a 33-step repeater and keeps accurate track - i.e. if you ran a multi-stage binary counter consisting of such signalless incrementers off a top-speed repeater (powerless minecart repeater, obviously), only the third stage would be slow enough that signal-operated counters could handle it:
...Z
╔═╗▼ ╔═╗║
║#B▼ ║#╬╝
║#1║ ║#║║
║#▼║ ║#║║
║#▼╝ ║#╚╝
╚═A# ╚═║#
..▼ ║
..▼ ║
╔═╝ ╔═╝
╚D╝ ╚═╝
D - Driver cart (cycling in the southern loop every 33 steps)
A, B - "counter" carts, switch role between pushing and pushed every round.
1 - "on" position of the counter cell.
Z - push cart's position of the next counter cell or other output.
If the to-be-pushed cart is in the "off" position at B, the incoming cart stops in the "on" position at 1 after the collision. If the 1 is occupied, the incoming cart rolls back into the pit, gets turned around to the east, goes around the corners to the north, pushes the next cell's pushing cart at Z, bounces back through _that_ pit and gets lifted out to the "off" position at B.
In the 33-step incrementer, the driver cart enters its push pit one step before the counter cart reaches position A and if a "carry" was sent, the push cart enters the pit inside the counter cell before the other cart reaches position B.
Of course, slower oscillators are also usable, e.g.
A
▼
▼
╔═╝
║ ║
╚═╝
Has a period of exactly 40 steps, and reconfiguring the incrementer loop to a five-count, like so
X
╔╗▼
#╬╝▼
║║║
║▼║
║▼╝
╚╬#
▼
sends one output for every five inputs received. With the 40-step oscillator, you get a (tested and proven) 200-step signal at X, which can be converted into a pressure plate signal for a clock. Materials needed - four minecarts (one driver, two counter, one receiver). If you want to make it stoppable, you'll also need one building material and two or three levers to build and link up a track stop.
The absolute minimum distance between countable inputs i could realise under this doctrine is 29 steps, feeding a count-to-four circuit (output period of 116 steps); you could place pressure plates on each of the four possible "rest" positions in the circuit, and you'd get the exact number out of it once stopped, so the "off" plates could recover.
I also worked on the loop a bit and got one with a maximum capacity of five to a regular circulation time of 69 steps, quite a bit faster than i had thought possible. It takes a bunch of impulse ramps to speed up the return of the counting cart from the "while-operation" trigger back into the main loop, and a highest-friction track stop to get back down to proper operation speed. In the "end loop" round, the controller cart is pushed out of the counter cart's way a full four steps before the latter arrives. Plenty of time. Longer loops take longer to run, but ~80 steps are still possible with a ten-capacity loop. So that's two actions that can perform too fast for pressure plates to keep up - "while loops" and incrementation. To actually get those speeds, machinery must be very tightly packed together. (Impulse) ramps can help with transfers between processing units, but for operations in ramps, speed must be regulated down to less than derail, or the counter carts end up moving too quickly to properly switch off when the loop ends.