LuckyNumber with Prolog

Hi all , i’m a newbie at prolog, i’m trying to resolve this exercise Coding Games and Programming Challenges to Code Better

I’m not able to resolve it, what i got so far is this
https://justpaste.it/9s34j

At first step i was trying to check a list of single digit (1,10) it seems to count 6 and 8 (if i debug the code i see that the var P goes to 2) but then the output is 0 :\

Also i don’t know how to edit the check in order to works with more digits (like 16) as well, if someone could explain it to me would be really appreciate.

A post was merged into an existing topic: [Community Puzzle] The Lucky Number