1 ! Copyright (c) 2007 Aaron Schaefer, Daniel Ehrenberg.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: hashtables kernel math math.functions math.ranges project-euler.common
4 sequences sorting sets ;
7 ! http://projecteuler.net/index.php?section=problems&id=4
12 ! A palindromic number reads the same both ways. The largest palindrome made
13 ! from the product of two 2-digit numbers is 9009 = 91 * 99.
15 ! Find the largest palindrome made from the product of two 3-digit numbers.
23 : source-004 ( -- seq )
24 100 999 [a,b] [ 10 divisor? ] reject ;
26 : max-palindrome ( seq -- palindrome )
27 natural-sort [ palindrome? ] find-last nip ;
31 : euler004 ( -- answer )
32 source-004 dup [ * ] cartesian-map combine max-palindrome ;
34 ! [ euler004 ] 100 ave-time
35 ! 1164 ms ave run time - 39.35 SD (100 trials)