1 ! Copyright (c) 2007 Aaron Schaefer.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel math project-euler.common ;
6 ! http://projecteuler.net/index.php?section=problems&id=12
11 ! The sequence of triangle numbers is generated by adding the natural numbers.
12 ! So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first
15 ! 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
17 ! Let us list the factors of the first seven triangle numbers:
27 ! We can see that the 7th triangle number, 28, is the first triangle number to
28 ! have over five divisors.
30 ! Which is the first triangle number to have over five-hundred divisors?
36 : euler012 ( -- answer )
37 8 [ dup nth-triangle tau* 500 < ] [ 1+ ] [ ] while nth-triangle ;
39 ! [ euler012 ] 10 ave-time
40 ! 6573 ms ave run time - 346.27 SD (10 trials)