wu :: forums
« wu :: forums - Compacting Pairs of Numbers »

Welcome, Guest. Please Login or Register.
Apr 25th, 2024, 6:03pm

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   medium
(Moderators: Icarus, Grimbal, ThudnBlunder, william wu, towr, SMQ, Eigenray)
   Compacting Pairs of Numbers
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: Compacting Pairs of Numbers  (Read 906 times)
Virgilijus
Newbie
*





   


Gender: male
Posts: 11
Compacting Pairs of Numbers  
« on: Dec 21st, 2015, 11:37am »
Quote Quote Modify Modify

After accidentally leaving the door open between the crocodile farm and the nursery, Willy has had to find another job. With his reputation preceding him, he can only find work in the boring and seemingly infinite Number Storage Warehouse.
 
On his first day, Willy's boss puts him to task; he needs to store every single unique pair of positive integers on the shelf. However, Willy has an idea; if he can take each unique pair and somehow transform them into a unique single number, he'll double the amount of pairs they can store (though his coworker, Mr. Cantor, disagrees) and perhaps he'll get a promotion.
 
Devise a way to transform a unique pair of positive integers (x,y) into a single, unique positive integer output (z). Note: order does matter to the pair i.e. f(x,y) = z implies f(y,x) =/= z.
IP Logged
towr
wu::riddles Moderator
Uberpuzzler
*****



Some people are average, some are just mean.

   


Gender: male
Posts: 13730
Re: Compacting Pairs of Numbers  
« Reply #1 on: Dec 21st, 2015, 10:34pm »
Quote Quote Modify Modify

z = frombase10str(tobase9str(x) + '9' + tobase9str(y))  
e.g. (123, 345) => 1469556; (987, 654) => 13169806

I bet there's more efficient ways though. I mean, aside from using a large base B and B+1.
« Last Edit: Dec 21st, 2015, 10:36pm by towr » IP Logged

Wikipedia, Google, Mathworld, Integer sequence DB
rmsgrey
Uberpuzzler
*****





134688278 134688278   rmsgrey   rmsgrey


Gender: male
Posts: 2873
Re: Compacting Pairs of Numbers  
« Reply #2 on: Dec 22nd, 2015, 9:11am »
Quote Quote Modify Modify

A bijective mapping:
 
1) Convert y in Z to y' in N by taking the absolute value, doubling it, and subtracting 1 if y is negative.
 
2) Pad the shorter number with leading zeroes so they're the same length, then, starting with the first digit of x, interleave the digits of x and y' to produce a new number, z, with the same sign as x.
 
To reverse:
 
2') If z has an odd number of digits, pad it with a leading 0, then take alternate digits and the sign of z as x, and the remaining digits as y'
 
1') If y' is odd, add 1 and subtract the result from 0. Either way, halve that number to give y.
IP Logged
markr
Junior Member
**





   


Gender: male
Posts: 90
Re: Compacting Pairs of Numbers  
« Reply #3 on: Dec 23rd, 2015, 10:45pm »
Quote Quote Modify Modify


Similar to the diagonal method of mapping fractions to integers:
 
f(x,y) = (x^2 + y^2 + 2xy - 3x - y + 2) / 2
IP Logged
towr
wu::riddles Moderator
Uberpuzzler
*****



Some people are average, some are just mean.

   


Gender: male
Posts: 13730
Re: Compacting Pairs of Numbers  
« Reply #4 on: Dec 24th, 2015, 1:06pm »
Quote Quote Modify Modify

Very nice, that.
IP Logged

Wikipedia, Google, Mathworld, Integer sequence DB
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board