Skip to content

Instantly share code, notes, and snippets.

@jessemcdowell
Created April 30, 2011 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jessemcdowell/950058 to your computer and use it in GitHub Desktop.
Save jessemcdowell/950058 to your computer and use it in GitHub Desktop.
JessesAverage
int JessesAverage(int a, int b)
{
return (a / 2) + (b / 2) + (((a % 2) + (b % 2)) / 2);
}
@jessemcdowell
Copy link
Author

The first revision was what I proposed originally in my interview. After someone pointed out that it had a problem with Average(1, 1) I revised it to the second revision with the sum of the moduli.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment