Tech News
← Back to articles

Solving LinkedIn Queens with APL

read original related products more articles

Solving LinkedIn Queens with APL

14 Jun 2025 on Peter Vernigorov’s blog

A couple months ago I noticed that LinkedIn now has a few simple games. They’re not much to write home about, but I really enjoy playing Queens.

This week I saw two posts about solving the Queens game programmatically. Both were quite interesting to me, so I thought this was a good opportunity to also solve the game in my favourite language - APL - and share my experience. Having been using APL for Advent of Code, I wanted to share my passion for it with others.

Rules

The game is pretty straightforward: each colored region must have exactly one queen, and two queens cannot occupy the same row, column, or be adjacent. Multiple queens may share diagonals as long as they’re separated by at least one space.

Board

First, let’s choose a data structure. LinkedIn sends the initial state as a list of rows, assigning each color a number starting from 0. That works for APL too, so let’s create a 2‑dimensional board representing the image:

b←⍉⍪0 0 0 0 0 0 0 0 b⍪← 0 0 1 1 1 1 2 0 b⍪← 0 0 1 3 3 1 2 0 b⍪← 0 0 3 3 3 1 2 2 b⍪← 0 4 4 3 1 1 2 2 b⍪← 0 4 5 5 1 6 6 2 b⍪← 4 4 5 5 5 5 6 6 b⍪← 4 4 4 5 7 5 5 6

And print it, by assigning it to the screen represented by a box:

... continue reading