21
4
FizzBuzz is so simple, bet you can do it backwards. In this challenge, you will be given the length of the FizzBuzz string and must give the positive integer that produced that string.
Description
To break this down, a FizzBuzz string for n
is generated by the following algorithm.
Start with an empty string and, for every i=1..n
(inclusive):
- If
i
is divisible by3
and by5
, appendFizzBuzz
to the string. - If
i
is just divisible by3
appendFizz
. - If
i
is just divisible by5
appendBuzz
. - If
i
is divisible by neither, append the decimal representation ofi
.
So for example FizzBuzz(15)
is the following:
12Fizz4BuzzFizz78FizzBuzz11Fizz1314FizzBuzz
You will be given Length(FizzBuzz(n))
and must determine n
. You may assume that the input is positive and is always going to be the length of some FizzBuzz string.
Rules
Your solution may a complete program or a function definition in any standardly acceptable language. Your program/function may take in arguments and return answers in any standardly accepted way. Standard loopholes are forbidden.
You may assume that the input is positive and valid (describes the length of some FizzBuzz string) and is smaller than the largest integer representable natively in your language.
This is code golf, so shortest byte-count wins.
Examples
Here are some example cases
Length(FizzBuzz(n)) -> n
1 -> 1
6 -> 3
15 -> 6
313 -> 100
3677 -> 1001
Edit
Fixed last test case. Thanks @SteadyBox.
Argh! I tried to do recursion but my numbers were too big... – 0WJYxW9FMN – 2017-02-21T21:09:53.237
Related. Related. – Digital Trauma – 2017-02-21T21:19:14.397
3@Toto How is this a duplicate? – AdmBorkBork – 2017-02-22T13:30:59.683
1@Toto This is not at all a duplicate. Maybe you should read up on what being a duplicate means. – mbomb007 – 2017-02-22T14:34:50.753