Search code examples
answer-set-programmingclingo

How do I generate a fixed sized list of facts (duplicates included)?


I'm new to ASP & Clingo and I need to work on a project for school. I thought about some basic music generator.

For now, I need to generate notes (I'm sticking with C major for now). I also want to generate them randomly and I don't know how to do that. How can I make the following code generate a random sequence of notes (duplicates too)?

note(c;d;e;f;g;a;b).

20 { play(X) : note(X)} 30.

#show play/1.

So far, the code won't allow for more than 7 as the upper bound, because it won't show duplicate notes.

Current output: play(b) play(g) play(e) play(c)

Wanted output: play(d) play(g) play(f) ...[20-30 randomly generated notes]

I want to be able to add constraints later (such as this note should not be followed by that note, and so on). I appreciate any tips since I know so little about this.


Solution

  • An answer set is a set. The atoms have no order and duplicates are not possible because it is a set.

    You want to guess one note for each beat.

    beat(1..8).

    1 { play(N,B) : note(N) } 1 :- beat(B).