20
0
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
4
For future reference, confusion and misunderstandings like this can often be avoided by posting challenge ideas in the sandbox first, where you can get feedback from the community before people start solving your challenge.
– Martin Ender – 2016-09-27T07:53:28.003@Ajay Since there was still some confusion about the specification I have edited the challenge once more with what I think was your intent behind this challenge. I hope I didn't misinterpret it, but do let me know if I got anything wrong. – Martin Ender – 2016-09-27T16:59:45.157
@MartinEnder the new test case should be
536870913,67108865,134217729,1,268435457
– Jörg Hülsermann – 2016-09-27T17:19:30.937@JörgHülsermann Feel free to add that as well, but my intention was to add a test case that covers
N = 30
as one of the input values. – Martin Ender – 2016-09-27T17:26:24.167Even if badly exposed, it's really a good challenge. Well done Ajay (and thanks @Martin) – edc65 – 2016-09-27T20:21:38.210
Is
3,33,65,129,257
a possible input? – Titus – 2016-09-27T22:54:42.343@Titus I'd say yes. What's wrong with it? – edc65 – 2016-09-27T23:07:15.087
Nothing; but I think You should have a test case where the injected value is
2**n+1
and the min value. – Titus – 2016-09-27T23:16:52.720If the integers in the series are contiguous, it should be just as easy to include the integer that was replaced, as well as the impostor. Anyone think it'd be easy to mod their code for this? – jaxter – 2016-09-28T01:02:35.350
What if all of the integers are valid, e.g. your test case "65,129,257,513,4097"? – None – 2016-09-28T03:03:16.043
@MartinEnder Yep, you got the challenge right. Thanks for the edit. And, sorry everyone for posting it in a bad way. I'll try to post these challenge in sandbox from now on. – Ajay – 2016-09-28T05:02:01.483
@Snowman the five value aren't contiguous. 4097 is the odd one out. – Martin Ender – 2016-09-28T05:18:40.690
@edc65 The inputs are generated by taking 5 contiguous values and replacing one of those with an invalid one. In that test case
134217729
was replaced (just like in the third test case9
was replaced and in the fourth one17
). – Martin Ender – 2016-09-28T08:25:13.0201An interesting challenge because it's so easy to come up with wrong algorithms. And indeed I've never seen so many incorrect answers posted. It would have been even worse if duplicates were allowed (many set based methods (including mine) would fail) – Ton Hospel – 2016-09-28T08:52:38.787
easy...just
return https://goo.gl/P9RUdN
28 bytes xD – Mario Garcia – 2016-09-28T12:24:48.823Could you add
1 3 5 9 17
(in some order) as a testcase ? It's a sequence of five2^N+1
without breaks, but 1 is not in the original set so33
has been replaced by1
which is the odd one out – Ton Hospel – 2016-09-28T14:35:13.223