Inverting Gauss’ Formula
blog.demofox.org
Inverting Gauss’ Formula
1–10 of 17 posts
Re: Inverting Gauss’ Formula
#2 #include "stdio.h"
#include "math.h"
#include "stdint.h"
/*integer sqrt from libopus*/
unsigned isqrt32(uint32_t _val){
unsigned b;
unsigned g;
int bshift;
g=0;
bshift=((32-__builtin_clz(_val))-1)>>1;
b=1U>=1;
bshift--;
}
while(bshift>=0);
return g;
}
int InverseGaussSumInt(uint32_t sum)
{
return (isqrt32(8*sum+1)-1)>>1;
}
int InverseGaussSum(int sum)
{
return (int)floor(sqrt(2.0f * (float)sum + 0.25) - 0.5f);
}
int GaussSum(int N)
{
return N * (N + 1) / 2;
}
int main(void){
int i;
int eint=0;
int efloat=0;
/*GaussSum(65535/2)==(2^32-1)/8*/
for(i=0;i
The first error in the article's function is at 5793 for me, but I wouldn't be confident that platform/compiler/optimization differences changed the behavior somewhat.Re: Inverting Gauss’ Formula
#3I found the use of floating point dubious, it only took me a minute to eliminate it, most of which was spent finding and pasting an integer square root :). #include "stdio.h" #include "math.h" #include "stdint.h" /*integer sqrt from libopus*/ unsigned isqrt32(uint32_t _val){ unsigned b; unsigned g; int bshift; g=0; bshift=((32-__builtin_clz(_val))-1)>>1; b=1U >=1; bshift--; } while(bshift>=0); return g; } int Inverse…
Re: Inverting Gauss’ Formula
#4Re: Inverting Gauss’ Formula
#5He told me they are using such an algorithm in some of their products and he picks the brain of potential hires to see if they find a more elegant way of doing so. Left a great impression, he really cared about thought processes and communicating! (I didn't end up taking the job for reasons unrelated to the company or the offer.)
Re: Inverting Gauss’ Formula
#6A while back I interviewed with a networking company in the bay area and one of the things the interviewer asked me do was to devise an algorithm to walk the fully connected graph without visiting any edge twice if possible. Was a nice problem to discuss, he moved me along nicely in my thought process and we eventually reached a recursive solution. So the length of this walk is basically this formula. He told me they…
Re: Inverting Gauss’ Formula
#7If you have young kids (6 or 7) who understand multiplication and like math, Gauss's formula is such a magical thing to show them, because it seems like it'd be impossible to shortcut adding up all those numbers that way, on the surface, and it's such an easy thing to prove visually.
Re: Inverting Gauss’ Formula
#8If you have young kids (6 or 7) who understand multiplication and like math, Gauss's formula is such a magical thing to show them, because it seems like it'd be impossible to shortcut adding up all those numbers that way, on the surface, and it's such an easy thing to prove visually.
Re: Inverting Gauss’ Formula
#9A while back I interviewed with a networking company in the bay area and one of the things the interviewer asked me do was to devise an algorithm to walk the fully connected graph without visiting any edge twice if possible. Was a nice problem to discuss, he moved me along nicely in my thought process and we eventually reached a recursive solution. So the length of this walk is basically this formula. He told me they…
Isn't the length of the walk the number of edges?
Re: Inverting Gauss’ Formula
#10If you have young kids (6 or 7) who understand multiplication and like math, Gauss's formula is such a magical thing to show them, because it seems like it'd be impossible to shortcut adding up all those numbers that way, on the surface, and it's such an easy thing to prove visually.