From 9152b6d5f0b1c47b9ffbc448eaa3315456f389b1 Mon Sep 17 00:00:00 2001 From: Aaron Schaefer Date: Mon, 3 Nov 2008 18:25:50 -0500 Subject: [PATCH] Cleanup of Project Euler problem 92 --- extra/project-euler/092/092.factor | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/extra/project-euler/092/092.factor b/extra/project-euler/092/092.factor index ea131d6e1b..c778fd9525 100644 --- a/extra/project-euler/092/092.factor +++ b/extra/project-euler/092/092.factor @@ -1,6 +1,6 @@ ! Copyright (c) 2008 Aaron Schaefer, Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: kernel math math.ranges sequences ; +USING: kernel math math.ranges project-euler.common sequences ; IN: project-euler.092 ! http://projecteuler.net/index.php?section=problems&id=92 @@ -29,7 +29,7 @@ IN: project-euler.092 digits [ sq ] sigma ; : chain-ending ( n -- m ) dup [ 1 = ] [ 89 = ] bi or [ next-link chain-ending ] unless ; @@ -40,15 +40,14 @@ IN: project-euler.092 : fast-chain-ending ( seq n -- m ) dup 567 > [ next-link ] when 1- swap nth ; -: count ( seq quot -- n ) - 0 -rot [ rot >r call [ r> 1+ ] [ r> ] if ] curry each ; inline - PRIVATE> : euler092 ( -- answer ) lower-endings 9999999 [1,b] [ fast-chain-ending 89 = ] with count ; ! [ euler092 ] 10 ave-time -! 11169 ms run / 0 ms GC ave time - 10 trials +! 33257 ms ave run time - 624.27 SD (10 trials) + +! TODO: this solution is not very efficient, much better optimizations exist MAIN: euler092