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

Algorithms

 
GeneralRe: fast division algoirthm Pin
harold aptroot22-Jun-13 10:32
harold aptroot22-Jun-13 10:32 
GeneralRe: fast division algoirthm Pin
khomeyni22-Jun-13 23:19
khomeyni22-Jun-13 23:19 
GeneralRe: fast division algoirthm Pin
harold aptroot23-Jun-13 1:42
harold aptroot23-Jun-13 1:42 
GeneralRe: fast division algoirthm Pin
khomeyni2-Jul-13 2:42
khomeyni2-Jul-13 2:42 
GeneralRe: fast division algoirthm Pin
harold aptroot2-Jul-13 3:11
harold aptroot2-Jul-13 3:11 
GeneralRe: fast division algoirthm Pin
khomeyni2-Jul-13 8:58
khomeyni2-Jul-13 8:58 
GeneralRe: fast division algoirthm Pin
harold aptroot2-Jul-13 9:44
harold aptroot2-Jul-13 9:44 
QuestionAlgorithm Sum From Offset To Number Pin
A*****17-Jun-13 12:37
A*****17-Jun-13 12:37 
I was using code similar to the following to calculate the sum from offset(where offset >=0) to length:

int offset = 2;
int length = 364;

float sum = 0.0f;

for(int i= offset; i<=length; i++)
{
    sum += (float) i;
}


However this seemed a naïve approach so I worked out(from the algorithm for sum (0 to number) that I could use the following:
where
f=offset
n=length

sum = ((1+n) * (n/2.0)) - ((1+f) * (f/2.0) - f)

which seems to give the correct answer.


Out of curiosity what algorithm would normally be used for this kind of thing?
My blog:[^]

AnswerRe: Algorithm Sum From Offset To Number Pin
A*****17-Jun-13 17:07
A*****17-Jun-13 17:07 
GeneralRe: Algorithm Sum From Offset To Number Pin
dusty_dex17-Jun-13 23:03
dusty_dex17-Jun-13 23:03 
GeneralRe: Algorithm Sum From Offset To Number[Edited] Pin
A*****18-Jun-13 12:50
A*****18-Jun-13 12:50 
GeneralRe: Algorithm Sum From Offset To Number[Edited] Pin
dusty_dex18-Jun-13 13:20
dusty_dex18-Jun-13 13:20 
GeneralRe: Algorithm Sum From Offset To Number[Edited] Pin
A*****18-Jun-13 13:24
A*****18-Jun-13 13:24 
AnswerRe: Algorithm Sum From Offset To Number Pin
Bernhard Hiller18-Jun-13 20:57
Bernhard Hiller18-Jun-13 20:57 
GeneralRe: Algorithm Sum From Offset To Number Pin
dusty_dex18-Jun-13 22:38
dusty_dex18-Jun-13 22:38 
QuestionWikipedia's comments on Interpolation Search Pin
harold aptroot11-Jun-13 0:59
harold aptroot11-Jun-13 0:59 
AnswerRe: Wikipedia's comments on Interpolation Search Pin
Alan Balkany13-Jun-13 8:27
Alan Balkany13-Jun-13 8:27 
GeneralRe: Wikipedia's comments on Interpolation Search Pin
harold aptroot13-Jun-13 8:59
harold aptroot13-Jun-13 8:59 
Questionalgorithm that finds the m smallest numbers in a list of numbers Pin
demo 29-Jun-13 21:00
demo 29-Jun-13 21:00 
AnswerRe: algorithm that finds the m smallest numbers in a list of numbers Pin
Richard MacCutchan9-Jun-13 21:14
mveRichard MacCutchan9-Jun-13 21:14 
GeneralRe: algorithm that finds the m smallest numbers in a list of numbers Pin
demo 29-Jun-13 23:50
demo 29-Jun-13 23:50 
GeneralRe: algorithm that finds the m smallest numbers in a list of numbers Pin
Richard MacCutchan9-Jun-13 23:53
mveRichard MacCutchan9-Jun-13 23:53 
GeneralRe: algorithm that finds the m smallest numbers in a list of numbers Pin
demo 210-Jun-13 0:07
demo 210-Jun-13 0:07 
GeneralRe: algorithm that finds the m smallest numbers in a list of numbers Pin
Richard MacCutchan10-Jun-13 0:13
mveRichard MacCutchan10-Jun-13 0:13 
GeneralRe: algorithm that finds the m smallest numbers in a list of numbers Pin
demo 210-Jun-13 0:24
demo 210-Jun-13 0:24 

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.