user-pic

jarich

  • About: I know Perl 5, but I could stand to know more about perl5i and perl6, so I'm going to try to solve basic to hard problems in each of the three languages, learning the idioms as I go.
  • Posted Reconsidering Exercise 1 to jarich

    Hao Wu provided a great comment showing how I could solve exercise one using sum from List::Util and grep. I'd considered sum but utilzed false laziness and didn't…

  • Commented on Exercise 1. 3s and 5s.
    Thanks for the comment, Hao, you are of course right, I pondered grep briefly, but that is indeed a more elegant solution. I have another problem I'm currently working on, but you've inspired me to consider how Perl 5/5i/6 stack...
  • Posted Exercise 1. 3s and 5s. to jarich

    My starting problem is easy. Coming from Project Euler:

    If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

    Find the sum of all the multiples of 3 or 5 below 1000.

    Pe…

  • Posted Purpose of this blog to jarich

    At this point, I don't have a Perl blog. I do Perl things, but nothing that ever seems worth blogging about. However, I've decided to improve my knowledge of Perl 5i and Perl 6, and generally practice my proramming, so I'm going to work through a bunch of easy through to difficult problems in…

Subscribe to feed Recent Actions from jarich

  • Mike Sanders commented on Exercise 1. 3s and 5s.

    Don´t have no perl6 runtime here to verify it, but in your time comparison the Perl 6 solution actually gives a different result (98 instead of 78)?!

  • coke commented on Exercise 1. 3s and 5s.

    I tried to run the perl6 version here against a git-fresh perl6, but it died with a syntax error.

    Here's a version that is more idiomatic, faster, and gives the right same answer as the perl5 examples (the difference seems to be that the perl6 example above included "20", while p5 variants excluded it.)

    use v6;
    
    

    sub MAIN($max = 1000) {
    my @threes = 3, 6, 9 ... * >= $max;
    my @fives = 5, 10, 15 ... * >= $max;

    # combine the series, order, eliminate dupes, remove any trailing high elements.
    my @multiples = (@threes, @fives).sort.sq…

  • coke commented on Exercise 1. 3s and 5s.

    My code was mangled. Trying again with slightly more compact formatting:

    use v6;
    
    

    sub MAIN($max = 1000) {
    my @threes = 3, 6, 9 ... * >= $max;
    my @fives = 5, 10, 15 ... * >= $max;

    my @multiples = (@threes, @fives)\
    .sort.squish.grep({$_

    # Print multiples and the total.
    say "My multiples are: ", @multiples;

    say "total: {[+] @multiples}";
    }

  • raiph commented on Exercise 1. 3s and 5s.

    In your P6 code you have this line of code:

    unless any(@multiples) $start {

    That looks like TTIAR (two terms in a row) to me (syntax error).

  • Olivier Mengué (dolmen) commented on Exercise 1. 3s and 5s.

    The code is still mangled :(

Subscribe to feed Responses to Comments from jarich

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl with a graphic design donated by Six Apart, Ltd.