in reply to Re^3: 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?

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

Replies are listed 'Best First'.
Re^5: 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 22:03 UTC

    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
      say [+] ^$n,$n

      (You do not want to change $n, so ++ is out of the question)

      Also note that currently $n cannot be a native int when using ++, though that will be fixed.

      $ perl6 -e'my Int $n = 10; say ++$n;' 11 $ perl6 -e'my int $n = 10; say ++$n;' Cannot assign to an immutable value in sub prefix:<++> at src/gen/m-CORE.setting:5565 in block <unit> at -e:1 $ perl6 -e'my int $n = 10; say [+] ^$n' 45 $ perl6 -e'my int $n = 10; say [+] ^$n,$n' 55

      Enjoy, Have FUN! H.Merijn