Fog Creek Software
Discussion Board




Sum it up solution

How about  xor ing each number with the next.  When the ones bit doesn't change - you  have the extra number.  Works in both cases.

Tom Hopkins
Monday, January 03, 2005

You could also loop the numbers and always substract the current number (n) from the previous (m), and if n-m would equal zero then n is the repeater. Works with both sets, and also if there were any number of repeating numbers.

MP
Tuesday, January 04, 2005

What if you are not guaranteed that the numbers are in order?  My guess is that is what the problem intended, even though the example set is ordered.

Will Smith
Friday, January 14, 2005

*  Recent Topics

*  Fog Creek Home