! Copyright (C) 2009 Your name. ! See http://factorcode.org/license.txt for BSD license. ! Find the largest palindrome made from the product of two 3-digit numbers. USING: math math.parser math.functions math.ranges kernel sequences lists.lazy lists ; IN: project-euler.problem4 : palindrome? ( str -- ? ) dup reverse = ; : numeric-palindrome? ( n -- ? ) number>string palindrome? ; : digit-nums ( n -- seq ) [ 1 - ] keep [ 10^ ] bi@ 1 - [a,b] reverse ; : a*b ( a,b -- ab ) [ first ] keep second * ; : digit-nums-list ( n -- list ) digit-nums sequence>list ; : pair-digit-nums ( n -- seq seq ) digit-nums-list dup ; : digit-num-pairs ( n -- seq ) pair-digit-nums lcartesian-product ; : products ( seq -- seq ) [ a*b ] lazy-map ; : first-palindrome ( seq -- n ) [ palindrome? ] lfilter car ; : solution ( n -- n ) digit-num-pairs products first-palindrome ;