Anyone a math wiz?
by Travis Evans · in General Discussion · 03/10/2009 (8:18 am) · 18 replies
For the past few days I've been trying to solve this math problem. I'm not sure that it can even be done, but I'm hoping that someone here help.
Let's say I have 2 numbers, 12 and 33. Is there any way to mathematically combine the numbers into 1 result but then recover the 2 numbers again?
So like:
12 (Some Equation) 33 = 78
Then:
78 (Some Equation) = 12 and 33
Thanks
Let's say I have 2 numbers, 12 and 33. Is there any way to mathematically combine the numbers into 1 result but then recover the 2 numbers again?
So like:
12 (Some Equation) 33 = 78
Then:
78 (Some Equation) = 12 and 33
Thanks
#2
if you know that each of the two numbers is less than some value it's easy.
say X and Y are both less than 100.
just do Z = X + 100 * Y
then X = Z - (floor(Z/100) * 100)
and Y = Z - X
if you choose a power of two for the limit this is very easy and efficient to implement in a language like C.
a more difficult but more mathematically robust way is to use "diagonalization". imagine you have a grid starting with a cell in the upper left and extending forever out to the right and below. each edge of the grid is numbered with the non-negative whole numbers. so "first" cell is in the upper left, and will be at [0,0]. the one below it will be at [0,1] and the one to the right of it will be at [1,0], and so on. then you fill this grid with whole numbers, in a diagonal fashion starting with the upper left and moving diagonally. like so:
so now you have a mapping from any pair of non-negative integers to the whole numbers and back again.
one interesting implication of this is that if you're allowed to use numbers as large as you want, you can encode an arbitrary amount of information in a single number.
also fwiw, this is one way to prove that the rational numbers (fractions) are "countable". "countable" means there may be an infinite number of them, but you can map them to the whole numbers, which this diagonalization trick clearly does for the rationals. you can prove that the irrationals (numbers which are not rational, ie they can not be represented as a ratio of two integers, for example sqrt(2)) can not be mapped in any way to the whole numbers. this is why the irrationals are said to have a "larger" infinity than the rationals or the integers.
03/10/2009 (10:46 am)
an easy but limited way:if you know that each of the two numbers is less than some value it's easy.
say X and Y are both less than 100.
just do Z = X + 100 * Y
then X = Z - (floor(Z/100) * 100)
and Y = Z - X
if you choose a power of two for the limit this is very easy and efficient to implement in a language like C.
a more difficult but more mathematically robust way is to use "diagonalization". imagine you have a grid starting with a cell in the upper left and extending forever out to the right and below. each edge of the grid is numbered with the non-negative whole numbers. so "first" cell is in the upper left, and will be at [0,0]. the one below it will be at [0,1] and the one to the right of it will be at [1,0], and so on. then you fill this grid with whole numbers, in a diagonal fashion starting with the upper left and moving diagonally. like so:
0 1 2 3.. +---+---+---+-- 0| 1 | 3 | 6 | 10 +---+---+---+-- 1| 2 | 5 | 9 | +---+---+---+-- 2| 4 | 8 | | +---+---+---+-- 3| 7 | | | . .
so now you have a mapping from any pair of non-negative integers to the whole numbers and back again.
one interesting implication of this is that if you're allowed to use numbers as large as you want, you can encode an arbitrary amount of information in a single number.
also fwiw, this is one way to prove that the rational numbers (fractions) are "countable". "countable" means there may be an infinite number of them, but you can map them to the whole numbers, which this diagonalization trick clearly does for the rationals. you can prove that the irrationals (numbers which are not rational, ie they can not be represented as a ratio of two integers, for example sqrt(2)) can not be mapped in any way to the whole numbers. this is why the irrationals are said to have a "larger" infinity than the rationals or the integers.
#3
03/10/2009 (10:57 am)
Great...though his problem involved 2 numbers and a simple question. being that no other info was given, I don't think he was looking for a lesson in mathematics, but GREAT ANSWER!
#4
03/10/2009 (1:08 pm)
Great answer Orion, I like the way you covered the differing possiblities.
#5
CameraData
DebrisData
ExplosionData
FlyingVehicleData
GameBaseData
HoverVehicleData
ItemData
LightningData
MissionMarkerData
ParticleData
ParticleEmitterData
PathEmitterNodeData
PathCameraData
PlayerData
PrecipitationData
ProjectileData
ShapeBaseData
SimDataBlock
SplashData
StaticShapeData
TriggerData
VehicleData
WheeledVehicleData
WheeledVehicleSpring
WheeledVehicleTire
Camera
Debris
Explosion
FlyingVehicle
GameBase
HoverVehicle
Item
Lightning
MissionMarker
Particle
ParticleEmitter
PathEmitterNode
PathCamera
Player
Precipitation
Projectile
ShapeBase
-none-
Splash
StaticShape
Trigger
Vehicle
WheeledVehicle
WheeledVehicle
WheeledVehicle
Like maybe the available methods and properties for the object classes?
THAT needs some detailed explanation
03/10/2009 (1:12 pm)
Since I have your attention.. can you or anyone else tell me where I can find specifics about:CameraData
DebrisData
ExplosionData
FlyingVehicleData
GameBaseData
HoverVehicleData
ItemData
LightningData
MissionMarkerData
ParticleData
ParticleEmitterData
PathEmitterNodeData
PathCameraData
PlayerData
PrecipitationData
ProjectileData
ShapeBaseData
SimDataBlock
SplashData
StaticShapeData
TriggerData
VehicleData
WheeledVehicleData
WheeledVehicleSpring
WheeledVehicleTire
Camera
Debris
Explosion
FlyingVehicle
GameBase
HoverVehicle
Item
Lightning
MissionMarker
Particle
ParticleEmitter
PathEmitterNode
PathCamera
Player
Precipitation
Projectile
ShapeBase
-none-
Splash
StaticShape
Trigger
Vehicle
WheeledVehicle
WheeledVehicle
WheeledVehicle
Like maybe the available methods and properties for the object classes?
THAT needs some detailed explanation
#6
What I'm looking to do is take 2 numbers, then through some equation return 1 number. But If I reverse the equation, I'm able to get the 2 original values back. I like the grid.
Now I'm just thinking out loud.
Ok, so lets say my grid looks like this:
X 0 1 2 3
==========
0| 0 2 5 9
1| 1 4 5 C
2| 3 7 B E
3| 6 A D F
So if my values are 12 and 33, 12 becomes 7 and 33 becomes F.
So 1233 becomes 7F... like a hex value or 127 as a Decimal.
So is it now possible to take 7F an get only 1 number from it? I know it seems odd and crazy, but I'm just wondering if it can be done. I've trying to keep my mind out of the box in order to solve this.
Thanks for the help so far guys!
03/10/2009 (4:26 pm)
Orion, Thanks for the help. I tried the equation but it didn't give the answer I was looking for.What I'm looking to do is take 2 numbers, then through some equation return 1 number. But If I reverse the equation, I'm able to get the 2 original values back. I like the grid.
Now I'm just thinking out loud.
Ok, so lets say my grid looks like this:
X 0 1 2 3
==========
0| 0 2 5 9
1| 1 4 5 C
2| 3 7 B E
3| 6 A D F
So if my values are 12 and 33, 12 becomes 7 and 33 becomes F.
So 1233 becomes 7F... like a hex value or 127 as a Decimal.
So is it now possible to take 7F an get only 1 number from it? I know it seems odd and crazy, but I'm just wondering if it can be done. I've trying to keep my mind out of the box in order to solve this.
Thanks for the help so far guys!
#7
close but not quite.
if your values are 12 and 33, your grid would need to be say 66 x 66,
and the single value you get would be whatever is in cell [12,33],
which happens to be 958. So if you knew your "combined" number was 958, you would find where 958 appears in the table, and value 1 is the X-coordinate and value 2 is the Y.
this google spreadsheet illustrates it: spreadsheets.google.com/ccc?key=pjk5k-M0sgaq4jw9tb1J9Fg
again, this diagonal thing is really a pure math tool, not so much a practical computer coding tool.
it sounds like you're working with relatively small values tho,
like each value is a byte ?
if your output value has the same number as bits as the two input values, there's no way you can do this.
if your output value can be two bytes however, and your inputs are one byte, then your work is easy:
C = A + 256 * B
then to get A back it's just:
A = C % 256
B = (C - A) / 256
03/10/2009 (4:47 pm)
hey Travis -close but not quite.
if your values are 12 and 33, your grid would need to be say 66 x 66,
and the single value you get would be whatever is in cell [12,33],
which happens to be 958. So if you knew your "combined" number was 958, you would find where 958 appears in the table, and value 1 is the X-coordinate and value 2 is the Y.
this google spreadsheet illustrates it: spreadsheets.google.com/ccc?key=pjk5k-M0sgaq4jw9tb1J9Fg
again, this diagonal thing is really a pure math tool, not so much a practical computer coding tool.
it sounds like you're working with relatively small values tho,
like each value is a byte ?
if your output value has the same number as bits as the two input values, there's no way you can do this.
if your output value can be two bytes however, and your inputs are one byte, then your work is easy:
C = A + 256 * B
then to get A back it's just:
A = C % 256
B = (C - A) / 256
#8
C = 12 + 256 * 33 = 8460
so then
A = 8460 % 256 = 12
B = (8460 - 12) / 256 = 33
03/10/2009 (5:12 pm)
egC = 12 + 256 * 33 = 8460
so then
A = 8460 % 256 = 12
B = (8460 - 12) / 256 = 33
#9
it comes in the form of a game:
first, you tell me any number of pieces of paper you want,
and then i give you that many pieces of paper. could be one, could be a gazillion. but not infinite.
then, i tell you any number i want. let's call that number Q.
your challenge is to express any number larger than Q on those pieces of paper using a pen. (you get as many pens as you want, too).
you're allowed to use any notation you like, including algorithms.
assuming we both play optimally, who wins ?
03/10/2009 (5:16 pm)
here is an interesting math puzzle. at least, interesting to me.it comes in the form of a game:
first, you tell me any number of pieces of paper you want,
and then i give you that many pieces of paper. could be one, could be a gazillion. but not infinite.
then, i tell you any number i want. let's call that number Q.
your challenge is to express any number larger than Q on those pieces of paper using a pen. (you get as many pens as you want, too).
you're allowed to use any notation you like, including algorithms.
assuming we both play optimally, who wins ?
#10
Orion, thanks for trying to help me. Your answers are getting me to think. Basically through tables and representations I'm trying to break down numbers. It's giving a headache yes, but I know it could be done.... at least to some extent. What I'm working on, with a buddy who know about as much math as I do, which as you can see is minimal, is a form of compression. And as I noted in my first post, I don't even think it can be done. But it is a challenge and I do like a challenge every now and then. Ok so let's say I have 2 bytes in bit form:
01010011 01101111
What I had thought was to group 2 bits at a time then using a table replace the binary.
00 = 0
01 = 1
10 = 2
11 = 3
01010011 01101111
Becomes
1103 1233
This is how I got 1233. 1233 represents the binary. Obviously this isn't binary and by converting the Decimal, 1233, to hex, you actually get inflation. Not exactly what's wanted. So my buddy suggested HEX which at first I though inflation, but then I started to think, what if I can break the 4 numbers, 1233 and by using another table write a nibble.
With the binary example, there's really no math involved, just replacing A for B. Similar to the older compression methods.
Again, I'm not sure if it's even possible. But you've really got to think outside the box, which is never a bad thing.
03/10/2009 (5:40 pm)
Honestly, I couldn't tell ya.Orion, thanks for trying to help me. Your answers are getting me to think. Basically through tables and representations I'm trying to break down numbers. It's giving a headache yes, but I know it could be done.... at least to some extent. What I'm working on, with a buddy who know about as much math as I do, which as you can see is minimal, is a form of compression. And as I noted in my first post, I don't even think it can be done. But it is a challenge and I do like a challenge every now and then. Ok so let's say I have 2 bytes in bit form:
01010011 01101111
What I had thought was to group 2 bits at a time then using a table replace the binary.
00 = 0
01 = 1
10 = 2
11 = 3
01010011 01101111
Becomes
1103 1233
This is how I got 1233. 1233 represents the binary. Obviously this isn't binary and by converting the Decimal, 1233, to hex, you actually get inflation. Not exactly what's wanted. So my buddy suggested HEX which at first I though inflation, but then I started to think, what if I can break the 4 numbers, 1233 and by using another table write a nibble.
With the binary example, there's really no math involved, just replacing A for B. Similar to the older compression methods.
Again, I'm not sure if it's even possible. But you've really got to think outside the box, which is never a bad thing.
#11
i believe compression is really only possible if you have a largish number of bits you're trying to compress.
consider the simplest case where you have two single-bit numbers: clearly there is no way to encode them both in another single-bit number.
when the number of bits grows large however,
you can take advantage of patterns in the bits.
you might be interested in reading up on "Huffman Coding".
the basic idea there is that you analyze your data for "words",
and replace each word with a short bit-string representing it.
the trick is that you assigne shorter bit-strings to the more common words.
03/10/2009 (5:54 pm)
hey Travis - yeah, thinking outside the box is good.i believe compression is really only possible if you have a largish number of bits you're trying to compress.
consider the simplest case where you have two single-bit numbers: clearly there is no way to encode them both in another single-bit number.
when the number of bits grows large however,
you can take advantage of patterns in the bits.
you might be interested in reading up on "Huffman Coding".
the basic idea there is that you analyze your data for "words",
and replace each word with a short bit-string representing it.
the trick is that you assigne shorter bit-strings to the more common words.
#12
So Say 12 33 then include 20 13
I'm pretty persistent and stubborn, I know.
Could you also give me a quick run down of how the % symbol works? I know it's not your run of the mill percentage.
03/10/2009 (6:36 pm)
Orion, is it possible to add a 3rd digit or even 4th digit to the example you showed?So Say 12 33 then include 20 13
C = 12 + 256 * 33 = 8460 so then A = 8460 % 256 = 12 B = (8460 - 12) / 256 = 33
I'm pretty persistent and stubborn, I know.
Could you also give me a quick run down of how the % symbol works? I know it's not your run of the mill percentage.
#13
last login is 1969?
http://www.garagegames.com/account/profile/148217
but shes been a member since 2009.
just a web dev bug if anyone cares.
sorry for stealing your topic travis.
03/10/2009 (7:24 pm)
not to get too offtopic here but how is that Libra'slast login is 1969?
http://www.garagegames.com/account/profile/148217
but shes been a member since 2009.
just a web dev bug if anyone cares.
sorry for stealing your topic travis.
#14
03/10/2009 (7:43 pm)
Not a problem. My guess would be the Last Login Table has a value of 0.
#15
basically the thing above w/ multiplying by 256 is another way of just stringing one byte after another. multiplying a value by 256 is the same as shifting the bits to the left 8 times. (shifting the bits of a number left once is the same as multiplying by two, and shifting right once is the same as dividing by two) so yeah, you could shift the bits left 8 times again and add another byte in there. if your original values are bytes (8 bits) and your encoded value is a full integer (32 bits) then you could certainly encode 4 values this way, but it's really using the same number of bits.
here's the 12 & 33 example in binary -
so really all we've done is written one of the bytes after the other.
the % operator is the "modulo" operator. A % B gives you the remainder of A divided by B. it's equivelant to A - (floor(A / B) * B). so for example 4 % 3 would be the remainder of 14 / 3, which is 2, since 3 goes into 14 as 12 remainder 2. so C % 256 is just a way to extract the last 8 bits from a larger value.
it's great that you're thinking about this stuff! persistence and stubborness can lead to real innovation.
03/11/2009 (12:48 am)
hey Travis - basically the thing above w/ multiplying by 256 is another way of just stringing one byte after another. multiplying a value by 256 is the same as shifting the bits to the left 8 times. (shifting the bits of a number left once is the same as multiplying by two, and shifting right once is the same as dividing by two) so yeah, you could shift the bits left 8 times again and add another byte in there. if your original values are bytes (8 bits) and your encoded value is a full integer (32 bits) then you could certainly encode 4 values this way, but it's really using the same number of bits.
here's the 12 & 33 example in binary -
12 = 00001100 33 = 00100001 256 * 33 = 0010000100000000 (same as 33 but with 8 zeros after) 12 + 256 * 33 = 0010000100001100
so really all we've done is written one of the bytes after the other.
the % operator is the "modulo" operator. A % B gives you the remainder of A divided by B. it's equivelant to A - (floor(A / B) * B). so for example 4 % 3 would be the remainder of 14 / 3, which is 2, since 3 goes into 14 as 12 remainder 2. so C % 256 is just a way to extract the last 8 bits from a larger value.
it's great that you're thinking about this stuff! persistence and stubborness can lead to real innovation.
#16
What if the first pass were to "decode" the 1s and 0s? Say 1 = 01 and 0 = 00.
Then if you were to run another pass and decode it further and so on. It's all theory.. based off some blurry idea rattling in my head.
03/11/2009 (8:06 am)
Well I was reading over an article on the "Huffman Coding" as you suggested. I had heard about it before, use in Zip... I think. I'm not much of a programmer so the whole node/leaf thing is a bit sketchy but I do understand why it's needed but can't explain it. But while reading, I got to thinking and asked my self this, can Huffman be applied to binary? So for an example. Say we have the byte:01100011
What if the first pass were to "decode" the 1s and 0s? Say 1 = 01 and 0 = 00.
01100011 00010100 00000101
Then if you were to run another pass and decode it further and so on. It's all theory.. based off some blurry idea rattling in my head.
#17
say you just have two 2-bit numbers A & B you want to encode into another 2-bit number C.
each number can have four possible values: 00, 01, 10, 11.
so there are sixteen total possible values for A & B together:
00 00
00 01
00 10
00 11
01 00
01 01
01 10
01 11
10 00
10 01
10 10
10 11
11 00
11 01
11 10
11 11
would your encoding scheme work for all 16 possible inputs ?
03/11/2009 (8:30 am)
try working it out with an even simpler example.say you just have two 2-bit numbers A & B you want to encode into another 2-bit number C.
each number can have four possible values: 00, 01, 10, 11.
so there are sixteen total possible values for A & B together:
00 00
00 01
00 10
00 11
01 00
01 01
01 10
01 11
10 00
10 01
10 10
10 11
11 00
11 01
11 10
11 11
would your encoding scheme work for all 16 possible inputs ?
#18
I took part of a lyrics, then got the binary from it, broke it up into 2 bit grouping then counted the occurrences of the 4 groups. Looking for any patterns. I started by counting the occurrences.
00 = 103
01 = 136
10 = 96
11 = 57
I did the same for 4 bit grouping:
0000 = 21
0001 = 08
0010 = 28
0011 = 07
0100 = 12
0101 = 14
0110 = 54
0111 = 24
1000 = 02
1001 = 06
1010 = 00
1011 = 00
1100 = 04
1101 = 04
1110 = 06
1111 = 06
I don't know though... I keep thinking of a tree and/or master table.
03/11/2009 (9:31 am)
At the moment, probably not. That's why I'm trying to wrap my mind around this. Looking at patterns.Currently looking at this: 01 01 00 11 01 10 11 11 00 10 00 00 01 10 00 11
I took part of a lyrics, then got the binary from it, broke it up into 2 bit grouping then counted the occurrences of the 4 groups. Looking for any patterns. I started by counting the occurrences.
00 = 103
01 = 136
10 = 96
11 = 57
I did the same for 4 bit grouping:
0000 = 21
0001 = 08
0010 = 28
0011 = 07
0100 = 12
0101 = 14
0110 = 54
0111 = 24
1000 = 02
1001 = 06
1010 = 00
1011 = 00
1100 = 04
1101 = 04
1110 = 06
1111 = 06
I don't know though... I keep thinking of a tree and/or master table.
Torque 3D Owner RealmX
variable y = 12;
variable z = x + y;
...if you're refering to coding