diff --git a/extra/project-euler/116/116.factor b/extra/project-euler/116/116.factor new file mode 100644 index 0000000000..d48cdf175c --- /dev/null +++ b/extra/project-euler/116/116.factor @@ -0,0 +1,55 @@ +! Copyright (c) 2008 Eric Mertens +! See http://factorcode.org/license.txt for BSD license. +USING: kernel math math.ranges sequences sequences.lib ; + +IN: project-euler.116 + +! http://projecteuler.net/index.php?section=problems&id=116 + +! DESCRIPTION +! ----------- + +! A row of five black square tiles is to have a number of its tiles replaced +! with coloured oblong tiles chosen from red (length two), green (length +! three), or blue (length four). + +! If red tiles are chosen there are exactly seven ways this can be done. +! If green tiles are chosen there are three ways. +! And if blue tiles are chosen there are two ways. + +! Assuming that colours cannot be mixed there are 7 + 3 + 2 = 12 ways of +! replacing the black tiles in a row measuring five units in length. + +! How many different ways can the black tiles in a row measuring fifty units in +! length be replaced if colours cannot be mixed and at least one coloured tile +! must be used? + +! SOLUTION +! -------- + +! This solution uses a simple dynamic programming approach using the +! following recurence relation + +! ways(n,_) = 0 | n < 0 +! ways(0,_) = 1 +! ways(n,i) = ways(n-i,i) + ways(n-1,i) +! solution(n) = ways(n,1) - 1 + ways(n,2) - 1 + ways(n,3) - 1 + + + +: (euler116) ( length -- permutations ) + 3 [1,b] [ ways ] with sigma ; + +: euler116 ( -- permutations ) + 50 (euler116) ; diff --git a/extra/project-euler/117/117.factor b/extra/project-euler/117/117.factor new file mode 100644 index 0000000000..5056560a85 --- /dev/null +++ b/extra/project-euler/117/117.factor @@ -0,0 +1,42 @@ +! Copyright (c) 2008 Eric Mertens +! See http://factorcode.org/license.txt for BSD license. +USING: kernel math splitting sequences ; + +IN: project-euler.117 + +! http://projecteuler.net/index.php?section=problems&id=117 + +! DESCRIPTION +! ----------- + +! Using a combination of black square tiles and oblong tiles chosen +! from: red tiles measuring two units, green tiles measuring three +! units, and blue tiles measuring four units, it is possible to tile a +! row measuring five units in length in exactly fifteen different ways. + +! How many ways can a row measuring fifty units in length be tiled? + +! SOLUTION +! -------- + +! This solution uses a simple dynamic programming approach using the +! following recurence relation + +! ways(i) = 1 | i <= 0 +! ways(i) = ways(i-4) + ways(i-3) + ways(i-2) + ways(i-1) + + + +: (euler117) ( n -- m ) + V{ 1 } clone tuck [ next ] curry times peek ; + +: euler117 ( -- m ) + 50 (euler117) ; diff --git a/extra/project-euler/150/150.factor b/extra/project-euler/150/150.factor new file mode 100644 index 0000000000..5b22a1b9f6 --- /dev/null +++ b/extra/project-euler/150/150.factor @@ -0,0 +1,44 @@ +! Copyright (c) 2008 Eric Mertens +! See http://factorcode.org/license.txt for BSD license. +USING: kernel math sequences locals ; +IN: project-euler.150 + + + +:: (euler150) ( m -- n ) + [let | table [ sums-triangle ] | + m [| x | + x 1+ [| y | + m x - [| z | + x z + table nth + [ y z + 1+ swap nth ] + [ y swap nth ] bi - + ] map partial-sums infimum + ] map-infimum + ] map-infimum + ] ; + +: euler150 ( -- n ) + 1000 (euler150) ;