1 ! Copyright (c) 2007, 2008 Aaron Schaefer.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: kernel math ranges sequences project-euler.common ;
6 ! https://projecteuler.net/problem=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
18 ! first ten natural numbers and the square of the sum is 3025 -
21 ! Find the difference between the sum of the squares of the
22 ! first one hundred natural numbers and the square of the sum.
30 : sum-of-squares ( seq -- n )
33 : square-of-sum ( seq -- n )
38 : euler006 ( -- answer )
39 100 [1..b] [ sum-of-squares ] [ square-of-sum ] bi - abs ;
41 ! [ euler006 ] 100 ave-time
42 ! 0 ms ave run time - 0.24 SD (100 trials)