Created
April 30, 2011 22:43
-
-
Save jessemcdowell/950058 to your computer and use it in GitHub Desktop.
JessesAverage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int JessesAverage(int a, int b) | |
{ | |
return (a / 2) + (b / 2) + (((a % 2) + (b % 2)) / 2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.