in reply to How do I write a program that calculates the sum of all numbers to a number, n?

say [+] ^$n

Enjoy, Have FUN! H.Merijn
  • Comment on Re: How do I write a program that calculates the sum of all numbers to a number, n?
  • Download Code

Replies are listed 'Best First'.
Re^2: How do I write a program that calculates the sum of all numbers to a number, n?
by LanX (Saint) on Feb 24, 2015 at 21:46 UTC
Re^2: How do I write a program that calculates the sum of all numbers to a number, n?
by RonW (Parson) on Feb 24, 2015 at 21:48 UTC
    Perl 6 mojo?

      We told you guys; it’s fun! Though I’m not positive the answer shouldn’t have been 91 instead… to v through.

      ~>perl6 > $n = 13 13 > say [+] ^$n 78
        Though I’m not positive the answer shouldn’t have been 91 instead

        ^$n means 0 .. $n - 1; so try:

        say [+] ^$n+1;

        Not sure about precedence, so it might need brackets. Or maybe:

        say [+] ^++$n;

        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
        In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

        I read "to" in the OP as TO, not UPTO AND INCLUDING.

        The OP also did not specify what language to give the solution in, hence the short perl6.


        Enjoy, Have FUN! H.Merijn
      "...mojo?"

      Or Voodoo? Perhaps a servant of the spirits?

      Best regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

        "mojo" eq "magic" (or "voodoo", if you prefer that terminology)