The Challenge:
Consider the function F(N) = 2^N + 1
where N
is a positive integer less than 31
. The sequence defined by this function is:
3, 5, 9, 17, 33, 65, 129, 257, 513, 1025, 2049, 4097, 8193, 16385, 32769, 65537, 131073, 262145, 524289, 1048577, 2097153, 4194305, 8388609, 16777217, 33554433, 67108865, 134217729, 268435457, 536870913, 1073741825
An input will be generated as follows:
- Take 5 contiguous integers from the above sequence.
- Replace one of them with a different, positive integer (which may or may not be part of the above sequence).
- Optionally reorder the the 5 resulting numbers.
Given such a list of 5 integers, find the one that was swapped in and is therefore not part of the original 5 contiguous integers.
Example:
- Original sublist:
5, 9, 17, 33, 65
. - Replace one:
5, 7, 17, 33, 65
. - Reorder:
33, 17, 5, 7, 65
.
The expected output would be 7
.
The 5 values in the input will always be distinct and there will always be a unique solution. (For instance, you won't have to deal with inputs like 3, 9, 17, 33, 129
where either 3
or 129
might have been swapped in.)
Test Cases:
5,9,17,33,829
o/p: 829
9,5,17,829,33
o/p: 829
33, 17, 5, 7, 65
o/p: 7
5,9,177,33,65
o/p: 177
65,129,259,513,1025
o/p: 259
129,259,513,1025,65
o/p: 259
63,129,257,513,1025
o/p: 63
65,129,257,513,4097
o/p: 4097
5, 9, 2, 17, 33
o/p: 2
536870913, 67108865, 1073741825, 1, 268435457
o/p: 1
536870913,67108865,134217729,1,268435457
\$\endgroup\$N = 30
as one of the input values. \$\endgroup\$