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

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
  • Comment on Re^5: 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^6: How do I write a program that calculates the sum of all numbers to a number, n?
by raiph (Deacon) on Feb 25, 2015 at 01:23 UTC
Re^6: How do I write a program that calculates the sum of all numbers to a number, n?
by Tux (Canon) on Feb 25, 2015 at 11:20 UTC
    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