# B Elevator Game

#### DaveC426913

Gold Member
My friend has asked me for a formula that will solve his kid's elevator game.

Imagine an apartment building with an infinite number of floors, both + and -.
You start on an arbitrary floor, say 11.
The game asks you to meet your mother on the 61st floor (the actual goal floor changes).
But the elevator is broken so pressing UP will go up 61 floors (changes with each game).
And pressing DOWN will go down 18 floors (also changes).

I'll generalize it for any game parameters - after I figure it out for the example parameters.

Here's my formula for this game's params:

61x - 18y = z

Where x is the number of UPs,
y is the number of DOWNs
and z is the trip desired (number of floors to move).
z is 61 -11, so that's +50.

I can move things around till I get a proper function.
61x - 18y = 50
-18y = 50 - 61x
y = (50 - 61x)/18

This gives me a line graph. But I'm missing a second formula to sub in for x or y, to give me a point.

BTW, I worked it out by brute force, solving the equation for increasing values of x, until I reached a value of y that is an integer. (Not as hard as all that: x has to be even, and it's gonna be more than 6 or so. I only had to get from 6 to 20 in even increments.)

20 UPs and 65 DOWNs will move the car up by 50 floors to mom's place.

Anyway, I'm missing that substitution formula. It's got to be the ratio of 18 to 61.

#### DaveC426913

Gold Member
Ah. I think it must be x = 18/61y.

[EDIT] No, that's not right...

And besides, it can't result in a single answer, since there are multiple possible solutions. We'd be interested in the smallest, but a simple formula of the form 'y=...' isn't going to divulge that.

Is it possible this can't be solved with a formula? It would have to output an unlimited number of solutions.

Last edited:

#### DaveC426913

Gold Member
This my general algorithm:

Dx - Uy = z'-z

Where
D is the number of floors a single push of DOWN goes,
U is the number of floors a single push of UP goes,
x is the number of required DOWN pushes,
y is the number of required UP pushes,
z is the end floor.
z' is the start floor.

Solve for increasing values of x, until y is an integer.

But that's not a formula.

#### jedishrfu

Mentor
Is this like hailstone numbers?

They use a different rule though if the number is even divide by 2 but if the number is odd multiply by 3 and add 1. Starting at any number you get this up/down sequence of numbers that eventually terminates at 1.

In any event, for your game you establish some "beats" like up-down or up-down-down ... and construct a list of deltas to choose from. However, I probably don't know what I'm talking about.

#### DaveC426913

Gold Member
Is this like hailstone numbers?

They use a different rule though if the number is even divide by 2 but if the number is odd multiply by 3 and add 1. Starting at any number you get this up/down sequence of numbers that eventually terminates at 1.
No. But I've played that game.
Solved it up to about 100.
Something very special about 27. It takes a ridiculously long time to reach 1.

In any event, for your game you establish some "beats" like up-down or up-down-down ... and construct a list of deltas to choose from. However, I probably don't know what I'm talking about.
I thought about that.
61-(18*3) = 7
61-(18*4) = -11
etc.
But I think that results in a tedious algorithm.

#### jedishrfu

Mentor
Hmm so floor delta = x*ups + y*downs

50 = 61*x - 18*y ==> (61*x - 50)/18 = y with the constraint that x, y are integers.

So it seems if x starts as an integer say x=1 then y will be a rational number so you need to find an n such that ny is an integer.

Say x=1 but y=0.02 then n=50 making x=50 and y=1

EDITTED to fix sign mistake

#### DaveC426913

Gold Member
Hmm so floor delta = x*ups + y*downs

50 = 61*x + 18*y ==> (50 - 61*x)/18 = y with the constraint that x, y are integers.
Yup. That's exactly what I got. (except it should be - 18*y)
But it's an algorithm, not a formula - i,.e. it must be solved iteratively.

#### jedishrfu

Mentor
yes sorry I got the sign wrong, my bad.

#### DaveC426913

Gold Member
So, is it possible to write a formula that outputs multiple values?
(I mean, it must be. y=x^2 has multiple solutions.)

#### jedishrfu

Mentor
if it output a vector then yes.

#### DaveC426913

Gold Member
Yeah, I dunno how to do that.

#### jedishrfu

Mentor
input is a number and output is a vector:

FXY(50) = <x,y>

#### jedishrfu

Mentor
The trouble is I think this is a diophantine problem which makes it somewhat difficult.

Perhaps @fresh_42 could give some insight here.

#### mfb

Mentor
• PeroK

#### hmmm27

Well... I can't offer a positive solution but, for starters...

The (unary disallowed) common divisors of the Up and Down values is a subset of the divisors of the Distance. Otherwise "you can't get there from here".

Last edited:

#### DaveC426913

Gold Member
There isn't a simple formula, but you can use the results of the steps of the euclidean algorithm for the greatest common divisor to solve the equation.
https://www.math.uh.edu/~minru/number/hj02cs01.pdf
or
Cool. Thanks. Who'da thunk a kid's video game could require such advanced math...

Hm. I'm not sure how to deal with the fact that my equation doesn't equal 1. It equals 50:

61U - 18D = 50

#### mfb

Mentor
If you figure out how to move by 1 floor you can also move by 50 floors: Multiply both sides by 50, then (optional) subtract 18 U and 61 D until you reach the minimal number of steps.

#### DaveC426913

Gold Member
If you figure out how to move by 1 floor you can also move by 50 floors: Multiply both sides by 50, then (optional) subtract 18 U and 61 D until you reach the minimal number of steps.
Sure, but thats back to an iterative approach. I've already got that solution. I was looking to meet the letter of my friend's request, which was a formula.
(Although I guess, solving a Diophantine formula is iterative anyway.)

#### mfb

Mentor
What I described can easily be converted to a formula. Easier than finding a solution for 1 floor.

### The Physics Forums Way

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving