Yes, the 8 Queens problem can be solved in marcel, as a one-liner even. If you want the details, you can find them here. But the basic idea is this:
Use Python's itertools.permutations to generate candidates.
Write a function to check the candidate for queen attacks along diagonals.
Pipe the candidates to the checking function.
Well, that's cheating, isn't it? I mean, all the work is being done in Python, either with a library function (itertools.permutation) or a lambda.
That's sort of the point. Marcel makes it really easy to use Python from the command line, and then combine those bits of logic. Sure, you could write eightqueens.py, and the code would be much the same. Or, if for some reason you really want to do 8 queens as a shell script, bash can do the job. But right from the command line? I don't think any other shells can do that.
Comments