Hi,
If you ever wondered, how to persuade a Constraint solver to do some bluegrass improvisations (no you haven't), wait no longer. Here is the answer:
Ok, it is not really "improvisation" but the generation of a melody under hand crafted constraints. But the constraints are similar to what you would read in books about bluegrass improvisation (Use the pentatonic scale..) minus the musicality ;-).
Nevertheless i hope this is a good start for your own experiments with music and constraint programming.
The tough part was getting all the music libraries to work in the notebook, but thats software development (80% of the time you are spent with tasks not really relevant to what you want to achieve).
The implementation using Google's CP-SAT Solver (Google's CP SAT Solver) can be found in this github gist Fun With CP Bluegrass Improvisation.
If you are using Google's Colaboratoy (http://colab.research.google.com/) you should be able to open and run the notebook with "open in colab".
This is the result of one of the constraint solvers "solos":
And here are some examples, how real solos should sound ;-):
Blogging is dead, long live blogging. Ok, maybe i binge-watched too much Big Bang Theory but inspired by Sheldon Coopers "Fun with Flags" i started the "Fun with Constraint Programming" blog. This will hopefully contain fun (nerdy) things to do with Constraint Programming. If you are looking for a more general blog about constraint programming i recommend the excellent blog Constraint Programming Blog by Hakank K.
Sunday, February 17, 2019
Friday, January 11, 2019
Magic Square 2019
Magic Square 2019
Lets start with a magic square. In a magic square the sum of the rows and cells are all the same(magic) number and every number appears only once.
Dürer Magic
In 1514 Albrecht Dürer created a famous Magic Square contained in his work Melencolia, which also contained the numbers 15 and 14 next to each other i.e. the year of its creation. As you can check for yourself the sum of the numbers in each row and columns is the same number, called magic constant, in this case 34.![]() |
| Dürers Magic Square (source Wikipedia) |
Happy New Year Square
For the New Year i wanted to create a magic square for 2019 like Dürer did with 1514. Only then i realized, if one adds 5 to every cell of Dürer Square we already have (a kind of) magic square for 2019:| 21 | 8 | 7 | 18 |
| 10 | 15 | 16 | 13 |
| 14 | 11 | 12 | 17 |
| 9 | 20 | 19 | 6 |
Ok, this would be too boring even for this blog.
So how can we get a real Magic Square 2019?
First of all we need a bigger square as 20 and 19 should appear in it. Let's use a 6x6 square so we can put the year in the middle of the last row. Then we'll have to add the additional constraints (all numbers must be different, the sums of rows and columns must be the same magic constant) and let the constraint solver do its magic.
An implementation using Google's CP-SAT Solver (Google's CP SAT Solver) can be found in this github gist Fun With CP Magic Square 2019.
If you are using Google's Colaboratoy (http://colab.research.google.com/) you should be able to open and run the notebook with "open in colab".
Alternatively you can use your local python Jupyter environment. It should be easy to port it to your favourite constraint solver.
Happy New Year &
Have fun with Constraint Programming!
PS:
Hope you had as much fun as:
Subscribe to:
Posts (Atom)
Solving CSP problems in the browser with Sentient
It is surprising difficult to find a CSP Solver for solving CSP Problems directly in Javascript. One such systems is Sentient https://sent...
-
It is surprising difficult to find a CSP Solver for solving CSP Problems directly in Javascript. One such systems is Sentient https://sent...
-
Magic Square 2019 Lets start with a magic square. In a magic square the sum of the rows and cells are all the same (magic) number and ev...
-
Hi, If you ever wondered, how to persuade a Constraint solver to do some bluegrass improvisations (no you haven't), wait no longer. Her...

