I am new to prolog. I was asked this question. I cannot be done in SWI-Prolog. Just in prolog base (not sure what to call it). All the answers I found were in SWI-Prolog.
First element of each nested list is either a 0
or a 1
. The second element of each nested list is some integer.
As an example: [[0 1] [1 2] [1 3] [0 4] [0 3]]
First element of each nested list is the key and the second element of the nested lists is the value.
In prolog, implement a predicate, count by cat/2
, that takes such a list as input and yields a two element list where:
- the first element is the sum of the values of all nested lists with
0
as the key, and - the second element is the sum of the values of all nested lists with
1
as the key.