1 ! Copyright (c) 2007 Samuel Tardieu.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: combinators kernel math math.functions
7 ! https://projecteuler.net/problem=169
12 ! Define f(0) = 1 and f(n) to be the number of different ways n
13 ! can be expressed as a sum of integer powers of 2 using each
14 ! power no more than twice.
16 ! For example, f(10) = 5 since there are five different ways to
33 { [ dup 2 < ] [ drop 1 ] }
34 { [ dup odd? ] [ 2/ fn ] }
35 [ 2/ [ fn ] [ 1 - fn ] bi + ]
38 : euler169 ( -- result )
41 ! [ euler169 ] 100 ave-time
42 ! 0 ms ave run time - 0.2 SD (100 trials)