### Archive

Archive for the ‘Power Sums’ Category

## Power sum in Ruby

The logo, selected as winner of the Ruby Logo Contest (Photo credit: Wikipedia)

$1^m + 2^m + \ldots + n^m = ?$

It is not easy to calculate if n is 50, nad m is 9. Here Ruby comes for help. If you had already installed Ruby 1.8 or Ruby 1.9, open terminal (in Linux) type irb and press enter. Then type following (don’t type > sign) :

>sum(n,m)
>return 1 if n == 1
>sum(n-1,m) + n^m if n > 1
>end

It is all, now type sum(50,9) and you will get the answer…

## Power Sum problem

Find the sum of $1^2 - 2^2 + 3^2 - 4^2 + \ldots + (-1)^{m-1} \cdot m^2$