Permutations with constraints

In order to apply constraints while generating permutations, I needed a new algorithm. Haskell’s library function Data.List.permutations builds permutations using interleave, so each item added could end up anywhere in the list. I needed items to stay in the same place once chosen. Note that this performs much worse than Data.List.permutations, because it has toContinue reading “Permutations with constraints”

Magic Square by brute force

This was inspired by Tsoder’s video where he generated all the 3×3 magic squares by brute force, generating all permutations of 1-9 and rejecting the ones which were not magic squares. My first reaction was that that was not brute force; this was brute force: This turned out to be faster than Tsoder’s method,Continue reading “Magic Square by brute force”