Previous Up Next

6.42.30  Compter les éléments d’une liste ou d’une matrice vérifiant une propriété : count

count a un, deux ou trois paramètres :

  1. une liste d’entiers L

Lorsque count a :

On tape :

count([1,3,1,1,2,10,3])

On obtient :

[[1,3],[2,1],[3,2],[10,1]]

On tape :

count((x)->x,[2,12,45,3,7,78])

Ou on tape :

count((x)->x,[[2,12,45],[3,7,78]])

On obtient :

147

car on a : 2+12+45+3+7+78=147.
On tape :

count((x)->x,[[2,12,45],[3,7,78]],row)

On obtient :

[59,88]

car on a : 2+12+45=59 et 3+7+78=88.
On tape :

count((x)->x,[[2,12,45],[3,7,78]],col)

On obtient :

[5,19,123]

car on a : 2+3=5,12+7=10,45+78=123.
On tape :

count((x)->x<12,[2,12,45,3,7,78])

On obtient :

3

On tape :

count((x)->x==12,[2,12,45,3,7,78])

Ou on tape :

count((x)->x==12,[[2,12,45],[3,7,78]])

On obtient :

1

On tape :

count((x)->x>12,[2,12,45,3,7,78])

On obtient :

2

On tape :

count(x->x^2,[3,5,1])

On obtient :

35

En effet on a : 32+52+11=35.
On tape :

count(id,[3,5,1])

On obtient :

9

En effet, id est la fonction identité et on a : 3+5+1=9.
On tape :

count(1,[3,5,1])

On obtient :

3

En effet, 1 est la fonction constante égale à 1 et on a : 1+1+1=3.


Previous Up Next