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

77%
+5 −0
Challenges Partial Sums of Harmonic Series

Raku, 27 bytes {+([\+](1 X/1..*)...*>=$_)} Try it online! { } # Anonymous code block [\+]( ) # Get the partial sum of 1 X/ ...

posted 3y ago by Jo King‭  ·  edited 3y ago by Jo King‭

Answer
#2: Post edited by user avatar Jo King‭ · 2020-11-16T00:15:57Z (over 3 years ago)
  • # [Raku], 27 bytes
  • <!-- language-all: lang-perl6 -->
  • {+([\+](1 X/1..*)...*>=$_)}
  • [Try it online!][TIO-khjse7nk]
  • [Raku]: https://github.com/nxadm/rakudo-pkg
  • [TIO-khjse7nk]: https://tio.run/##K0gtyjH7n1upoJamYPu/WlsjOkY7VsNQIULfUE9PS1MPSNjZqsRr1v4vTqxU0AOqSssvUgDKGRr8BwA "Perl 6 – Try It Online"
  • ~~~
  • { } # Anonymous code block
  • [\+]( ) # Get the partial sum of
  • 1 X/ # 1 over each of
  • 1..* # All positive integers
  • ...*>=$_ # Take from the list until it is bigger than the input
  • +( ) # And return the length of the list
  • ~~~
  • This will start to suffer precision issues, but you can add `.FatRat` to [work correctly](https://tio.run/##K0gtyjH7n1upoJamYPu/WlsjOkY7VsNQzy2xJCixRCFC31BPT0tTD0jY2arEa9b@L06sVNADKk7LL1IAyhka/) (but much slower)
  • # [Raku], 27 bytes
  • <!-- language-all: lang-perl6 -->
  • {+([\+](1 X/1..*)...*>=$_)}
  • [Try it online!][TIO-khjse7nk]
  • [Raku]: https://github.com/nxadm/rakudo-pkg
  • [TIO-khjse7nk]: https://tio.run/##K0gtyjH7n1upoJamYPu/WlsjOkY7VsNQIULfUE9PS1MPSNjZqsRr1v4vTqxU0AOqSssvUgDKGRr8BwA "Perl 6 – Try It Online"
  • ~~~
  • { } # Anonymous code block
  • [\+]( ) # Get the partial sum of
  • 1 X/ # 1 over each of
  • 1..* # All positive integers
  • ...*>=$_ # Take from the list until it is bigger than the input
  • +( ) # And return the length of the list
  • ~~~
  • This will start to suffer precision issues, but you can add `.FatRat` to [work correctly](https://tio.run/##K0gtyjH7n1upoJamYPu/WlsjOkY7VsNQzy2xJCixRCFC31BPT0tTD0jY2arEa9b@L06sVNADKk7LL1IAyhka/AcA) (but much slower)
#1: Initial revision by user avatar Jo King‭ · 2020-11-16T00:15:25Z (over 3 years ago)
# [Raku], 27 bytes

<!-- language-all: lang-perl6 -->

    {+([\+](1 X/1..*)...*>=$_)}

[Try it online!][TIO-khjse7nk]

[Raku]: https://github.com/nxadm/rakudo-pkg
[TIO-khjse7nk]: https://tio.run/##K0gtyjH7n1upoJamYPu/WlsjOkY7VsNQIULfUE9PS1MPSNjZqsRr1v4vTqxU0AOqSssvUgDKGRr8BwA "Perl 6 – Try It Online"

~~~
{                         }  # Anonymous code block
   [\+](        )            # Get the partial sum of
        1 X/                 # 1 over each of
            1..*             # All positive integers
                 ...*>=$_    # Take from the list until it is bigger than the input
 +(                      )   # And return the length of the list
~~~

This will start to suffer precision issues, but you can add `.FatRat` to [work correctly](https://tio.run/##K0gtyjH7n1upoJamYPu/WlsjOkY7VsNQzy2xJCixRCFC31BPT0tTD0jY2arEa9b@L06sVNADKk7LL1IAyhka/) (but much slower)