Write a function in Scheme or rules in Prolog called countlt that takes a list of numbers, L, and another number, N, and returns the count of numbers less than N in the list L. Example calls Scheme: (countlt '(6 1 9 ) 4) -> 1 ((countlt '(50 27 13 ) 1 )-> 0 Prolog ?- countlt ( [6, 1, 9], 4, X). X = 1. ?- countlt([SO, 27, 13], 1, X) X = 0. ( define countlt (lambda (L N ) (cond ((null? L ) 0 ) ((< ( car L) N) (+ 1 (countlt (cdr L ) N ))) ((else (countlt (cdr L ) N))))) countlt([], _, 0). counttl([H|T], N, X ): - H >= N, countlt(T,N, X ). countlt([H|T, N,X countlt ((T,N,C), H < N, X is C + 1.
Write a function in Scheme or rules in Prolog called countlt that takes a list of numbers, L, and another number, N, and returns the count of numbers less than N in the list L.
Example calls
Scheme:
(countlt '(6 1 9 ) 4) -> 1
((countlt '(50 27 13 ) 1 )-> 0
Prolog
?- countlt ( [6, 1, 9], 4, X).
X = 1.
?- countlt([SO, 27, 13], 1, X)
X = 0.
( define countlt (lambda (L N )
(cond
((null? L ) 0 )
((< ( car L) N) (+ 1 (countlt (cdr L ) N )))
((else (countlt (cdr L ) N)))))
countlt([], _, 0).
counttl([H|T], N, X ): -
H >= N,
countlt(T,N, X ).
countlt([H|T, N,X
countlt ((T,N,C),
H < N, X is C + 1.

Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images









