! Copyright (C) 2008 Jeffrey Drake. ! See http://factorcode.org/license.txt for BSD license. USING: kernel sequences fry math.ranges math.parser sorting arrays prettyprint ; IN: euler4 ! by prunedtree : all-tuples ( seqs -- seqs ) dup length 1 = [ flip ] [ unclip-last-slice [ all-tuples ] dip [ '[ _ suffix ] map ] with map concat ] if ; : all-threenumberproducts ( -- seq ) 100 999 [a,b] dup 2array all-tuples [ product ] map ; : palindrome? ( string -- ? ) dup reverse = ; : euler4 ( -- ) all-threenumberproducts [ number>string ] map [ palindrome? ] filter [ string>number ] map natural-sort reverse first . ;