12345678910111213141516171819202122 |
- #!/usr/bin/ruby
- # Author: Daniel "Trizen" Șuteu
- # License: GPLv3
- # Website: https://github.com/trizen
- # Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
- # https://projecteuler.net/problem=6
- # Runtime: 0.148s
- func sum_pow_2(n) {
- 1/3 * [n**3, (3/2)*(n**2), (1/2)*n].sum;
- }
- func sum_pow_1(n) {
- 1/2 * [n**2, n].sum;
- }
- say int(sum_pow_1(100)**2 - sum_pow_2(100));
|