-! Copyright (c) 2008 Eric Mertens
+! Copyright (c) 2008 Eric Mertens.
! See http://factorcode.org/license.txt for BSD license.
-USING: kernel sequences sequences.lib math math.functions math.ranges locals ;
+USING: kernel sequences math math.functions ranges project-euler.common ;
IN: project-euler.190
-! PROBLEM
-! -------
-
! http://projecteuler.net/index.php?section=problems&id=190
+! DESCRIPTION
+! -----------
+
! Let Sm = (x1, x2, ... , xm) be the m-tuple of positive real numbers
! with x1 + x2 + ... + xm = m for which Pm = x1 * x22 * ... * xmm is
-! maximised.
+! maximized.
! For example, it can be verified that [P10] = 4112 ([ ] is the integer
! part function).
! Find Σ[Pm] for 2 ≤ m ≤ 15.
+
! SOLUTION
! --------
PRIVATE>
:: P_m ( m -- P_m )
- m [1,b] [| i | 2 i * m 1+ / i ^ ] PI ;
+ m [1..b] [| i | 2 i * m 1 + / i ^ ] PI ;
+
+: euler190 ( -- answer )
+ 2 15 [a..b] [ P_m truncate ] map-sum ;
+
+! [ euler150 ] 100 ave-time
+! 5 ms ave run time - 1.01 SD (100 trials)
-: euler190 ( -- n )
- 2 15 [a,b] [ P_m truncate ] sigma ;
+SOLUTION: euler190