1 ! Copyright (c) 2008 Aaron Schaefer.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: combinators.short-circuit kernel math.parser math.ranges
4 project-euler.common sequences ;
7 ! http://projecteuler.net/index.php?section=problems&id=36
12 ! The decimal number, 585 = 1001001001 (binary), is palindromic in both bases.
14 ! Find the sum of all numbers, less than one million, which are palindromic in
17 ! (Please note that the palindromic number, in either base, may not include
24 ! Only check odd numbers since the binary number must begin and end with 1
28 : both-bases? ( n -- ? )
29 { [ palindrome? ] [ >bin dup reverse = ] } 1&& ;
33 : euler036 ( -- answer )
34 1 1000000 2 <range> [ both-bases? ] filter sum ;
36 ! [ euler036 ] 100 ave-time
37 ! 1703 ms ave run time - 96.6 SD (100 trials)