1 ! Copyright (c) 2007 Aaron Schaefer, Daniel Ehrenberg.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: kernel math math.functions project-euler.common ranges
4 sequences sets sorting ;
7 ! https://projecteuler.net/problem=4
12 ! A palindromic number reads the same both ways. The largest
13 ! palindrome made from the product of two 2-digit numbers is
16 ! Find the largest palindrome made from the product of two
25 : source-004 ( -- seq )
26 100 999 [a..b] [ 10 divisor? ] reject ;
28 : max-palindrome ( seq -- palindrome )
29 sort [ palindrome? ] find-last nip ;
33 : euler004 ( -- answer )
34 source-004 dup [ * ] cartesian-map union-all max-palindrome ;
36 ! [ euler004 ] 100 ave-time
37 ! 1164 ms ave run time - 39.35 SD (100 trials)