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
15 ! For example, f(10)=5 since there are five different ways to express 10:
30 { [ dup 2 < ] [ drop 1 ] }
31 { [ dup odd? ] [ 2/ fn ] }
32 { [ t ] [ 2/ [ fn ] keep 1- fn + ] }
35 : euler169 ( -- result )
38 ! [ euler169 ] 100 ave-time
39 ! 0 ms run / 0 ms GC ave time - 100 trials