From cf19d8a37cef0c510381c066b376315bd96e2611 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Mon, 31 Dec 2007 02:59:53 +0100 Subject: [PATCH] Factor solution to project Euler problem 173 --- extra/project-euler/173/173.factor | 34 ++++++++++++++++++++++++ extra/project-euler/project-euler.factor | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 extra/project-euler/173/173.factor diff --git a/extra/project-euler/173/173.factor b/extra/project-euler/173/173.factor new file mode 100644 index 0000000000..4eef3ec3e2 --- /dev/null +++ b/extra/project-euler/173/173.factor @@ -0,0 +1,34 @@ +! Copyright (c) 2007 Aaron Schaefer. +! See http://factorcode.org/license.txt for BSD license. +USING: kernel math math.functions math.ranges sequences ; +IN: project-euler.173 + +! http://projecteuler.net/index.php?section=problems&id=173 + +! DESCRIPTION +! ----------- + +! We shall define a square lamina to be a square outline with a square +! "hole" so that the shape possesses vertical and horizontal +! symmetry. For example, using exactly thirty-two square tiles we can +! form two different square laminae: [see URL for figure] + +! With one-hundred tiles, and not necessarily using all of the tiles at +! one time, it is possible to form forty-one different square laminae. + +! Using up to one million tiles how many different square laminae can be +! formed? + +! SOLUTION +! -------- + +: laminaes ( upper -- n ) + 4 / dup sqrt [1,b] 0 rot [ over /mod drop - - ] curry reduce ; + +: euler173 ( -- answer ) + 1000000 laminaes ; + +! [ euler173 ] 100 ave-time +! 0 ms run / 0 ms GC ave time - 100 trials + +MAIN: euler173 diff --git a/extra/project-euler/project-euler.factor b/extra/project-euler/project-euler.factor index f256f03138..68c71da049 100644 --- a/extra/project-euler/project-euler.factor +++ b/extra/project-euler/project-euler.factor @@ -10,7 +10,7 @@ USING: definitions io io.files kernel math math.parser sequences strings project-euler.067 project-euler.134 project-euler.169 - project-euler.175 ; + project-euler.173 project-euler.175 ; IN: project-euler