[Question]
  [
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): 
1. If `i` is divisible by `3` and by `5`, append `FizzBuzz` to the string.
2. If `i` is just divisible by `3` append `Fizz`.
3. If `i` is just divisible by `5` append `Buzz`.
4. If `i` is divisible by neither, append the decimal representation of `i`.
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](http://meta.codegolf.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods?answertab=votes#tab-top). 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.
  
[Answer]
# C, ~~81~~ 78 bytes
```
l,i;f(n){for(l=i=0;l<n;l+=++i%3?i%5?snprintf(0,0,"%d",i):4:i%5?4:8);return i;}
```
**68 bytes** if you don't mind converting to `double` and back:
```
l,i;f(n){for(l=i=0;l<n;l+=++i%3?i%5?log10(i)+1:4:i%5?4:8);return i;}
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~16~~ 14 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
2 bytes saved using more recent language features `)` for `µ€` and `Ä` for `+\`
```
3,5ḍS×4oDL$)Äi
```
**[Try it online!](https://tio.run/##y0rNyan8/99Yx/Thjt7gw9NN8l18VDQPt2T@BwqamZsDAA)** or see the [test cases](https://tio.run/##ATUAyv9qZWxsef//Myw14biNU8OXNG9ETCQpw4Rp/8W8w4figqxH//9bMSw2LDE1LDMxMywzNjc3XQ).
### How?
Builds a list of the lengths of every item from `1` to the input, reduces by addition and then finds the one-based index of the input in the list. (This also means an invalid input results in `0`, "not in list").
```
3,5ḍS×4oDL$)Äi - Main link: theLength
           )    - perform the chain to the left for each (€) in
                     implicit range from 1 to the input and
                     pass the result into the monadic chain (µ) to the right
3,5            - 3 paired with 5: [3,5]
   ḍ           - divides?  for a multiple of 15 [1,1]; sum = 2; times 4 = 8
    S          - sum       for a multiple of  5 [0,1]; sum = 1; times 4 = 4
     ×4        - times 4   for a multiple of  3 [1,0]; sum = 1; times 4 = 4
                           for none of those    [0,0]; sum = 0; times 4 = 0
          $    - last two links as a monad
        D      -     to decimal digit list
         L     -     length - e.g. 313 -> [3,1,3] -> 3
       o       - logical or: replace a 0 with the decimal length, keep the 4s and 8s
            Ä  - reduce with addition: e.g. [1,1,4,1, 4, 4, 1, 1, 4, 4, 2, 4, 2 ,2, 8]
                                         -> [1,2,6,7,11,15,16,17,21,25,27,31,33,35,43]
             i - index of theLength in that list (e.g. 15 is at index 6)
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~31~~ ~~28~~ 27 bytes
```
`@:tI5h!\XJA)VXznJ~z4*+G-}@
```
[Try it online!](https://tio.run/nexus/matl#@5/gYFXiaZqhGBPh5agZFlGV51VXZaKl7a5b6/D/v7GhMQA)
### Explanation
```
`        % Do...while
  @:     %   Push array [1 2 ...k], where k is iteration index
  t      %   Duplicate  
  I5h!   %   Push column vector [3; 5]
  \      %   Modulo, with broadcast. Gives 2 × k matrix
  XJ     %   Copy into clipboard J
  A      %   Row vector that contains true for columns that contain two nonzeros
  )      %   Index with that vector. This keeps numbers that are non-fizz/buzz
  V      %   Convert to string. This inserts spaces between numbers
  Xzn    %   Number of nonspace characters
  J      %   Push 2 × k matrix resulting from modulo operation again
  ~z     %   Number of zeros
  4*     %   Multiply by 4. Gives number of characters corresponding to fizz/buzz
  +      %   Add
  G-     %   Subtract input. This is the loop condition: exit if 0
}        % Finally (execute right before exiting loop)
  @      %   Push current iteration index
         % End (implicit)
         % Display (implicit)
```
[Answer]
## Mathematica, 67 bytes
```
(For[n=s=0,s<#,s+=Tr[4Boole[{3,5}∣++n]]/. 0:>IntegerLength@n];n)&
```
This is both faster and shorter than my initial solution:
```
1//.x_/;Sum[Tr[4Boole[{3,5}∣n]]/. 0:>IntegerLength@n,{n,x}]!=#:>x+1&
```
or my desperate attempt to shorten it:
```
(s=0;1)//.x_/;(s+=Tr[4Boole[{3,5}∣x]]/. 0:>IntegerLength@x)!=#:>x+1&
```
## Explanation
Standard `For` loop which increments `n` until `s := Length(FizzBuzz(n))` is at least equal to the input `#`. The only interesting bit is how I calculate the length of the `(n+1)`-th term of the FizzBuzz sequence
```
                ++n                           Preincrement n
          {3,5}∣                              Test for divisibility by 3 and 5 (returns a list)
    Boole[         ]                          Convert True to 1 and False to 0
   4                                          Multiply by 4
Tr[                 ]                         Sum
                     /.                       Replace
                        0                     0 (leading space is necessary or it thinks we are dividing by 0.0)
                         :>                   with
                           IntegerLength@n    the number of digits in n
```
[Answer]
# Java 8, 100 97 bytes
Golfed:
```
l->{int i=0;for(String s="";s.length()<l;)s+=++i%15<1?"12345678":i%5<1||i%3<1?"1234":i;return i;}
```
Ungolfed:
```
import java.util.function.*;
public class HowDidIEndUpWithThisFizzBuzz {
  public static void main(String[] args) {
    for (final int[] data : new int[][] { { 1, 1 }, { 6, 3 }, { 15, 6 },
        { 313, 100 }, { 3677, 1001 } }) {
      final int fizzBuzzLength = data[0];
      final int expected = data[1];
      final int actual = f(l -> {
        int i = 0;
        for (String s = ""; s.length() < l;) {
          s += (++i % 15 < 1 ? "12345678" : (i % 5 < 1 || i % 3 < 1 ? "1234" : i));
        }
        return i;
      } , fizzBuzzLength);
      System.out.println("Length(FizzBuzz(n)) -> " + fizzBuzzLength);
      System.out.println("Expected            -> " + expected);
      System.out.println("Actual              -> " + actual);
      System.out.println();
    }
  }
  private static int f(IntFunction<Integer> function, int fizzBuzzLength) {
    return function.apply(fizzBuzzLength);
  }
}
```
Output:
```
Length(FizzBuzz(n)) -> 1
Expected            -> 1
Actual              -> 1
Length(FizzBuzz(n)) -> 6
Expected            -> 3
Actual              -> 3
Length(FizzBuzz(n)) -> 15
Expected            -> 6
Actual              -> 6
Length(FizzBuzz(n)) -> 313
Expected            -> 100
Actual              -> 100
Length(FizzBuzz(n)) -> 3677
Expected            -> 1001
Actual              -> 1001
```
[Answer]
# MATL, ~~31 30~~ 28 bytes
```
:tI5h!\~s4*t~b10&YlkQ*+YsG=f
```
Uses the same idea as Jonathan Allen's Jelly solution.
Try it on [matl.io](https://matl.io/?code=%3AtI5h%21%5C%7Es4%2At%7Eb10%26YlkQ%2A%2BYsG%3Df&inputs=15&version=19.8.0)!
[Answer]
## JavaScript (ES6), ~~62~~ 57 bytes
```
f=(n,k=0)=>n?f(n-(++k%3?k%5?`${k}`.length:4:k%5?4:8),k):k
```
### Test cases
```
f=(n,k=0)=>n?f(n-(++k%3?k%5?`${k}`.length:4:k%5?4:8),k):k
console.log(f(1   )); // -> 1
console.log(f(6   )); // -> 3
console.log(f(15  )); // -> 6
console.log(f(313 )); // -> 100
console.log(f(3677)); // -> 1001
```
[Answer]
# Javascript (ES6), 56 bytes
```
f=(x,s=i=0)=>s[x]?i:f(x,s+[++i%3?i%5?i:1e3:i%5?1e3:1e7])
```
```
<!-- snippet demo: -->
<input list=l oninput=console.log(f(this.value))>
<datalist id=l><option value=1><option value=6><option value=15><option value=313><option value=3677></datalist>
```
[Answer]
# Ruby, ~~69~~ 66 bytes
```
->n{i=0;(i+=1;n-=i%3>0?i%5>0?i.to_s.size: 4:i%5>0?4:8)while n>0;i}
```
Originally, I was avoiding the nested ternary operator *monstrosity* and got down to 69 bytes:
```
->n{i=0;(i+=1;n-=(x=[i%3,i%5].count 0)>0?4*x:i.to_s.size)while n>0;i}
```
[Answer]
# Python 3, 78 bytes
```
f=lambda i,n=1,s=0:~-n*(s==i)or f(i,n+1,s+(4*((n%3<1)+(n%5<1))or len(str(n))))
```
Recursive function. Will need the recursion limit increased for any result above 1000.
**Explanation:**
```
# i = length of final string
# n = current number in sequence, starting with 1
# s = length of current string, starting with 0
f=lambda i,n=1,s=0: \
# if s==1, this will evaluate to n+1, which is NOT 0, and will return
# else, it will evaluate to (n+1)*0, and trigger the second half of the OR clause
~-n*(s==i)or \
# recursively call the next iteration, with the next number in the sequence
f(i,n+1, \ 
# increase s by 4 if Fizz or Buzz, 8 if FizzBuzz, or len(n) if number
s+(4*((n%3<1)+(n%5<1))or len(str(n))))
```
[Answer]
# Python, 93 bytes
```
def g(n,c=0,a=[4,0]):
 while n:c+=1;s=a[c%3>0]+a[c%5>0];s+=(s<1)*len(str(c));n-=s
 return c
```
[Answer]
# k, 33 bytes
```
{1+&x=+\{(#$x;4;8)+/~3 5!'x}'1+!x}
```
Brief (python-ish) explanation:
```
{                                } / function(x):
                             1+!x  /   array from 1 to x, inclusive
                            '      /   for y in array:
        {                  }       /     function(y):
         (#$x;4;8)                 /       yield [ len(str(y), 4, 8 ][
                  +/~3 5!'x        /         sum([not(y mod 3), not(y mod 5)])
                                   /       ]
      +\                           /   cumulative sum of result of for loop
 1+&x=                             /   get index of x in cumulative sum, add one
```
Example using kmac 2016.06.28:
```
 f:{1+&x=+\{(#$x;4;8)+/~3 5!'x}'1+!x}
 ,/f'1 6 15 313 3677
1 3 6 100 1001
```
[Answer]
# [dc](https://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html), ~~76~~ 70 bytes
```
?sa0dsbsc[lc4+sc]sh[lbZ+sc]so[lcdlb1+ddsb3%0=h5%0=hlc=olcla!=y]dsyxlbp
```
[Try it online!](https://tio.run/nexus/dc#@29fnGiQUpxUnBydk2yiXZwcW5wRnZMUBWblA8VScpIMtVOAKoxVDWwzTEFETrJtfk5yTqKibWVsSnFlRU5Swf//xmbm5l/z8nWTE5MzUgE "dc – TIO Nexus")
[Answer]
# Java 8, ~~95~~ 93 bytes
```
l->{int j=0,i=0;for(;j<l;)j+=++i%15<1?8:i%3<1||i%5<1?4:Math.floor(Math.log10(i)+1);return i;}
```
This is the optimized version of [@Snowman's answer](https://codegolf.stackexchange.com/a/110881/56341)
[Answer]
# Groovy, 76 bytes
`def f(n){i=0;for(s='';s.size()<n;)s+=++i%15<1?"1"*8:i%5<1||i%3<1?"1"*4:i;i;}`
Mostly the same as [@Snowman's answer](https://codegolf.stackexchange.com/a/110881/56341), but uses some Groovy magic/differences to cut down on the byte count.
[Answer]
# [Perl 6](https://perl6.org), ~~55~~ 52 bytes
```
{1+first $_,:k,[\+] map {4*($_%%3+$_%%5)||.chars},1..*}
```
```
{(0,{my \i=++$;$_+(4*(i%%3+i%%5)||i.chars)}...$_)-1}
```
[Try it online!](https://tio.run/nexus/perl6#Ky1OVSgzs@bKrVRQS1Ow/V@tYaBTDeTEZNpqa6tYq8Rra5hoaWSqqhprAwlTzZqaTL3kjMSiYs1aPT09lXhNXcPa/8WJlQppCobWXBCGGYxhaApjGRsaw5lm5ubW/wE "Perl 6 – TIO Nexus")
### How it works
```
{                                                  }  # A lambda.
  0                                                   # Start with 0.
   ,{                                     }           # Use the iteration formula...
     my \i=++$;                                       #   Fetch current index.
               $_+(                      )            #   Last element plus:
                   4*(i%%3+i%%5)                      #     Fizz/Buzz/FizzBuzz length,
                                ||i.chars             #     or number length.
                                           ...$_      # ...until the input is reached.
 (                                              )-1   # Sequence length minus 1.
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 20 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
@µ35ìx_XvZÃ*4ªXìÊ}f1
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=QLUzNex4X1h2WsMqNKpY7Mp9ZjE&input=MzY3Nw)
```
@µ35ìx_XvZÃ*4ªXìÊ}f1     :Implicit input of integer U
@                        :Function taking an integer X as argument
 µ                       :  Decrement U by
  35ì                    :    Digit array of 35
     x                   :    Reduce by addition
      _                  :    After passing each Z through the following function
       XvZ               :      Is X divisible by Z?
          Ã              :    End reduce
           *4            :    Multiply by 4
             ª           :    Logical OR with
              Xì         :      Digit array of X
                Ê        :      Length
                 }       :End function
                  f1     :First integer >=1 that returns a falsey value (i.e, 0) when passed through that function
```
[Answer]
# [Perl 5](https://www.perl.org/) `-p`, 48 bytes
```
$\++;($_-=4*(!($\%3)+!($\%5))||length$\)&&redo}{
```
[Try it online!](https://tio.run/##K0gtyjH9/18lRlvbWkMlXtfWREtDUUMlRtVYUxtMm2pq1tTkpOall2SoxGiqqRWlpuTXVv//b2xmbv4vv6AkMz@v@L@ur6megaHBf90CAA "Perl 5 – Try It Online")
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 68 bytes, `stdout`-spamming
* Thanks to [H.PWiz](https://codegolf.stackexchange.com/users/71256/h-pwiz) for this approach, saving six bytes.
```
f(n,j,r){for(r=j=0;!r;r=!n*j)n-=++j%3?j%5?printf("%d",j):4:j%5?4:8;}
```
[Try it online!](https://tio.run/##ZY3BasMwEETv@YqNikDrKMRCjlNshOkhLYHSQmhvuQTZChZ4W@T2FPLtruwSCukedmDe7oxdnqwdBidIehnw7D6CCMabtJyHMpg5JR5paRYLz3Xl@br6DC19OcF4zaTHIitGMyvuy8twVzeupQbeYpgjvF6uEtg9vbzut8BQdiZWobwySFYHcoJnNYKBKFD9iuA9HohJkl3Mim/GUcX6b2ubvmcFe3zYPb/vtwzLWXdsKTZ2eI7NAKAkjBtn8DcTyCeg/wG1nkB@C7TSEag0vQE632zk6CuEy/AD "C (gcc) – Try It Online")
---
# [C (gcc)](https://gcc.gnu.org/), 74 bytes
```
f(n,j,r){for(r=j=0;!r;r=!n*j)n-=++j%3?j%5?snprintf(0,0,"%d",j):4:j%5?4:8;}
```
[Try it online!](https://tio.run/##XcyxasMwEAbgPU9xURHoEgUk5DjBRpgOLRQ6hWTLEmQrWJBLkdop5Nld2W2H9Ib74bufc6uzc8PgBckgI978NYpog1X1PNbRzmkRkFZ2uQzcNIGvm0QfsadPL5RUkvGWyYBVUY2notrW9@Gp7XxPHezzS0/422Ze8KJFsJADmp8QPOGRmMxFQZjbU1rrqWHpy7kuJVax1@e398PuhWE9u5x6yo1bfg4AWsK4cQZ/M3E5sfnHej1x@chGm8xaqQc25WYjR9UI9@Eb "C (gcc) – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 17 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
Lε35SÖ4*OygM}.¥sk
```
[Try it online](https://tio.run/##yy9OTMpM/f/f59xWY9Pgw9NMtPwr031r9Q4t9cz@/9/QFAA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9WeXiCvZLCo7ZJCkr2/33ObTU2DT48zUTLvzLdt1bv0NLi7P86/6MNdAx1zHQMTXWMDY11jM3MzWMB).
**Explanation:**
```
L          # Create a list in the range [1, (implicit) input]
           #  i.e. 15 → [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
 ε         # Map each value to:
  35S      #  Push 35 as digit list: [3,5]
     Ö     #  Check if the current value is divisible by these (1 if truthy; 0 if falsey)
      4*   #  Multiply both by 4
        O  #  And take the sum of that
           #   i.e. 2 → [0,0] → [0,0] → 0
           #   i.e. 9 → [1,0] → [4,0] → 4
           #   i.e. 10 → [0,1] → [0,4] → 4
           #   i.e. 15 → [1,1] → [4,4] → 8
  yg       #  Push the current value again, and pop and push it's length
           #   i.e. 2 → 1
           #   i.e. 15 → 2
  M        #  And then push the largest value on the stack
           #   i.e. 0 and 1 → 1
           #   i.e. 8 and 2 → 8
 }.¥       # After the map: undelta the list (starting from 0)
           #  i.e. [1,1,4,1,4,4,1,1,4,4,2,4,2,2,8]
           #   → [0,1,2,6,7,11,15,16,17,21,25,27,31,33,35,43] 
    sk     # Swap to get the (implicit) input, and get its 0-based index in the list
           #  i.e. 15 → 6
           # (after which the result is output implicitly)
```
[Answer]
# Python 3.8 (86 bytes)
```
f=lambda s:len(s.rpartition("z")[2])/len(str(n:=max(s.count("F")*3,s.count("B")*5)))+n
```
This exploits the fact that after the last "Fizz" or "Buzz", all the following integers have the same number of digits.
[Try it Online](https://tio.run/##K6gsycjPM7YoKPr/P802JzE3KSVRodgqJzVPo1ivqCCxqCSzJDM/T0OpSkkz2ihWUx8sU1KkkWdlm5tYAVSUnF@aV6Kh5KakqWWsA@c6Abmmmpqa2nn/C4oygSJpGkqGSpqaXAieERrXLbOqCouQCTYxp1LsakHiuMyByZnjlbTAL0vQcLAKQs5DqDI0JFYd8TZD1Boak6ba0IRU9aT6FF2foRlQ538A)
[Answer]
# Python 3 (79 bytes)
```
f=lambda s,n=0,l=0:l-len(s)and f(s,n+1,l+(4*(n%3//2+n%5//4)or len(str(n))))or n
```
# Python 2 (74 bytes)
```
f=lambda s,n=0,l=0:l-len(s)and f(s,n+1,l+(4*(n%3/2+n%5/4)or len(`n`)))or n
```
[Answer]
# [Thunno](https://github.com/Thunno/Thunno), \$ 29 \log\_{256}(96) \approx \$ 23.87 bytes
```
Re1+Ax35d%.!S4*xdL~Ez(A$sAh1+
```
Port of Jonathan Allan's Jelly answer.
#### Explanation
```
           # Implicit input
Re         # Loop through range(0, input):
  1+Ax     #   Add one and store in x without popping
      35d  #   Pair [3, 5]
%.!        #   Check for divisibility
   S4*     #   Multiply the sum by 4
      xdL  #   Get the length of the digits of x
~          #   Do a logical or
 E         # End the loop
  z(       # Get the running sums of the list
    A$     # Push the input
      sAh  # Get the index of this in the running sums
1+         # And add one to account for Thunno's 0-indexing
           # Implicit output
```
#### Screenshot
[![Screenshot](https://i.stack.imgur.com/wO2ebm.png)](https://i.stack.imgur.com/wO2eb.png)
]