MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

neat way to program minimum of sum

  • To: mathgroup at
  • Subject: [mg75072] neat way to program minimum of sum
  • From: cgenie at (P. Kaminski)
  • Date: Mon, 16 Apr 2007 20:08:24 -0400 (EDT)

I need to program the following function:

f(t) = max{n>0 : X1 + ... + Xn > t}

where Xi are some random numbers. I've done it using Module and Wile:

f[t_]:=f[t]=Module[{i}, i=1; While[Total[Array[x, i]]<=t, i++]; Return[i-1]];

This works but requires Module and three instructions within. Can it
be simplified to a true one-liner, preferably with some functional
programming trick?

Thanks in advance,
P. Kaminski

  • Prev by Date: Re: Differentiation and evaluation of function
  • Next by Date: Re: what does this error message mean
  • Previous by thread: Re: Continued Fractions
  • Next by thread: Re: neat way to program minimum of sum