1 ! Copyright (c) 2007, 2008 Aaron Schaefer.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel math math.ranges sequences project-euler.common ;
6 ! http://projecteuler.net/index.php?section=problems&id=6
11 ! The sum of the squares of the first ten natural numbers is,
12 ! 1² + 2² + ... + 10² = 385
14 ! The square of the sum of the first ten natural numbers is,
15 ! (1 + 2 + ... + 10)² = 55² = 3025
17 ! Hence the difference between the sum of the squares of the first ten natural
18 ! numbers and the square of the sum is 3025 - 385 = 2640.
20 ! Find the difference between the sum of the squares of the first one hundred
21 ! natural numbers and the square of the sum.
29 : sum-of-squares ( seq -- n )
32 : square-of-sum ( seq -- n )
37 : euler006 ( -- answer )
38 100 [1..b] [ sum-of-squares ] [ square-of-sum ] bi - abs ;
40 ! [ euler006 ] 100 ave-time
41 ! 0 ms ave run time - 0.24 SD (100 trials)