Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

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

Search the Archive

Re: A friendly challenge: Generalized Partition

  • To: mathgroup at smc.vnet.net
  • Subject: [mg34908] Re: A friendly challenge: Generalized Partition
  • From: "Carl K. Woll" <carlw at u.washington.edu>
  • Date: Wed, 12 Jun 2002 02:15:47 -0400 (EDT)
  • References: <ae4e7h$97i$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Here is a version based on some code that several of us worked on when we
were trying to simulate Split in Mathematica version 2.

hh[s_,t_]:=Take[s,#]&/@Transpose[{Drop[#,-1],Rest[#]-1}]&@FoldList[Plus,1,t]

Carl Woll
Physics Dept
U of Washington

----- Original Message -----
From: ""Mr. Wizard"" <gleam at flashmail.com>
To: mathgroup at smc.vnet.net
Subject: [mg34908] A friendly challenge: Generalized Partition


> In the 4.1 help browser, in Further Examples under Take, there is code
> for a generalized partition function, called gg.  This code is
> somewhat long and extremely slow.  I challenge you to duplicate the
> functionality of this code (ignoring the ggCheckArgs condition), while
> making it 1) as sort as possible, and/or 2) as fast as possible.
>
> Your function must be in good form, leaving no stray assignments, i.e.
> using the appropriate scoping construct(s).
>
> For efficiency testing, I will use (where func is your function):
>
> a = Range[2000];
> b = Table[Random[Integer, {1, 20}], {150}];
> First[Timing[Do[func[a, b], {100}]]]
>
> I will post my versions after a little while.  For reference, on my
> machine, the function from the help files, omitting the ggCheckArgs
> condition, takes 8 seconds; my fastest version takes 0.33 seconds.  My
> shortest version is 44 characters in length, and takes 0.94 seconds.
>
> Good luck!
>
> Paul
>
>




  • Prev by Date: RE: "TableLabel"?
  • Next by Date: Re: Using Mathgroup Effectively -- cutting and pasting expressions
  • Previous by thread: A friendly challenge: Generalized Partition
  • Next by thread: Re: A friendly challenge: Generalized Partition