Skip to content

Instantly share code, notes, and snippets.

View ltbringer's full-sized avatar
💭
😸 I overthink so that you don't have to.

ltbringer ltbringer

💭
😸 I overthink so that you don't have to.
View GitHub Profile
'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)