1

In wxmaxima, for my assignment I was given a list exp. L:[1,-2,3,4,-5,11,-12]

I need to count members of the list that are less than 0, print that data and print such members. I used:

L:[1,-2,3,4,-5,11,-12]$
n: length(L)$
for k:1 thru n step 1 do
if L[k]<0 then print(L[k]);

and I got:

-2
-5
-12
done

My question is, how do I get the number of members,which in this example would be 3, printed?

Robert Dodier
  • 16,905
  • 2
  • 31
  • 48
Kugelblitz
  • 11
  • 1
  • There are different ways to go about it, but a simple way is to say `foo: sublist(L, P)` where P is a predicate function, and then say `length(foo)`. A suitable predicate is, for example, `lambda([x], x < 0)`. – Robert Dodier Nov 05 '20 at 00:54

0 Answers0