Click here to Skip to main content
15,893,588 members
Home / Discussions / Algorithms
   

Algorithms

 
QuestionNeed a Classified Ad Aggregator Algorithm Pin
Beyslist114-Nov-12 17:14
Beyslist114-Nov-12 17:14 
Questionfinding the best algorithm Pin
speedchandu20-Oct-12 11:32
speedchandu20-Oct-12 11:32 
AnswerRe: finding the best algorithm Pin
Alan Balkany22-Oct-12 5:00
Alan Balkany22-Oct-12 5:00 
GeneralRe: finding the best algorithm Pin
speedchandu22-Oct-12 20:12
speedchandu22-Oct-12 20:12 
GeneralRe: finding the best algorithm Pin
_Kel_22-Oct-12 23:36
_Kel_22-Oct-12 23:36 
GeneralRe: finding the best algorithm Pin
AshrafKawarezmey14-Nov-12 4:57
AshrafKawarezmey14-Nov-12 4:57 
AnswerRe: finding the best algorithm Pin
YvesDaoust22-Oct-12 21:41
YvesDaoust22-Oct-12 21:41 
AnswerRe: finding the best algorithm Pin
YvesDaoust22-Oct-12 22:11
YvesDaoust22-Oct-12 22:11 
More seriously, an easy option is to work in base 1 billion, using an array of integers. Every integer will store 9 significant decimal digits.

It is a rather straightforward matter to implement a doubling algorithm, by means of long addition, as in the following quick Python code.
C++
N= [0] * (Digits - 1) + [1]                     # Large number representation of 1
for Exponent in range(2000):                    # Double 2000 times
    for Position in range(Digits):              # For all digits
        N[Position]= 2 * N[Position]            # Double this digit
        if N[Position] >= Base:                 # Detect carry out
            N[Position]-= Base                  # Adjust the digit...
            N[Position - 1]+= 1                 # ... and carry out to the left one
print N

Output:
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 114813069, 527425452, 423283320, 117768198, 402231770, 208869520, 47764273, 682576626, 139237031, 385665948, 631650626, 991844596, 463898746, 277344711, 896086305, 533142593, 135616665, 318539129, 989145312, 280000688, 779148240, 44871428, 926990063, 486244781, 615463646, 388363947, 317026040, 466353970, 904996558, 162398808, 944629605, 623311649, 536164221, 970332681, 344168908, 984458505, 602379484, 807914058, 900934776, 500429002, 716706625, 830522008, 132236281, 291761267, 883317206, 598995396, 418127021, 779858404, 42159853, 183251540, 889433902, 91920554, 957783589, 672039160, 81957216, 630582755, 380425583, 726015528, 348786419, 432054508, 915275783, 882625175, 435528800, 822842770, 817965453, 762184851, 149029376]

In reality, this algorithm uses a trick: a carry-in to a digit (from the right) will never cause a carry-out (to the left). This is because the doubled digits are even, at most 999999998, and can stand one incrementation. This allows us to process left-to-right. This property doesn't hold for plain addition where carries can propagate further.

A more efficient but a little more complex solution can be achieved by using a base conversion algorithm.

modified 3-Dec-12 6:44am.

GeneralRe: finding the best algorithm Pin
Peter_in_27802-Dec-12 14:45
professionalPeter_in_27802-Dec-12 14:45 
GeneralRe: finding the best algorithm Pin
YvesDaoust2-Dec-12 20:59
YvesDaoust2-Dec-12 20:59 
GeneralRe: finding the best algorithm Pin
Peter_in_27802-Dec-12 23:34
professionalPeter_in_27802-Dec-12 23:34 
GeneralRe: finding the best algorithm Pin
YvesDaoust3-Dec-12 0:15
YvesDaoust3-Dec-12 0:15 
GeneralRe: finding the best algorithm Pin
YvesDaoust2-Dec-12 21:40
YvesDaoust2-Dec-12 21:40 
QuestionSplitting up multiple readings... Pin
glennPattonWork39-Oct-12 0:50
professionalglennPattonWork39-Oct-12 0:50 
GeneralRe: Splitting up multiple readings... Pin
harold aptroot9-Oct-12 0:57
harold aptroot9-Oct-12 0:57 
GeneralRe: Splitting up multiple readings... Pin
glennPattonWork39-Oct-12 1:27
professionalglennPattonWork39-Oct-12 1:27 
GeneralRe: Splitting up multiple readings... Pin
harold aptroot9-Oct-12 1:35
harold aptroot9-Oct-12 1:35 
GeneralRe: Splitting up multiple readings... Pin
Pete O'Hanlon9-Oct-12 2:05
mvePete O'Hanlon9-Oct-12 2:05 
GeneralRe: Splitting up multiple readings... Pin
glennPattonWork39-Oct-12 2:36
professionalglennPattonWork39-Oct-12 2:36 
GeneralRe: Splitting up multiple readings... Pin
Pete O'Hanlon9-Oct-12 2:45
mvePete O'Hanlon9-Oct-12 2:45 
GeneralRe: Splitting up multiple readings... Pin
Jochen Arndt9-Oct-12 3:09
professionalJochen Arndt9-Oct-12 3:09 
GeneralRe: Splitting up multiple readings... Pin
glennPattonWork39-Oct-12 4:34
professionalglennPattonWork39-Oct-12 4:34 
GeneralRe: Splitting up multiple readings... Pin
Jochen Arndt9-Oct-12 4:45
professionalJochen Arndt9-Oct-12 4:45 
GeneralRe: Splitting up multiple readings... Pin
glennPattonWork39-Oct-12 5:15
professionalglennPattonWork39-Oct-12 5:15 
GeneralRe: Splitting up multiple readings... Pin
Jochen Arndt9-Oct-12 5:55
professionalJochen Arndt9-Oct-12 5:55 

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.