Click here to Skip to main content
15,899,026 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: algorithm to get each individual digit from a decimal number (integer) Pin
ant-damage18-May-10 9:01
ant-damage18-May-10 9:01 
QuestionRe: algorithm to get each individual digit from a decimal number (integer) Pin
CPallini18-May-10 10:01
mveCPallini18-May-10 10:01 
AnswerRe: algorithm to get each individual digit from a decimal number (integer) Pin
ant-damage18-May-10 10:25
ant-damage18-May-10 10:25 
QuestionUnique number from two numbers [modified] Pin
theCPkid15-May-10 2:58
theCPkid15-May-10 2:58 
AnswerRe: Unique number from two numbers Pin
Luc Pattyn15-May-10 4:18
sitebuilderLuc Pattyn15-May-10 4:18 
GeneralRe: Unique number from two numbers Pin
theCPkid15-May-10 5:02
theCPkid15-May-10 5:02 
GeneralRe: Unique number from two numbers Pin
Som Shekhar15-May-10 5:15
Som Shekhar15-May-10 5:15 
GeneralRe: Unique number from two numbers [modified] Pin
harold aptroot15-May-10 5:21
harold aptroot15-May-10 5:21 
Yes, but the width of the result will be at least as much as the sum of the widths of the inputs (proof below). Which is why every way to do this will suck in practice.

For example you could interleave the bits of the inputs, spreading x to the even bits of the result and y to the odd bits.
Or you could (but this sucks) take the product of the x-th and y-th prime numbers.

(this is not really a formal proof, but close)
Proof that #f(x,y) >= #z+#y
Let #x denote the size of x in bits.
Assume f(x,y) is unique for every pair x,y and #f(x,y) < #z+#y
Then 2^#f(x,y) < 2^(#z+#y) (where ^ denoted exponentiation)
Since there are less possible outcomes than there are inputs, at least one output must correspond to multiple inputs.
f(x,y) is not unique for at least one pair x,y so the assumption must be false.
Therefore #f(x,y) >= #x+#y

Instead of bits you could use any other base, just replace the 2 later on.

modified on Saturday, May 15, 2010 11:33 AM

GeneralRe: Unique number from two numbers Pin
Luc Pattyn15-May-10 5:34
sitebuilderLuc Pattyn15-May-10 5:34 
GeneralRe: Unique number from two numbers Pin
harold aptroot15-May-10 5:37
harold aptroot15-May-10 5:37 
GeneralRe: Unique number from two numbers Pin
Luc Pattyn15-May-10 5:40
sitebuilderLuc Pattyn15-May-10 5:40 
GeneralRe: Unique number from two numbers Pin
theCPkid15-May-10 5:47
theCPkid15-May-10 5:47 
GeneralRe: Unique number from two numbers Pin
harold aptroot15-May-10 5:49
harold aptroot15-May-10 5:49 
GeneralRe: Unique number from two numbers Pin
Luc Pattyn15-May-10 5:53
sitebuilderLuc Pattyn15-May-10 5:53 
GeneralRe: Unique number from two numbers Pin
theCPkid15-May-10 5:41
theCPkid15-May-10 5:41 
GeneralRe: Unique number from two numbers Pin
harold aptroot15-May-10 5:43
harold aptroot15-May-10 5:43 
GeneralRe: Unique number from two numbers Pin
Luc Pattyn15-May-10 6:00
sitebuilderLuc Pattyn15-May-10 6:00 
GeneralRe: Unique number from two numbers Pin
CPallini18-May-10 1:52
mveCPallini18-May-10 1:52 
GeneralRe: Unique number from two numbers Pin
CPallini17-May-10 22:37
mveCPallini17-May-10 22:37 
GeneralRe: Unique number from two numbers Pin
theCPkid18-May-10 1:39
theCPkid18-May-10 1:39 
GeneralRe: Unique number from two numbers Pin
CPallini18-May-10 1:45
mveCPallini18-May-10 1:45 
QuestionSocket message(frame) pattern matching Pin
Hamed Musavi13-May-10 7:42
Hamed Musavi13-May-10 7:42 
AnswerRe: Socket message(frame) pattern matching Pin
Luc Pattyn13-May-10 7:55
sitebuilderLuc Pattyn13-May-10 7:55 
GeneralRe: Socket message(frame) pattern matching Pin
Hamed Musavi13-May-10 8:21
Hamed Musavi13-May-10 8:21 
GeneralRe: Socket message(frame) pattern matching Pin
Luc Pattyn13-May-10 8:31
sitebuilderLuc Pattyn13-May-10 8:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.