1 ! Copyright (c) 2007 Samuel Tardieu.
2 ! See http://factorcode.org/license.txt for BSD license.
4 USING: combinators kernel math math.functions memoize ;
6 ! http://projecteuler.net/index.php?section=problems&id=169
11 ! Define f(0) = 1 and f(n) to be the number of different ways n can be
12 ! expressed as a sum of integer powers of 2 using each power no more than
15 ! For example, f(10) = 5 since there are five different ways to express 10:
31 { [ dup 2 < ] [ drop 1 ] }
32 { [ dup odd? ] [ 2/ fn ] }
33 [ 2/ [ fn ] [ 1- fn ] bi + ]
36 : euler169 ( -- result )
39 ! [ euler169 ] 100 ave-time
40 ! 0 ms ave run time - 0.2 SD (100 trials)