top of page
Search

8 Queens as a Marcel One-Liner

Writer's picture: Jack OrensteinJack Orenstein

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.

72 views0 comments

Recent Posts

See All

Compiling Marcel to Python

Marcel is interpreted. A command like this: gen 100 | map (x: (x, x**0.5)) | write gives rise to objects of type marcel.op.Gen,...

Marcel in more places

Thanks to two different pilot errors on my part, I have broken the packaging system of two OSes that package marcel. I would have had no...

Comments


  • github
  • email
bottom of page