Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

60%
+1 −0
Challenges Partial Sums of Harmonic Series

BQN, 23 bytes {𝕩{𝕊⍟(𝕗>·+´∘÷1+↕)𝕩+1}1} This recursion is more complicated than it should, but I managed to keep it purely functional. I use a modifier to mimic passing a left argument, that's...

posted 17d ago by panadestein‭

Answer
#1: Initial revision by user avatar panadestein‭ · 2025-03-15T19:30:49Z (17 days ago)
# [BQN], 23 bytes

    {𝕩{𝕊⍟(𝕗>·+´∘÷1+↕)𝕩+1}1}

This recursion is more complicated than it should, but I managed to keep it purely functional. I use a modifier to mimic passing a left argument, that's why we have the 𝕗 inside the recursion test.

# [BQN], 17 bytes

    ⌊0.5+·⋆⊢-0.57722˙

I don't know if it is fair to use an approximation, but the harmonic series' partial sums are given by the Euler-Maclaurin formula, so we can do:

$H_k \approx \ln k + \gamma > n$

So we solve for k and take the nearest integer. I have tuned the Euler–Mascheroni constant value so I can reproduce the recursion (although I hit CBQN's recursion limit for n=9 already):

[BQN online REPL][Try]

[BQN]: https://mlochbaum.github.io/BQN/
[Try]: https://mlochbaum.github.io/BQN/try.html#code=QSDihpAg4oyKMC41K8K34ouG4oqiLTAuNTc3MjLLmQpSIOKGkCB78J2VqXvwnZWK4o2fKPCdlZc+wrcrwrTiiJjDtzEr4oaVKfCdlakrMX0xfQoKKEHCqOKLiMK34oiowrTCtyhB4omhUinCqMKvM+KGk+KKoikgMSvihpUxMAo=