|Subject||Re: Problem with quotes|
> ((m*m+1)-(n*n+1))/2Adam, sorry it doesn't work for me. :)
> I am sure we can optimise the divide by 2 with a right shift op ;)
lets check for some numbers, between 6 and 12 for example
(145-37)/2 = 54
the correct calculation is:
((12*12+12)-(5*5+5))/2 = (156-30)/2 = 63
There is 63-54 non standart devision from exact result. ;)
(n*(n+1))/2 = (n*n+n)/2 -- eliminate one of literal operands
we need here sum of numbers from 1 to 12 minus 1 to 5.
there are two solution in my mind:
(there may be more shorter than them, i m not a mathmatician :P )
1) ((m*m+m)-(n*n+n))/2 + n
bit shifting also has no so much advantage here i think.
(we should refer to CPU's referance books to find out
clock cycles cost of both )
I wasn't intend to create a polemic here.
I mean, programming is an art, the art of science.
it is independent from any coding language,
language is the outer-face of programming not the brain/spirit.
So, programmers are should be the cleverst-creative people,
not the drag dropper, copy paster or asprinist doctor.
We were worked in heavy conditions in old days,
slower CPUs ( a few mhz), limited RAM (at KB level), DISK(some MB),
Today there is GHZ machines, GB, TB DISCs, GB RAMs, etc..
This shouldn't be to create unawered programmers.
Programming is not a job for the people hope to find a job.
When i ask this question, most of programmers start to write
some program with different loop versios without any design or think.
computers as successful as their programmers.
Bosses don't understand the differences between programmers and real-
programmers, and they will prefer only programmers in todays world,
because they are fast coder. And bosses knows them as they no need to
think, coding is enough to programming the computers.
If i must to solve a problem with coding i must to solve it in my
brain and must to get the perfect result before coding. i don't
think via commands or codes.
There is a lot of language in this planet, but every people have
poems, arts, etc..
All english speakers are not computer engineer because of they speak
in english, all right?
if we are using SQL, it doesn't mean we shouldn't wot know how
computers work, engines work etc.. we must to know if we want to be
real-expert of it.
if we can aware of computer internals and science then
we know that:
some long codes doesn't mean they are slow or bad,
some shortes codes doesn't mean they are fastest or finest.
Sorry Helen, you can fire me because of noise if you want.