# N-Queens Combinatorial Problem

**URL:** <https://users.scala-lang.org/t/n-queens-combinatorial-problem/7575>\
**Category:** Announce\
**Created:** [July 5, 2021, 7:16am UTC](https://users.scala-lang.org/t/n-queens-combinatorial-problem/7575 "2021-07-05T07:16:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![philipschwarz](https://users.scala-lang.org/user_avatar/users.scala-lang.org/philipschwarz/32/3130_2.png) [@philipschwarz](https://users.scala-lang.org/u/philipschwarz)\
**Post date:** [July 5, 2021, 7:16am UTC](https://users.scala-lang.org/t/n-queens-combinatorial-problem/7575/1 "2021-07-05T07:16:09Z")

</div>

First see the problem solved using the List monad and a Scala for comprehension.

Then see the Scala program translated into Haskell, both using a do expression and using a List comprehension.

Understand how the Scala for comprehension is desugared, and what role the withFilter function plays.

Also understand how the Haskell do expression and List comprehension are desugared, and what role the guard function plays.

> **[N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Has…](https://www.slideshare.net/pjschwarz/nqueens-combinatorial-problem-polyglot-fp-for-fun-and-profit-haskell-and-scala-part-1)**
>
> First see the problem solved using the List monad and a Scala for comprehension. Then see the Scala program translated into Haskell, both using a do expressio…

---

<div class="post-metadata">

**Author:** ![philipschwarz](https://users.scala-lang.org/user_avatar/users.scala-lang.org/philipschwarz/32/3130_2.png) [@philipschwarz](https://users.scala-lang.org/u/philipschwarz)\
**Post date:** [August 1, 2021, 2:03pm UTC](https://users.scala-lang.org/t/n-queens-combinatorial-problem/7575/2 "2021-08-01T14:03:57Z")

</div>

Hi all, here is part 2.

See how the guard function has migrated from MonadPlus to Alternative and learn something about the latter.

Learn how to write a Scala program that draws an N-Queens solution board using the Doodle graphics library.

See how to write the equivalent Haskell program using the Gloss graphics library.  
learn how to use Monoid and Foldable to compose images both in Haskell and in Scala.

> **[N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Has…](https://www.slideshare.net/pjschwarz/nqueens-combinatorial-problem-polyglot-fp-for-fun-and-profit-haskell-and-scala-part-2)**
>
> See how the guard function has migrated from MonadPlus to Alternative and learn something about the latter. Learn how to write a Scala program that draws an N-…

---

<div class="post-metadata">

**Author:** ![philipschwarz](https://users.scala-lang.org/user_avatar/users.scala-lang.org/philipschwarz/32/3130_2.png) [@philipschwarz](https://users.scala-lang.org/u/philipschwarz)\
**Post date:** [August 22, 2021, 11:44am UTC](https://users.scala-lang.org/t/n-queens-combinatorial-problem/7575/3 "2021-08-22T11:44:04Z")

</div>

Hi all, here is part 3.

Learn how to write FP code that displays a graphical representation of all the numerous N-Queens solutions for N=4,5,6,7,8.

See how to neatly solve the problem by exploiting its self-similarity and using a divide and conquer approach.

Make light work of assembling multiple images into a whole, by exploiting Doodle’s facilities for combining images using a relative layout.

See relevant FP functions, like Foldable’s intercalate and intersperse, in action.

> **[N-Queens Combinatorial Problem - Polyglot FP for fun and profit - Has…](https://www.slideshare.net/pjschwarz/nqueens-combinatorial-problem-polyglot-fp-for-fun-and-profit-haskell-and-scala-part-3)**
>
> Learn how to write FP code that displays a graphical representation of all the numerous N-Queens solutions for N=4,5,6,7,8 . See how to neatly solve the proble…

---

<div class="post-metadata">

**Author:** ![philipschwarz](https://users.scala-lang.org/user_avatar/users.scala-lang.org/philipschwarz/32/3130_2.png) [@philipschwarz](https://users.scala-lang.org/u/philipschwarz)\
**Post date:** [October 4, 2021, 12:12pm UTC](https://users.scala-lang.org/t/n-queens-combinatorial-problem/7575/4 "2021-10-04T12:12:49Z")

</div>

Hi all, here is part 4.

See how feeding FP workhorses map and filter with monadic steroids turns them into the intriguing mapM and filterM.

Graduate to foldM by learning how it behaves with the help of three simple yet instructive examples of its usage.

Use the powers of foldM to generate all permutations of a collection with a simple one-liner.

Exploit what you learned about foldM to solve the N-Queens Combinatorial Problem with an iterative approach rather than a recursive one.

> **[N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit - Has…](https://www.slideshare.net/pjschwarz/n-queens-combinatorial-problem-polyglot-fp-for-fun-and-profit-haskell-and-scala-part-4)**
>
> See how feeding FP workhorses map and filter with monadic steroids turns them into the intriguing mapM and filterM. Graduate to foldM by learning how it behave…
