Re: Use pattern to find minimum without using min
- To: mathgroup at smc.vnet.net
- Subject: [mg71855] Re: Use pattern to find minimum without using min
- From: Peter Pein <petsie at dordos.net>
- Date: Fri, 1 Dec 2006 06:22:07 -0500 (EST)
- References: <ekmdbc$7th$1@smc.vnet.net>
wooks schrieb: > Tried > > {9, 4, 6, 5, 3, 7} //. {a___, b_, c___, d_, e___} :> b /; (b < d) > > and > > {9, 4, 6, 5, 3, 7} //. {x_,y_,z___} :> {x,z} /; (x<y) > > without much success. > Hi, your second example is not too bad, but you forgot the case x>=y: {9, 4, 6, 5, 3, 7} //. {{x1_, x2_, r___} /; x1 < x2 :> {x1, r}, {x1_, x2_, r___} /; x1 >= x2 :> {x2, r}} --> {3} or shorter: {9, 4, 6, 5, 3, 7} //. {x1_, x2_, r___} :> If[x1 < x2, {x1, r}, {x2, r}] Peter