?- length(Ls, 9),global_cardinality(Ls, [0-_,1-Ones]),Ones #>= 4,label(Ls).Ls = [0, 0, 0, 0, 0, 1, 1, 1, 1],Ones = 4 ;Ls = [0, 0, 0, 0, 1, 0, 1, 1, 1],Ones = 4 ;Ls = [0, 0, 0, 0, 1, 1, 0, 1, 1],Ones = 4 ;Ls = [0, 0, 0, 0, 1, 1, 1, 0, 1],Ones = 4 .
On 25/11/2017, at 14:06, Joseph Haley <josephhal...@gmail.com> wrote:I'm trying to get more into learning prolog as I'll be taking an AI class at school next semester. I've been able to get down the basics down and can do relation based stuff, however, I've been trying to learn permutations and combinatorics and they seem pretty straightforward, but it led me to a question that I can't figure out how to solve. Say I wanted to know the permutations of 1’s and 0's with a certain condition that there must be at least 4 1's in a row.
I have no idea where I would start to try and find a solution for this, but in the end I want the code to do something like this:
?- placeOnesAndZeros(9,X). %where 9 is the length of the list/array and X is the permutations
[0,0,0,0,0,0,0,0,0]