g | x | w | all
Bytes Lang Time Link
034TIBASIC TI83 Plus250516T145558Zmadeforl
043Juby250502T031307ZJordan
050Swift 6250505T131116ZmacOSist
043Python 3.8 prerelease250502T022730ZLucenapo
014Uiua240701T145732Znoodle p
010Japt240822T213450ZShaggy
012cQuents240609T233624ZStephen
006Vyxal240615T012600Zlyxal
051PHP240614T222508Zluciande
034Python 3240611T165355ZJonathan
034Octave240611T203644ZKa Wa Yi
036R240610T132146ZRui Barr
027Ruby240611T075034ZG B
043Desmos240610T114309ZAiden Ch
00705AB1E240610T104528ZKevin Cr
011Brachylog240610T083824ZFatalize
043Wolfram Language Mathematica240610T065632ZGreg Mar
057Google Sheets240610T015955Zz..
011MATL240609T223142ZLuis Men
036Python 3240609T192506Zxnor
007Jelly240609T200905ZJonathan
037PowerShell Core240609T204159ZJulian
041Arturo240609T200011Zchunes
041Python240609T185712Zcorvus_1
018Charcoal240609T184936ZNeil
031Haskell240609T184119Zcorvus_1
029JavaScript ES6240609T172040ZArnauld
008Vyxal 3240609T171030ZRubenVer

TI-BASIC (TI-83 Plus), 34 bytes

While 1
While C≤N
I+1→I
C+1/I→C
End
Disp I
N+1→N
End

outputs forever

J-uby, 43 bytes

:& &:<%(:+|:sum+(:/&1r))|:+&:find|~:^&(1..)

Attempt This Online!

Swift 6, 50 bytes

let h={$0<1 ?$1-1.0:h($0-1.0/$1,$1+1)},f={h($0,2)}

f(_:) is the function to call.

Try it on SwiftFiddle!

Python 3.8 (pre-release), 43 bytes

f=lambda n,t=1,k=2:n<t or-~f(k*n-t,k*t,k+1)

Try it online!

A modification of Jonathan Allan's answer that does not have any floating point limitations (uses ints only).

Uiua, 15 14 bytes

⍢(⊙+⟜÷⤚+1)⋅≥∩0

Try it online!

Nobody tried to beat my Uiua score in the three weeks since I posted this challenge, so I decided to just leave it here for reference.

This leaves k at the top of the stack, with the actual harmonic number below it and the input below that.

Here's the code commented with a translation to traditional imperative code:

⍢(⊙+⟜÷⤚+1)⋅≥∩0­⁡​‎⁠⁠⁠⁠⁠⁠⁠‎⁡⁠⁤⁢‏⁠‎⁡⁠⁤⁣‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁡‏⁠‎⁡⁠⁢‏⁠⁠⁠‎⁡⁠⁣⁣‏⁠‎⁡⁠⁣⁤‏⁠‎⁡⁠⁤⁡‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁣⁡‏⁠‎⁡⁠⁣⁢‏‏​⁡⁠⁡‌⁤​‎‎⁡⁠⁢⁢‏⁠‎⁡⁠⁢⁣‏⁠‎⁡⁠⁢⁤‏‏​⁡⁠⁡‌⁢⁡​‎‎⁡⁠⁣‏⁠‎⁡⁠⁤‏⁠‎⁡⁠⁢⁡‏‏​⁡⁠⁡‌­
            ∩0  # ‎⁡k = 0, H = 0, n = input
⍢(       )⋅≥    # ‎⁢while H >= n:
       +1       # ‎⁣  k += 1
  ⊙+⟜÷⤚         # ‎⁢⁡  H += 1/k

💎

Code explanation created with the help of Luminespire.

Uiua is a tacit language, so that translation isn't one-to-one, but it's close enough.

Japt, 10 bytes

@µ1/X c}f1

Try it

cQuents, 13 12 bytes

$0:#$<bN
;/$

Try it online!

-1 because I remembered I had added a unary / for reciprocal

Explanation

First line:

$0        set starting index to 0
  :       mode: sequence - given input n, return the nth term
          each term equals
   #                       the first value of N such that:
    $     the current index
     <                      <
      b                       the second line (   )
       N                                        N

Second line:

;         mode: series - given input n, return the sum of the first n terms
          each term equals
 /                         1 /
  $                            current index

Vyxal, 6 bytes

↵ʀ˦⌈ḟ

Try it Online!

You know me, gotta be posting the most stupid and inefficent answers. Goes slow for inputs that make \$10^x\$ very large. 1-indexed.

Uses some lucky math coincidences to get 6 bytes instead of 7 doing it the normal way.

Explained

↵ʀ˦⌈ḟ­⁡​‎‎⁡⁠⁡‏⁠‎⁡⁠⁢‏‏​⁡⁠⁡‌⁢​‎‏​⁢⁠⁡‌⁣​‎‎⁡⁠⁣‏‏​⁡⁠⁡‌⁤​‎‎⁡⁠⁤‏‏​⁡⁠⁡‌⁢⁡​‎‎⁡⁠⁢⁡‏‏​⁡⁠⁡‌⁢⁢​‎‎⁡⁠⁢⁢‏‏​⁡⁠⁡‌­
↵ʀ      # ‎⁡Push the range [0, 10 ** n]. As noted on the OEIS,
        # ‎⁡For n >= 1, log(n + 1/2) + gamma < H(n) < log(n + 1/2) + gamma + 1/(24n^2), where gamma is Euler's constant
        # ‎⁡(source: https://oeis.org/A002387 under the comments section)
        # ‎⁡Luckily, for n >= 1, 10 ** n > that. Therefore, it's guaranteed
        # ‎⁡that the answer is contained within the range.
# ‎⁢This is also why the program takes a while for larger inputs.
  Ė     # ‎⁣Reciprocals of each number in that range
   ¦    # ‎⁤Cumulative sums of those reciprocals
    ⌈   # ‎⁢⁡And take the floor of each cumulative sum.
     ḟ  # ‎⁢⁢Find the first index of the input in that list.
        # ‎⁢⁢This is why the output is 1-indexed.
        # ‎⁢⁢It's essentially finding the point where the harmonic number is first > n - 1
💎

Created with the help of Luminespire.

PHP, 51 bytes

function f($n,$k=0){return$n<1?$k:f($n-1/++$k,$k);}

Try it online!

Python 3, 34 bytes

f=lambda n,k=2:n<1or-~f(n-1/k,k+1)

A recursive function that accepts \$n\$ (0-indexed) and returns the required number of terms.

Try it online!

How?

Count the number of non-unit terms (\$\frac{1}{2}, \frac{1}{3}, ...\$) we need to subtract to reach a number below one and add one.

One may think that this could overshoot for some \$n\$, but that would only happen if some harmonic number other than \$0\$ or \$1\$ were an integer, which is not the case due to Bertrand's postulate - see "proof 2" here.

Uses the fact that in Python True quacks like 1.

f=lambda  ,   :                     # f is a function that accepts
         n                          # n
           k=2                      # and, optionally, k defaulting to 2:
               n<1                  #   is n less than one?
                  or                #   if not...
                      f(     ,   )  #     call f with
                        n-1/k       #       n reduced by the current term (1/k)
                              k+1   #       and k incremented -> C
                     ~              #     bitwise NOT         -> -1 - C
                    -               #     negate              -> -(-1 - C) = C + 1

Octave, 34 bytes

f=@(n)find(cumsum(1./(1:4^n))>n,1)

Try it Online!

Explanation

Vectorization + cumulative sum. Can evaluate a(13) easily.

Use the 'power of two' inequality:

$$H_k = 1+\frac{1}{2}+\frac{1}{3}+\frac{1}{4}+\frac{1}{5}+\frac{1}{6}+\frac{1}{7}+\frac{1}{8}+ \cdots +\frac{1}{k}$$ is greater than $$T_k = 1+\frac{1}{2} + \left(\frac{1}{4}+\frac{1}{4}\right)+\left(\frac{1}{8}+\frac{1}{8}+\frac{1}{8}+\frac{1}{8}\right) + \cdots +\frac{1}{k}$$

So \$T_k > N\$ implies \$H_k > N\$. For the original question, the smallest \$k\$ cannot be greater than \$2^{2N}\$.

R, 36 bytes

\(n){k=0;while(F<=n)F=F+1/(k=k+1);k}

Try it online!

Minus 2 bytes thanks to @pajonk's suggestion in comment.

Ruby, 28 27 bytes

->n{(1..).find{0>n-=1r/_1}}

Attempt This Online!

Desmos, 43 bytes

f(n)=g(n,1)
g(n,k)=\{n<0:0,g(n-1/k,k+1)+1\}

Port of xnor's Python answer.

Try It On Desmos!

Try It On Desmos! - Prettified

05AB1E, 7 bytes

∞.ΔLzO‹

Given a 0-based \$n\$, outputs the \$n^{th}\$ value.

Try it online or verify the infinite list.

Explanation:

∞        # Push an infinite positive list: [1,2,3,...]
 .Δ      # Pop and find the first value which is truthy for:
   L     #  Pop and push a list in the range [1,value]
    z    #  Convert each inner value v to its reciprocal 1/v
     O   #  Sum this list of reciprocals
      ‹  #  Check if the (implicit) input-integer is smaller than this
         # (after which the found result is output implicitly)

Brachylog, 11 bytes

≤.⟦₁/₁ᵐ+>?∧

Try it online!

Takes n as input.

Explanation

≤.            n ≤ k, k is the output
 .⟦₁          Take the range [1, …, k]
    /₁ᵐ       Map inverse: [1, …, 1/k]
       +>?    The sum of inverses must be greater than n
          ∧  (Implicitely find a value of k that fits these constraints)

Wolfram Language (Mathematica), 43 bytes

Ceiling@*InverseFunction[HarmonicNumber]@*N

Try it online! (for some reason TIO returns 1 instead of 2 for the input 1; it works correctly on my computer)

The inevitable built-in. Mathematica can calculate HarmonicNumber\$(x)\$ for any real number \$x>-1\$, and thus it can calculate the exact InverseFunction of that function. N makes it treat the input as a real number rather than an integer, and Ceiling rounds up to the nearest integer.

Yet again I wish I understood how to install and use Sledgehammer....

Google Sheets, 57 bytes

Expects \$n\$ in A1 (\$0\$-indexed)

=LET(R,LAMBDA(R,s,i,IF(s>A1,i-1,R(R,s+1/i,i+1))),R(R,,1))

Reaches calc limit starting from \$n=10\$ (\$a(n) = 12367\$).

MATL, 11 bytes

`1@:/sG>~}@

Inputs n, outputs a(n).

Try it online!

How it works

`       % Do...while
  1     %   Push 1
  @     %   Push iteration index k, starting at 1
  :     %   Range: gives [1 2 ... k]
  /     %   Inverse, element-wise
  s     %   Sum: gives H_k
  G     %   Push n
  >     %   Greater than?
  ~     %   Negate. This is the loop condition
}       % Finally (execute on loop exit)
  @     %   Push k of the last iteration
        % End (implicit)
        % Display stack (implicit)

Python 3, 36 bytes

f=lambda n,k=1:n>=0and-~f(n-1/k,k+1)

Try it online!

Outputs zero-indexed, which is how the OEIS is defined.

43 bytes

t=k=1
while[t%1*k<=1!=print(k)]:k+=1;t+=1/k

Try it online!

Prints forever

Jelly, 7 bytes

İ€S>ð1#

A monadic Link that accepts a non-negative integer and yields a singleton list containing a positive integer. Or a full program that prints the result.

Try it online!

How?

İ€S>ð1# - Link: non-negative integer, N
      # - starting with k=N increment k finding the...
     1  - ...first 1 k for which:
    ð   -   the dyadic chain - f(k, N):
İ€      -     inverse each of {[1..k]}
  S     -     sum
   >    -     is greater than {N}?

PowerShell Core, 37 bytes

for(){if(($s+=1/++$d)-gt$c){$d
$c++}}

Try it online!

Outputs the sequence indefinitely

Arturo, 41 bytes

g:$[n k][(n<1)?->k->g n-1//<=k+1]$=>[g&1]

Try it!

A port of Arnauld's JavaScript answer. Arturo doesn't have default arguments, so two functions are necessary where the second calls the first with a fixed k.

Python, 41 bytes

f=lambda n,k=0:n<1and k or f(n-1/-~k,-~k)

A port of @Arnauld's answer.

Attempt This Online!

Charcoal, 18 bytes

NθW¬‹θ⁰«→≧⁻∕¹ⅈθ»Iⅈ

Try it online! Based on @Arnauld's answer but I chose to make mine 0-indexed. Explanation:

Nθ

Input n.

W¬‹θ⁰«

Until n is negative...

→≧⁻∕¹ⅈθ

... subtract the next unit fraction from n.

»Iⅈ

Output k.

Haskell, 31 bytes

(0!)
k!n|n<1=k|k<-1+k=k!(n-1/k)

Ungolfed:

f n = (0!n)
(k!n)
 | n<1       = k
 | otherwise = let k' = 1+k in k' ! (n-1/k')

A port of @Arnauld's answer.

Attempt This Online!

JavaScript (ES6), 29 bytes

Returns the \$n\$-th term, 1-indexed.

f=(n,k=0)=>n<1?k:f(n-1/++k,k)

Try it online!

Vyxal 3, 8 bytes

λɾė∑⁰>}“

Try it Online!

λɾė∑⁰>}“­⁡​‎‎⁡⁠⁢⁤‏‏​⁡⁠⁡‌⁢​‎⁠‎⁡⁠⁤‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁣‏‏​⁡⁠⁡‌⁤​‎‎⁡⁠⁢‏‏​⁡⁠⁡‌⁢⁡​‎⁠‎⁡⁠⁢⁢‏‏​⁡⁠⁡‌⁢⁢​‎‎⁡⁠⁢⁡‏‏​⁡⁠⁡‌­
       “  # ‎⁡Find first positive integer such that
   ∑      # ‎⁢the sum of 
  ė       # ‎⁣the reciprocals of
 ɾ        # ‎⁤the numbers from 1 to the integer
     >    # ‎⁢⁡is greater than
    ⁰     # ‎⁢⁢the input
💎

Created with the help of Luminespire.