-2

I found the solution to this problem, but it does not work properly.

enter link description here

What is wrong? I always get the result 0.

num([]) -> 0;
num(NUMS) ->
        num(NUMS, 0).

num([H|L], Count) when H < 1 ->  %% use of guard
        num(L, Count+1);
num([_|L], Count) ->
        num(L, Count);
num([], Count) ->
        Count.

This is an example of use enter image description here

//Edit I found where is problem. This is correct code.

num([]) -> 0;
num(NUMS) ->
        num(NUMS, 0).

num([H|L], Count) when H < 1 ->  %% use of guard
        num(L, Count+1);
num([_|L], Count) ->
        num(L, Count+1);
num([], Count) ->
        Count.
pepe450
  • 1
  • 3

1 Answers1

0

You do not need first pattern in num/2 function:

num([_|L], Count) ->
        num(L, Count+1);
num([], Count) ->
        Count.

will be enough.

Alexei K
  • 142
  • 1
  • 5