MathGroup Archive 1999

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

Search the Archive

RE: the simplest way?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16440] RE: [mg16350] the simplest way?
  • From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
  • Date: Sat, 13 Mar 1999 02:21:49 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

Antoine Zahnd  wrote:
------------------------
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?

---------------------
Use the code below.

In[96]:=
lst={2,0,6,7,8,12,3,5};
Not at MemberQ[lst,_?OddQ]
Out[96]=
False


Here is evidence that it stops after it finds an odd number.


In[93]:=
Not at MemberQ[lst,_?((Print[#];OddQ[#])&)]
2
0
6
7
Out[93]=
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}}


Yes, but I am having a hard time finding a way to do it that doesn't look
like a mess.
Why do you insist on avoiding Length?

Regards,
Ted Ersek


  • Prev by Date: Re: the simplest way?
  • Next by Date: Re: Eliminating (-1)^2
  • Previous by thread: Re: the simplest way?
  • Next by thread: Re: the simplest way?