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

Perl 6 mojo?
  • Comment on Re^2: How do I write a program that calculates the sum of all numbers to a number, n?

Replies are listed 'Best First'.
Re^3: How do I write a program that calculates the sum of all numbers to a number, n?
by Your Mother (Archbishop) on Feb 24, 2015 at 21:51 UTC

    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

        More fun! Thanks. Parens work. Probably another way that I don’t know too.

        > say [+] ^1+$n 14 > say [+] ^++$n+1 15 > say [+] ^($n+1) 91 > say [+] ^++$n 105 > say [+] ^$n++ 105

      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
Re^3: How do I write a program that calculates the sum of all numbers to a number, n?
by karlgoethebier (Abbot) on Feb 25, 2015 at 12:04 UTC
    "...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)