This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/* | |
* given a string of bits such as 100100, calculate the number of steps required to convert | |
* the string to 000000 using the following rules: | |
* a bit may be flipped only if it is following immediately by a one, followed only by zeroes | |
* the far-right bit may be toggled freely | |
* | |
* examples: 111 -> 110 -> 010 -> 011 -> 001 -> 000 (score 5) | |
* 1101 -> 1100 -> 0100 -> 0101 -> 0111 -> 0100 -> 0010 -> 0011 -> 0001 -> 0000 (score 9) |