[Question]
  [
**Story**
So I have a book that I want to separate from my table with nothing but other books. I want to know how many books do I need to achieve this with \$n\$ book lengths.
Here's a visualization that my friend at Wolfram drew for me:
![a visualization from Wolfram](https://i.stack.imgur.com/481LF.gif)
More information about the topic in [Wolfram](http://mathworld.wolfram.com/BookStackingProblem.html) and [Wikipedia](https://en.wikipedia.org/wiki/Block-stacking_problem?wprov=sfla1).
**Challenge**
Given an integer input \$n\$, output how many books needed for the top book to be \$n\$ book length away from the table horizontally.  
*or*  
Find the smallest integer value of \$m\$ for input \$n\$ in the following inequality.
$$\sum\_{i=1}^{m}\frac{1}{2i} \geq n$$
***Edit:*** for fractions use at least a IEEE single-precision floating point. sorry for editing challenge after posting
([OEIS A014537](https://oeis.org/A014537))
**Test cases**
```
 1          4
 2         31
 3        227
 5      12367
10  272400600
```
  
[Answer]
# [Octave](https://www.gnu.org/software/octave/), ~~41~~ ~~40~~ 33 bytes
*1 byte saved thanks to @Dennis*
```
@(n)find(cumsum(.5./(1:9^n))>n,1)
```
[**Try it online!**](https://tio.run/##y08uSSxL/Z9mq6en999BI08zLTMvRSO5NLe4NFdDz1RPX8PQyjIuT1PTLk/HUPN/moap5n8A)
### Explanation
This uses the fact that harmonic numbers can be lower-bounded by a logarithmic function.
Also, the `>=` comparison can be replaced by `>` because harmonic numbers cannot be even integers (thanks, @Dennis!).
```
@(n)                                   % Anonymous function of n
                     1:9^n             % Range [1 2 ... 9^n]
                .5./(     )            % Divide .5 by each entry
         cumsum(           )           % Cumulative sum
                            >n         % Is each entry greater than n?
    find(                     ,1)      % Index of first true entry
```
[Answer]
# [Python 3](https://docs.python.org/3/), 35 bytes
```
f=lambda n,k=2:n>0and-~f(n-1/k,k+2)
```
[Try it online!](https://tio.run/##VYtBC4IwGEDP@Su@m84mpeJFKIggGJWH8tJJTCcN9Zts6xBif93EDtHxPd7rXuYhMRwrJVtQXMunKjiItpPKgGvNWr/0z1iaG9WIVhjncmJnlmbXdLc/UpgxY8mBJSy9UfhDQuaPF0@lhcTvH7hu6IMHPhmrTZO39zIHpPUmiHG7zrH03pWDnr@qab0MpkYqQBAIjk8hoBBSiEhsLTol0DiV3eMA3hb6aSJxNNhk/AA "Python 3 – Try It Online")
[Answer]
# [Husk](https://github.com/barbuz/Husk), 8 bytes
```
V≥⁰∫m\İ0
```
[Try it online!](https://tio.run/##yygtzv7/P@xR59JHjRsedazOjTmyweD////GAA "Husk – Try It Online")
Since Husk uses rational numbers when it can, this has no floating point issues
### Explanation
```
      İ0    The infinite list of positive even numbers
    m\      Reciprocate each
   ∫        Get the cumulative sum
V           Find the index of the first element
 ≥⁰         that is greater than or equal to the input
```
[Answer]
# JavaScript, 30 bytes
A recursive function so it'll crap out pretty early.
```
f=(n,x=0)=>n>0?f(n-.5/++x,x):x
```
[Try it online](https://tio.run/##y0osSyxOLsosKNHNy09J/f8/zVYjT6fC1kDT1i7PzsA@TSNPV89UX1u7QqdC06rif3J@XnF@TqpeTn66RpqGiabmfwA)
[Answer]
# Haskell, 38 bytes
```
k!n|n<=0=0|x<-n-1/(2*k)=1+(k+1)!x
(1!)
```
[Answer]
# [Swift](https://swift.org), 65 bytes
```
func f(n:Double){var i=0.0,s=i;while s<n{i+=1;s+=0.5/i};print(i)}
```
[Try it online!](https://tio.run/##Ky7PTCsx@f8/rTQvWSFNI8/KJb80KSdVs7ossUgh09ZAz0Cn2DbTujwjMydVodgmrzpT29bQulgbKGOqn1lrXVCUmVeikalZ@x@k2VCTC0QZQShjCGUKoQwNNP8DAA)
### Ungolfed
```
func f(n:Double) {
  var i = 0.0, s = 0.0
  while s < n {
    i += 1;
    s += 0.5 / i
  }
  print(i)
}
```
[Answer]
# [R](https://www.r-project.org/), 39 bytes
```
function(n){while((F=F+.5/T)<n)T=T+1;T}
```
[Try it online!](https://tio.run/##K/qfZqP7P600L7kkMz9PI0@zujwjMydVQ8PN1k1bz1Q/RNMmTzPENkTb0Dqk9n@ahqGB5n8A "R – Try It Online")
Brute Force!
[Answer]
# Javascript (ES6), 34 bytes
```
n=>eval("for(i=0;n>0;n-=.5/i)++i")
```
### Ungolfed
```
n => {
    for(i = 0; n > 0; ++i)
        n -= .5 / i
    return i;
}
```
### Test Cases
```
f=n=>eval("for(i=0;n>0;n-=.5/i)++i")
```
```
<button onclick="console.log(f(1))">Run for n = 1</button>
<button onclick="console.log(f(2))">Run for n = 2</button>
<button onclick="console.log(f(3))">Run for n = 3</button>
<button onclick="console.log(f(5))">Run for n = 5</button>
<button onclick="console.log(f(10))">Run for n = 10</button>
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 bytes
```
RİSH:ð1#
```
This is *very* slow.
[Try it online!](https://tio.run/##y0rNyan8/z/oyIZgD6vDGwyV/1srHW5/1LTG/f9/Qx0FIx0FYwA "Jelly – Try It Online")
[Answer]
# Haskell, ~~71~~ ~~49~~ 48 bytes
```
f x=length.fst.span(<x).scanl(+)0$(0.5/)<$>[1..]
```
@BMO saved me a whopping 22 bytes!
[Answer]
# [Julia 0.6](http://julialang.org/), ~~30~~ 27 bytes
```
<(n,i=1)=n>0?n-.5/i<i+1:i-1
```
[Try it online!](https://tio.run/##DcxdCkBAGAXQd6u4ycNMZjA0HuRnIfKgUJ90Sax/OAs4@3vIXIfQKhrpnO7YFwNt5nNpJXWNWBe28wYhxOgMSoPKwE8RcN3C56CKE8L2SNSfaB3raOUSPg "Julia 0.6 – Try It Online")
Only works up to `n = 6`, because Julia has no tail call optimization.
-3 bytes thanks to [Dennis](https://codegolf.stackexchange.com/users/12012/dennis).
[Answer]
# TI-BASIC, 27 bytes
Prompts user for input and displays output on termination. Note: `⁻¹` is the -1 (inverse) token.
```
Input N
1
Repeat 2N≤Σ(I⁻¹,I,1,Ans
Ans+1
End
Ans
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 11 bytes
```
XµN·zODI›}N
```
[Try it online!](https://tio.run/##MzBNTDJM/f8/4tBWv0Pbq/xdPB817Kr1@//fFAA "05AB1E – Try It Online")
**Explanation**
```
Xµ       }    # loop until counter is 1
  N·z         # push 1/(2*N)
     O        # sum the stack
      DI›     # break if the sum is greater than the input
          N   # push N
```
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 10 bytes
```
f!>Qsmc1yh
```
[Try it online!](https://tio.run/##K6gsyfj/P03RLrA4N9mwEsg2BgA "Pyth – Try It Online")
Extremely slow.
# [Pyth](https://github.com/isaacg1/pyth), 10 bytes
```
fgscL1STyQ
```
[Try it online!](https://tio.run/##K6gsyfj/Py29ONnHMDikMvD/f2MA "Pyth – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 12 bytes
The same length as, but slightly more efficient than, the recursive option.
```
@T¨(Uµ½÷X}a1
```
[Try it](https://ethproductions.github.io/japt/?v=2.0a0&code=QFSoKFW1vfdYfWEx&input=OA==)
---
## Explanation
```
@T¨(Uµ½÷X}a1
                 :Implicit input of integer U
@        }a1     :Return the first number X >=1 that returns truthy when passed through the following function
 T               :Zero
  ¨              :Greater than or equal to
    Uµ           :Decrement U by...
      ½÷X        :0.5 divided by X
```
[Answer]
# J, 22 bytes
*-6 bytes thanks to frownyfrog*
```
I.~0+/\@,1%2*1+[:i.9&^
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/PfXqDLT1Yxx0DFWNtAy1o60y9SzV4v5rcnGlJmfkK6QpGMEYxjCG6X8A "J – Try It Online")
## original answer
Luis's answer in J:
```
1+]i.~[:<.[:+/\1%2*1+[:i.9&^
```
## Ungolfed
```
1 + ] i.~ [: <. [: +/\ 1 % 2 * 1 + [: i. 9&^
```
Mostly curious to see if it can be drastically improved (*cough* paging miles)
## Explanation
```
1 +      NB. 1 plus... 
] i.~    NB. find the index of the arg in...
[: <.    NB. the floor of...
[: +/\   NB. the sumscan of...
1 %      NB. the reciprical of...
2 *      NB. two times...
1 +      NB. 1 plus...
[: i.    NB.  the integers up to 
9&^      NB. 9 raised to the power of the arg
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/DbVjM/Xqoq1s9KKttPVjDFWNtAy1o60y9SzV4v5rcnGlJmfkK6QpGMEYxjCG6X8A "J – Try It Online")
[Answer]
# PHP, 35 bytes
```
while($argv[1]>$s+=.5/++$i);echo$i;
```
Run it using the CLI:
```
$ php -d error_reporting=0 -r 'while($argv[1]>$s+=.5/++$i);echo$i;' 5
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 40 bytes
```
⌈x/.NSolve[HarmonicNumber@x==2#,x]⌉&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n6Zg@/9RT0eFvp5fcH5OWWq0R2JRbn5eZrJfaW5SapFDha2tkbJOReyjnk61/y750QFFmXkl0Xk6CkoKunYKSjoKadF5sbE6CtVAIUMgMqiN/Q8A "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# Java 8, 49 bytes
```
n->{float r=0,s=0;for(;s<n;)s+=.5f/++r;return r;}
```
**Explanation:**
[Try it online.](https://tio.run/##LY/NbsIwDMfvewqLU6KMrBx2mcneYFw4Ig6hpJNZ61RJyjShPntx20m2rL8/f775u9/GPvDt@jPVrc8Zvjzx4wWAuITU@DrAYZYATRt9gVpJAVij5EZxsQMwOJh4@/lYe5KrXrOrsIlJYd4z6mycfW/ejEmYQhkSQ8JxwnW@Hy4t1ZCLLxLuka7QCYQ6lkT8fTp7vQLMZNDJKQ6/i1ALhZDJnZmK3A5p73YVkjF6KQEc/3IJnY1Dsb3sKy0rMpsP2JjOspV39P8v4/QE) (Times out for test cases above `n=7`.)
```
n->{             // Method with integer parameter and float return-type
  float r=0,     //  Result-float, starting at 0
        s=0;     //  Sum-float, starting at 0
  for(;s<n;)     //  Loop as long as the sum is smaller than the input
    s+=.5f/++r;  //   Increase the sum by `0.5/(r+1)`,
                 //   by first increasing `r` by 1 with `r++`
  return r;}     //  Return the result-float
```
[Answer]
# [tinylisp](https://github.com/dloscutoff/Esolangs/tree/master/tinylisp), 98 bytes
```
(load library
(d _(q((k # N D)(i(l N(* D # 2))(_(inc k)#(+(* N k)D)(* D k))(dec k
(q((#)(_ 1 # 0 1
```
The last line is an unnamed lambda function that takes the number of book-lengths and returns the number of books needed. [Try it online!](https://tio.run/##FYwxDoMwFEN3TmEpiz8sTdUTIOZcAYWmw1dSoJSF04efzfJ79qnrVfS/18qyxYSiyxGPq2PCzB@Z4RAwCZUFgT0mK54inKnrG1kcB2uDJZMazgbTx1D7GNuHMxvedg/4ym/cMYL@3PASqTc "tinylisp – Try It Online")
### Explanation
The only numeric data type tinylisp has is integers, so we calculate the harmonic series as a fraction by keeping track of the numerator and denominator. At each step, `N` is the numerator, `D` is the denominator, and `k` is the sum index. We want the new partial sum to be `N/D + 1/k`, or `(N*k + D)/(D*k)`. Thus, we recurse with a new numerator of `N*K + D`, a new denominator of `D*k`, and a new index of `k+1`.
The recursion should halt once the partial sum is greater than or equal to `#`, the desired number of book-lengths. At this point, we've gone one book too far, so we return `k-1`. The condition is `1/2 * N/D < #`; multiplying out the denominator, we get `N < D*#*2`, which is the golfiest way to write it.
The recursive helper function `_` does all these calculations; the main function is merely a one-argument wrapper that calls `_` with the correct starting values for `k`, `N`, and `D`.
]