Solved LeetCode program · 780 of 1,000
#1016 · Binary String With Substrings Representing 1 To N
Original English source
Keep a shared source as empty text. Keep a shared parts as an empty list of text. Keep a shared encoded as empty text. Keep a shared found of 0. Keep a shared powers as an empty list of whole numbers. Keep a shared limit of 0.
To erase.
Repeat while the last position of parts is at least 0.
Remove the last item from parts.
To encode from number (a whole number) with power (a whole number). The rest is number.
Repeat while power is more than 0.
The bit is 0. If rest is at least power, set bit to 1, set rest to rest minus power. The piece is format whole number bit as text. Place piece into parts. Set power to power divided by 2.
To assemble. Set found to 0. Set encoded to join parts with "".
To seek from marker (a whole number). The lastpiece is the last position of encoded. The size is lastpiece plus 1. The lastsource is the last position of source. The endmark is lastsource plus 1. The final is endmark minus size plus 1.
For every start from 0 to final.
The piece is the slice of source from start to start plus size. If piece is encoded, set found to 1.
Set limit to 3. Place "0110" into source. The powers is a list of 4 zeros. Set item 1 of powers to 1.
For every number from 1 to limit.
The power is 1.
Repeat while power times 2 is at most number.
Set power to power times 2. If power times 2 is more than number, set item number of powers to power.
The valid is 1.
For every number from 1 to limit.
The power is item number of powers. Erase. Encode from number with power. Assemble. Seek from 0. If found is 0, set valid to 0.
If valid is 1, show true, otherwise show false.
Expected stdout
true