Paste: Euler 4

Author: jdrake
Mode: factor
Date: Tue, 23 Dec 2008 09:13:12
Plain Text |
! 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 . ;

New Annotation

Summary:
Author:
Mode:
Body: