23
Given a binary number A as input with d > 1 digits, output a binary number B with d digits according to the following rules for finding the nth digit of B:
The first digit of B is zero if the first and second digits of A are equal; otherwise, it is one.
If 1 < n < d, then if the (n-1)th, nth and (n+1)th digits of A are equal, then the nth digit of B is zero; otherwise, it is one.
The dth digit of B is zero if the (d-1)th and dth digits of A are equal; otherwise, it is one.
Rules
String/list input/output format is fine. Another allowed way of input/output is an integer followed by the number of preceding zeros (or following the number of preceding zeros).
Make your code as short as possible.
Test Cases
00 -> 00
01 -> 11
11 -> 00
010111100111 -> 111100111100
1000 -> 1100
11111111 -> 00000000
01010101 -> 11111111
1100 -> 0110
You should have waiting 10 more minutes, then you would have got a hat. Nice challenge though!
– caird coinheringaahing – 2017-12-14T20:59:17.973@cairdcoinheringaahing I remember those last year... oh, well. :-( – 0WJYxW9FMN – 2017-12-14T21:00:16.407
2Suggested test case:
1100 -> 0110
(the first 2 digits of the output are always identical in all other test cases; ditto for the last 2 digits) – Arnauld – 2017-12-15T09:15:40.650It's nice to see that no downvotes have been cast on this challenge or on its twenty-five answers. Well done, everyone! – 0WJYxW9FMN – 2017-12-29T19:21:33.570