Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Searching for a function.' topicStudent Support Forum > General > Archives > "Searching for a function."

< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic
Author Comment/Response
yehuda
01/22/13 04:39am

Try to use internal functions as much as possible. The key function here is Split, all the rest is "cosmetics"

l = {1, 2, 5, 9, 4, 2, 1, 10, 12, 1};
ups = Length@Select[Split[l, #1 < #2 &], Length[#] > 1 &]
downs = Length@Select[Split[l, #1 > #2 &], Length[#] > 1 &]

or similarly, using Count

ups=Count[Split[l, #1 < #2 &], x_ /; Length[x] > 1]
downs=Count[Split[l, #1 > #2 &], x_ /; Length[x] > 1]

yehuda

URL: ,

Subject (listing for 'Searching for a function.')
Author Date Posted
Searching for a function. Student Konrad 01/21/13 4:23pm
Re: Searching for a function. Bill Simpson 01/21/13 7:38pm
Re: Searching for a function. Bill Simpson 01/22/13 01:11am
Re: Searching for a function. yehuda 01/22/13 04:39am
Re: Searching for a function. Student Konrad 01/22/13 3:22pm
< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic