RE: the simplest way?
- To: mathgroup at smc.vnet.net
- Subject: [mg16475] RE: [mg16350] the simplest way?
- From: "Jean-Marie THOMAS" <jmthomas at agat.net>
- Date: Tue, 16 Mar 1999 03:59:36 -0500
- Sender: owner-wri-mathgroup at wolfram.com
Try this: l=Table[Random[Integer,{1,100}],{10}] First question: Catch[Scan[If[OddQ[#],Throw[{#,False}]]&,l]] Second question: l/.x_->x-1 Third question: Map[f,l] All these are Mathematica basics! **************************************** Jean-Marie THOMAS mailto:jmthomas at agat.net Conseil et Audit en Ingenierie de Calcul Strasbourg, France http://www.agat.net **************************************** -----Original Message----- From: Antoine Zahnd [mailto:antoine.zahnd at iprolink.ch] To: mathgroup at smc.vnet.net Subject: [mg16475] [mg16350] the simplest way? Hello, I have two questions with lists, each time to avoid the Length function. 1) For example, how to write a function that will go thru the elements of a list of integers, and will return False as soon as an odd number is found, without using Length? With Length it is easy, but not so clean ... f[l_]:= Block[{k},For[k=1,k<=Length[l],k++,If[OddQ[l[[k]]],Return[True]]]; False]; 2) Is it possible to write the following function without Length? l={1,2,3}; Table[ReplacePart[l,l[[i]]-1,i],{i,1,Length[l]}] {{0,2,3},{1,1,3},{1,2,2}} More generally, is there a way to write something like: (for x in l ... collect (f x) ) , and the collection of the (f x) are returned in a list? I don't see how to write a Lisp style dolist function in Mathematica without the Length! Hope that the questions make sens ... Thank you very much for your help. antoine.zahnd at iprolink.ch