Perl Weekly Challenge 55: Binary Numbers and Wave Arrays
These are some answers to the Week 55 of the Perl Weekly Challenge organized by Mohammad S. Anwar.
Task # 1: Flipping Binary Numbers
You are given a binary number B, consisting of N binary digits 0 or 1: s0, s1, …, s(N-1).
Choose two indices L and R such that 0 ≤ L ≤ R < N and flip the digits s(L), s(L+1), …, s(R). By flipping, we mean change 0 to 1 and vice-versa.
For example, given the binary number 010, the possible flip pair results are listed below:
L=0, R=0 the result binary: 110
L=0, R=1 the result binary: 100
L=0, R=2 the result binary: 101
L=1, R=1 the result binary: 000
L=1, R=2 the result binary: 001
L=2, R=2 the result binary: 011