Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2

Author Topic: Dwarven Calculator (very basic, homemade computing)  (Read 4170 times)

nzybwnb

  • Bay Watcher
    • View Profile
Dwarven Calculator (very basic, homemade computing)
« on: April 05, 2012, 05:53:17 am »

Long time lurker, first time poster. I've been working on this little project that I'm rather excited about, and I was hoping to get a little feedback for it. It's a machine that uses DF's fluid mechanics to add numbers. It's pretty basic, and I know that people have been doing more advanced computing around here, so I'll try to keep it short.

I don't have a prototype yet, but I can draw you a model. The actual counting process takes place on a staircase, with a single depth pit on every step, a 7/7 activated pressure plate inside the pit, and a door on the next tile activated by the lever.

W=wall, D=door, p=pressure plate. Side view.

Code: [Select]
W D WWW
WpW D W
WWWpW D
  WWWpW

The pressure plates can also be hooked up to an output monitor made of doors, or whatever you choose.

Now the math. This method requires 7/7 units of water per number, plus 2/7 "wasted" units that remain behind on the level above the pit and the space of the door, which means I need 9/7 units per number (that's definitely not the right term, but I don't really know math. Basically I need 9/7x, if x is the input number). However, it's impossible to add 2/7 of water in DF directly, so we need to add a second 7/7 and subtract 1/7 at a time, by running it down a staircase.

For the number 1, then, we take 14/7 units, and run it down 5 stairs, so we get 9/7 falling down the hatch into the calculator. Simple for the lower numbers, but what if you want to calculate, say, 157+389?

For this I needed to come up with a couple of formulas. It uses modular arithmetic, which you can learn in about five minutes if you don't already know it. Go ahead, I'll wait.

Okay, here are the formulas.

Code: [Select]
     x-x(mod7)
f(x)=_________ +1
         7

                   7x+14(f(x))
if: x(mod7) < 4; y=___________ -1 ; # of stairs = 7-2(x(mod7))
                        7

                    7x+14(f(x))
if: x(mod7) >= 4; y=___________ ; # of stairs =14-2(x(mod7))
                         7 

Basically, the way it works is this. Take your number (in our example, 157), and run x(mod7) [157(mod7)]. I think you can do this by dividing the number by 7- your remainder is x(mod7).

Now, check this number against the "if" statements, and run the numbers. "y" is the total amount of water you need to add, and "# of stairs" is the amount of stairs you need to run it down before dropping it into the calculator (subtracting 1/7 units of water per stair, to bring us down to 9/7x). It will never be more than 6.

In our example, 157(mod7)=3, so we run it through the x(mod7) < 4 formula. In this case, y = 1421/7, or 203 full squares of water. A little impractical, perhaps, but not terribly so. Especially not if you put the "# of stairs" in the filling chamber... let's see, that's 7-2(3)=1... well, in this case it may not be so practical, but it will work for smaller numbers, or any number if you're willing to build a calculator large enough to handle it.

Also, I think I misunderstood modular arithmetic and went on to 7 instead of having it loop back to 0. Oops. I'm not changing it now, so just keep it in mind when you're running numbers. It should only make a difference for the 7/0s, and the math works if you use my wrong system, so just go with it.

Anyway, pointers, commentary, or snide comments if deserved are all welcome. Most likely no one will read it, but I won't care because I'll be sleeping.
Logged

BastiBasti

  • Bay Watcher
  • ‼SCIENCE‼
    • View Profile
Re: Dwarven Calculator (very basic, homemade computing)
« Reply #1 on: April 05, 2012, 05:58:15 am »

You are the albert eingstein of dwarfs. WTF is that and how does it work? Explain more basically.
Logged

nzybwnb

  • Bay Watcher
    • View Profile
Re: Dwarven Calculator (very basic, homemade computing)
« Reply #2 on: April 05, 2012, 06:05:36 am »

You are the albert eingstein of dwarfs. WTF is that and how does it work? Explain more basically.

Er- let's see. It is only possible to multiply by 7, and subtract by 1, because God says so. If you need 9/7x, therefore, the task would seem impossible, but this set of formulas allows you to do just that, by placing the number in its appropriate position in a cycle of 7 and then adding the correct amount of water to get one multiple of 7 more than is needed, then subtracting down to exactly 9/7x.
Logged

xdarkcodex

  • Bay Watcher
  • Watch in awe!
    • View Profile
Re: Dwarven Calculator (very basic, homemade computing)
« Reply #3 on: April 05, 2012, 06:50:21 am »

Haha I still don't understand... :(
Logged
the statement below is true
the statement above is false

BastiBasti

  • Bay Watcher
  • ‼SCIENCE‼
    • View Profile
Re: Dwarven Calculator (very basic, homemade computing)
« Reply #4 on: April 05, 2012, 06:55:35 am »

You are the albert eingstein of dwarfs. WTF is that and how does it work? Explain more basically.

Er- let's see. It is only possible to multiply by 7, and subtract by 1, because God says so. If you need 9/7x, therefore, the task would seem impossible, but this set of formulas allows you to do just that, by placing the number in its appropriate position in a cycle of 7 and then adding the correct amount of water to get one multiple of 7 more than is needed, then subtracting down to exactly 9/7x.

.....wtf?
Logged

The_Countess

  • Bay Watcher
    • View Profile
Re: Dwarven Calculator (very basic, homemade computing)
« Reply #5 on: April 05, 2012, 07:01:41 am »

if you want to make 9 you have to look at how many times 7 fits into 9
which is once. and you have 2 remaining.
so add 7 more water units and subtract (7-2 =) 5 units of water.

if you need 15. you can fit 7 in there 2 times.
add one more 7. making 21, then subtract 1 6 times to make 15.
Logged

Loud Whispers

  • Bay Watcher
  • They said we have to aim higher, so we dug deeper.
    • View Profile
    • I APPLAUD YOU SIRRAH
Re: Dwarven Calculator (very basic, homemade computing)
« Reply #6 on: April 05, 2012, 07:26:38 am »

First post, and you're making calculator designs?

/respect

xdarkcodex

  • Bay Watcher
  • Watch in awe!
    • View Profile
Re: Dwarven Calculator (very basic, homemade computing)
« Reply #7 on: April 05, 2012, 07:37:00 am »

if you want to make 9 you have to look at how many times 7 fits into 9
which is once. and you have 2 remaining.
so add 7 more water units and subtract (7-2 =) 5 units of water.

if you need 15. you can fit 7 in there 2 times.
add one more 7. making 21, then subtract 1 6 times to make 15.
Oooooh :o that makes everything a lot clearer now. (No sarcasm) 
Logged
the statement below is true
the statement above is false

Trif

  • Bay Watcher
  • the Not-Quite-So-Great-as-Toady One
    • View Profile
Re: Dwarven Calculator (very basic, homemade computing)
« Reply #8 on: April 05, 2012, 07:43:16 am »

Hmm, so your concept is to run water down a "staircase", and each step equals one number, right? So if you want to have the number 2, you'd have to fill two steps of your staircase, using 9/7 * 2 = 18/7 units of water (because 2/7 get wasted at each step).
The problem is that you can't just get 18/7 units of water, but you can get 21/7 and let it run for 3 steps, making 18/7.

Your math to the problem is a bit... confusing to say the least. I'll try to break it down.
First, a sequence is more appropriate than a function.

rn = 9/7 * n

rn is just the required water for your staircase. I we insert the number 2, we get

r2 =  18/7.
Now, we know that we can't create 18/7 water, but we can create 21/7 and subtract 3/7 by running it down steps. How much water we can create can be calculated by this sequence:

wn =  rn + (7 - ((rn * 7) mod 7)) / 7

Or, if you use nzybwnb's notation, this:

Code: [Select]

            7 - ((x*7) mod 7)
f(x) = x + __________________
                    7

Hmm, that ended up looking just as complicated, but I'll try to explain. First, we take our old number rn, and decide how much we'll need to add to it. Let's assume 18/7 for rn.

w2 = 18/7 + (7 - ((18/7) * 7) mod 7)) / 7

First, we multiply it by 7, because mod works best with natural numbers.

w2 = 18/7 + (7 - (18 mod 7)) / 7

18 mod 7 is 4.

w2 = 18/7 + (7 - 4) / 7

And finally, we divide it by 7 again to get the fluid amounts.

w2 = 18/7 + 3/7

w2 = 21/7

This is how much water you'll need. It's easy for small numbers, but the formula will come in handy for bigger numbers like 157.
Now, if you want to know how many stairs it should run down, do this:

sn = (wn - rn) * 7

Obvious, right?

s2= (21/7 - 18/7) * 7
s2= 3

To display the number 2, I need 21/7 units of water to run down 3 steps to become 18/7 units of water which I can use in the calculation staircase.

Now let's try it with 157!

r157 = 9/7 * 157 = 1413/7

w157 = 1413/7 + (7 - ((1413/7) * 7) mod 7)) / 7
w157 = 1413/7 + (7 - (1413 mod 7)) / 7
w157 = 1413/7 + (7 - 6) / 7
w157 = 1413/7 + 1/7
w157 = 1414/7 = 202

s157 = (1414/7 - 1413/7) * 7 = 1

Looks like we only need 202 * 7/7 units of water if we let it run down one step. Your formula was off by one, probably because of the looping problems. Oh well.

Okay, this was fun. Your method is extremely complicated, needs way too much space (one step per number) and probably cannot be automated because you'll have to run a modular equation just to recognize numbers. It will probably never be built.

In other words, it's perfectly dwarfy. Welcome to the forums.
« Last Edit: April 05, 2012, 08:23:37 am by Trif »
Logged
Quote from: Toady One
I wonder if the game has become odd.

SRD

  • Bay Watcher
  • Who the hell do you think I think you are?
    • View Profile
Re: Dwarven Calculator (very basic, homemade computing)
« Reply #9 on: April 05, 2012, 07:44:47 am »

What if it runs out of battery?
Logged
Quote from: LoneTophat
EDIT: HOW DO I STOP THE BLEEDING!
SUPEREDIT: Nevermind. Bled to death ._.

BastiBasti

  • Bay Watcher
  • ‼SCIENCE‼
    • View Profile
Re: Dwarven Calculator (very basic, homemade computing)
« Reply #10 on: April 05, 2012, 11:28:08 am »

What if it runs out of battery?

This is the most understandable part of this whole post. Thank you, whoever you are.
Logged

SRD

  • Bay Watcher
  • Who the hell do you think I think you are?
    • View Profile
Re: Dwarven Calculator (very basic, homemade computing)
« Reply #11 on: April 05, 2012, 11:30:31 am »

I'm whoever you want me to be... for the right price.
Logged
Quote from: LoneTophat
EDIT: HOW DO I STOP THE BLEEDING!
SUPEREDIT: Nevermind. Bled to death ._.

Nyotor Lizardhammers

  • Bay Watcher
  • This adorable animal can't work.
    • View Profile
Re: Dwarven Calculator (very basic, homemade computing)
« Reply #12 on: April 05, 2012, 11:40:10 am »

I assume then it would be solar pow-


ahahahah I can't say that with a straight face. Solar. Ha. Oh man.
Logged
Nyo Ho Ho!

SRD

  • Bay Watcher
  • Who the hell do you think I think you are?
    • View Profile
Re: Dwarven Calculator (very basic, homemade computing)
« Reply #13 on: April 05, 2012, 11:40:45 am »

Dafuq you think this is? Human Fortress?
Logged
Quote from: LoneTophat
EDIT: HOW DO I STOP THE BLEEDING!
SUPEREDIT: Nevermind. Bled to death ._.

Nil Eyeglazed

  • Bay Watcher
    • View Profile
Re: Dwarven Calculator (very basic, homemade computing)
« Reply #14 on: April 05, 2012, 12:31:57 pm »

Oh, that's cool.  Do I understand correctly that basically, you're taking "number of tiles of water" and outputting based on "height that can be reached by that amount of water"?  Sounds like an interesting alternative adder design.  You might want to check the adder (computing) page on the wiki and put a note about this style of adder-- it only deals with logic gate based adders right now, and is a little boring/useless/dry (which is my fault).
Logged
He he he.  Yeah, it almost looks done...  alas...  those who are in your teens, hold on until your twenties...  those in your twenties, your thirties...  others, cling to life as you are able...<P>It should be pretty fun though.
Pages: [1] 2