Click here to Skip to main content
15,917,645 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: Not Cobol Pin
riced18-Dec-08 13:27
riced18-Dec-08 13:27 
GeneralRe: Not Cobol Pin
Luc Pattyn18-Dec-08 13:39
sitebuilderLuc Pattyn18-Dec-08 13:39 
GeneralRe: Question from my Phone Interview Pin
leonej_dt15-Dec-08 13:33
leonej_dt15-Dec-08 13:33 
AnswerFinding an extra/missing number Pin
supercat918-Dec-08 9:56
supercat918-Dec-08 9:56 
GeneralRe: Question from my Phone Interview Pin
Luc Pattyn18-Dec-08 13:15
sitebuilderLuc Pattyn18-Dec-08 13:15 
GeneralRe: Finding several extra/missing numbers Pin
Luc Pattyn19-Dec-08 1:28
sitebuilderLuc Pattyn19-Dec-08 1:28 
GeneralRe: Finding several extra/missing numbers Pin
supercat919-Dec-08 7:00
supercat919-Dec-08 7:00 
GeneralRe: Finding several extra/missing numbers Pin
Luc Pattyn19-Dec-08 7:25
sitebuilderLuc Pattyn19-Dec-08 7:25 
You could replace 65521 (the largest prime in range) by 65413 (the next prime) with the same result, forgoing the extra counters/flags. Intuitively I agree summing powers mod prime would hold all the information, and extracting it seems not obvious.

However IMO all that is way too complex. Here is mine:

you can accumulate the sum, that's good enough for 1 missing/extra number.

For two numbers, you can accumulate the sum and also the product, like so:
- threat zero separately (with a simple flag);
- use a double ("d0") to multiply all numbers from 1 to 65535
- use a double ("d2") to multiply all numbers present
- rescale both to prevent overflow (say divide both by 65536 each time d0 exceeds 65536)
- finally divide d0 by d2 (or d2 by d0) to get the product.
- even though d0 and d2 are both inaccurate (they lost most of the digits), their quotient
accurately represents the product of the missing (or extra) numbers.
With a 32-bit mantissa you can discriminate all possible products that have the same sum, the
extreme case is 65532*65535 against 65533*65534.
Having sum and product, a simple equation generates the two numbers.

For three numbers (say x y z):
- accumulate the sum x+y+z
- accumulate the product xyz
- accumulate the product (x+1)(y+1)(z+1)
- the products need 48-bit mantissa, a double still is OK
- a simple substitution yields xy+yz+zx
From these three (xyz, , xy+yz+zx, z+y+z) you can find x, y and z either analytically,
or by trial-and-error: just try all possible values of z (1..65535), and solve what remains
for x and y. Most z values will have no solution, you end up finding six permutations of the
one real solution.

For four numbers, you need a 64-bit mantissa, which a double does not offer; so you need a higher-
precision math package. Then accumulate products and two shifted products, in the end leading to
a fourth-order set of equations for which I haven't figured out yet if there is an acceptable
way to solve it.

Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

Fixturized forever. Confused | :confused:


GeneralRe: Finding several extra/missing numbers Pin
supercat919-Dec-08 8:56
supercat919-Dec-08 8:56 
GeneralRe: Finding several extra/missing numbers Pin
Luc Pattyn19-Dec-08 9:36
sitebuilderLuc Pattyn19-Dec-08 9:36 
GeneralRe: Finding several extra/missing numbers Pin
supercat921-Dec-08 12:28
supercat921-Dec-08 12:28 
GeneralRe: Finding an extra/missing number Pin
cp987619-Dec-08 11:46
cp987619-Dec-08 11:46 
GeneralRe: Finding an extra/missing number Pin
Luc Pattyn19-Dec-08 12:48
sitebuilderLuc Pattyn19-Dec-08 12:48 
GeneralRe: Finding an extra/missing number Pin
supercat920-Dec-08 15:57
supercat920-Dec-08 15:57 
GeneralRe: Finding an extra/missing number [modified] Pin
cp987621-Dec-08 13:58
cp987621-Dec-08 13:58 
GeneralRe: Finding an extra/missing number Pin
supercat922-Dec-08 9:58
supercat922-Dec-08 9:58 
GeneralRe: Finding an extra/missing number Pin
Mark Churchill22-Dec-08 18:55
Mark Churchill22-Dec-08 18:55 
GeneralRe: Finding an extra/missing number Pin
supercat923-Dec-08 6:55
supercat923-Dec-08 6:55 
GeneralRe: Finding an extra/missing number Pin
stevepqr8-Jan-09 5:59
stevepqr8-Jan-09 5:59 
AnswerRe: Question from my Phone Interview Pin
C Change25-Jan-09 0:55
C Change25-Jan-09 0:55 
QuestionWhat is Combinatorial Optimization? Pin
alexdow13-Dec-08 9:39
alexdow13-Dec-08 9:39 
AnswerRe: What is Combinatorial Optimization? Pin
Alan Balkany15-Dec-08 3:57
Alan Balkany15-Dec-08 3:57 
QuestionSome kind of LCS Pin
aggressorus9-Dec-08 7:22
aggressorus9-Dec-08 7:22 
Questionhelp me About Big O Pin
bosszy7-Dec-08 2:00
bosszy7-Dec-08 2:00 
GeneralRe: help me About Big O Pin
Luc Pattyn7-Dec-08 6:32
sitebuilderLuc Pattyn7-Dec-08 6:32 

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.