• About TC
  • Affiliate Disclaimer
  • Privacy Policy
  • TOS
  • Contact
Monday, June 16, 2025
Techcratic
  • TC
  • AI
    Artificial Intelligence

    Amazon Nova Lite enables Bito to offer a free tier option for its AI-powered code reviews

    Artificial Intelligence

    Bridging the Gap: New Datasets Push Recommender Research Toward Real-World Scale

    Artificial Intelligence

    7 Python Errors That Are Actually Features

    Artificial Intelligence

    10 Awesome OCR Models for 2025

    Artificial Intelligence

    5 Error Handling Patterns in Python (Beyond Try-Except)

    Artificial Intelligence

    Top 5 Alternative Data Career Paths and How to Learn Them for Free

    Artificial Intelligence

    Implementing Machine Learning Pipelines with Apache Spark

    Artificial Intelligence

    Learn Power BI for Free This Week

    Artificial Intelligence

    Build GraphRAG applications using Amazon Bedrock Knowledge Bases

  • Crypto
    Report: Justin Sun’s Tron Aims for Nasdaq Listing in High-Stakes Merger Deal

    Report: Justin Sun’s Tron Aims for Nasdaq Listing in High-Stakes Merger Deal

    Best Presales to Buy Today – Which Coins Are Poised for a Breakout?

    2025’s Breakout Meme Coin? Why Everyone’s Rushing to Get a Piece of $AKE

    Metaplanet Acquires Additional 1,112 Bitcoin, Total Holdings Reach 10,000 BTC

    Metaplanet Acquires Additional 1,112 Bitcoin, Total Holdings Reach 10,000 BTC

    Crypto to “Become Part of All Sectors” Under Trump: Kevin O’Leary

    Metaplanet Issues Fresh $210M Bonds to Evo Fund

    Bitcoin Going to $1M: Saylor’s Call Revives Interest in Adam Back’s 21M BTC Order

    Bitcoin Going to $1M: Saylor’s Call Revives Interest in Adam Back’s 21M BTC Order

    Bitcoin Eyes $30T Treasury Store of Value Market, Says Bitwise CEO

    Bitcoin Eyes $30T Treasury Store of Value Market, Says Bitwise CEO

    ZKJ Token Plummets More Than 60% in Flash Crash Amid Rug-Pull Allegations

    ZKJ Token Plummets More Than 60% in Flash Crash Amid Rug-Pull Allegations

    Bitcoin Holding $105K During War Is Bullish for Crypto

    Bitcoin Holding $105K During War Is Bullish for Crypto

    Saylor Signals Another Bitcoin Buy—Orange Dots Strike Again

    Saylor Signals Another Bitcoin Buy—Orange Dots Strike Again

  • Cybersecurity
    Cybersecurity

    AI Agents Run on Secret Accounts — Learn How to Secure Them in This Webinar

    Cybersecurity

    How to Address the Expanding Security Risk

    Cybersecurity

    ConnectWise to Rotate ScreenConnect Code Signing Certificates Due to Security Risks

    Cybersecurity

    5 Lessons from River Island

    Cybersecurity

    INTERPOL Dismantles 20,000+ Malicious IPs Linked to 69 Malware Variants in Operation Secure

    Cybersecurity

    SinoTrack GPS Devices Vulnerable to Remote Vehicle Control via Default Passwords

    Cybersecurity

    Researchers Uncover 20+ Configuration Risks, Including Five CVEs, in Salesforce Industry Cloud

    Cybersecurity

    Adobe Releases Patch Fixing 254 Vulnerabilities, Closing High-Severity Security Gaps

    Cybersecurity

    Researcher Found Flaw to Discover Phone Numbers Linked to Any Google Account

  • Deals
    Lexar 128GB (2-PK) Professional SILVER PRO SD Card, UHS-II, C10, U3, V60, Full HD, 4K,…

    Lexar 128GB (2-PK) Professional SILVER PRO SD Card, UHS-II, C10, U3, V60, Full HD, 4K,…

    SABRENT 2.5 Inch SATA to USB 3.0 Tool Free External Hard Drive Enclosure [Optimized for…

    SABRENT 2.5 Inch SATA to USB 3.0 Tool Free External Hard Drive Enclosure [Optimized for…

    B221000 Black Toner Cartridge B/MB2236 Replacement for Lexmark B221000 Toner Cartridge…

    B221000 Black Toner Cartridge B/MB2236 Replacement for Lexmark B221000 Toner Cartridge…

    Lexar 1TB Professional Go Portable SSD w/Hub, Supports Apple 4K 60fps ProRes, Up to…

    Lexar 1TB Professional Go Portable SSD w/Hub, Supports Apple 4K 60fps ProRes, Up to…

    Kingston NV3 1TB M.2 2280 NVMe SSD | PCIe 4.0 Gen 4×4 | Up to 6000 MB/s | SNV3S/1000G

    Kingston NV3 1TB M.2 2280 NVMe SSD | PCIe 4.0 Gen 4×4 | Up to 6000 MB/s | SNV3S/1000G

    Intel Core Ultra 7 Desktop Processor 265K – 20 cores (8 P-cores + 12 E-cores) up to 5.5…

    Intel Core Ultra 7 Desktop Processor 265K – 20 cores (8 P-cores + 12 E-cores) up to 5.5…

    Hitachi FIJ0038 Fuel Injector

    Hitachi FIJ0038 Fuel Injector

    EVGA Supernova 1300 P+, 80+ Platinum 1300W, Fully Modular, 10 Year Warranty, Includes…

    EVGA Supernova 1300 P+, 80+ Platinum 1300W, Fully Modular, 10 Year Warranty, Includes…

    Logitech G502 X Plus Wireless Gaming Mouse – LIGHTSPEED Optical, LIGHTFORCE Switches,…

    Logitech G502 X Plus Wireless Gaming Mouse – LIGHTSPEED Optical, LIGHTFORCE Switches,…

  • Gaming
    Fortnite CHAPTER 6 SEASON 3 – Trailer

    Fortnite CHAPTER 6 SEASON 3 – Trailer

    Minions Paradise – Gameplay Walkthrough Part 1 – Level 1-3 (iOS, Android)

    Minions Paradise – Gameplay Walkthrough Part 1 – Level 1-3 (iOS, Android)

    The new Windows 11 Insider release has a weird bug where it plays the Windows Vista start-up music instead of the current one

    The new Windows 11 Insider release has a weird bug where it plays the Windows Vista start-up music instead of the current one

    Flip 7 Review – Is It The Greatest Card Game of All Time?

    Flip 7 Review – Is It The Greatest Card Game of All Time?

    NEW GAME TRAILERS 2021 |PART 1| |FOR THE LOVE OF GAMING|

    NEW GAME TRAILERS 2021 |PART 1| |FOR THE LOVE OF GAMING|

    WWE 2K25 Review – Two Steps Forward, One Step Back

    WWE 2K25 Review – Two Steps Forward, One Step Back

    Honest Game Trailers | WoW: Wrath of the Lich King

    Honest Game Trailers | WoW: Wrath of the Lich King

    Hello Neighbor – Finland Story | Full Game Walkthrough

    Hello Neighbor – Finland Story | Full Game Walkthrough

    Elden Ring NIGHTREIGN Early Reviews Say It All….

    Elden Ring NIGHTREIGN Early Reviews Say It All….

  • Tesla
    Winch Stopper,Winch Accessories,Car Accessories Winch Cable Stopper,Rubber Winch…

    Winch Stopper,Winch Accessories,Car Accessories Winch Cable Stopper,Rubber Winch…

    LUCKEASY 2PCS Storage Box Compatible with Tesla Cybertruck 2024 2023 Center Console…

    LUCKEASY 2PCS Storage Box Compatible with Tesla Cybertruck 2024 2023 Center Console…

    Tesla on ‘self-driving’ gets stuck on train track and hit by train

    Tesla on ‘self-driving’ gets stuck on train track and hit by train

    Level 1/2 Tesla Charger – 16A 3.84KW Mobile EV Charging with 240V NEMA 6-20 Plug, 5-15…

    Level 1/2 Tesla Charger – 16A 3.84KW Mobile EV Charging with 240V NEMA 6-20 Plug, 5-15…

    Upgrade fit Tesla Model Y (2019-2023) Center Console Wireless Charger Mat – Silicone…

    Upgrade fit Tesla Model Y (2019-2023) Center Console Wireless Charger Mat – Silicone…

    Torx Plus Socket, 5-External Torx Socket 1/4″ Dr 10EPR Compatible With Tesla Model 3…

    Torx Plus Socket, 5-External Torx Socket 1/4″ Dr 10EPR Compatible With Tesla Model 3…

    Car Seat Organizers,Multi-functional Back Seat Protectors, Storage Pouches, and Tray…

    Car Seat Organizers,Multi-functional Back Seat Protectors, Storage Pouches, and Tray…

    AOHI USB C Car Charger, PD 45W&QC 30W 2 Port Type-C Fast Charging Car Charger Lighter…

    AOHI USB C Car Charger, PD 45W&QC 30W 2 Port Type-C Fast Charging Car Charger Lighter…

    Roof Sunshades for Tesla Model 3 2025, Upgraded 3.0 Sunroof Shade Sunshade Roof Sun…

    Roof Sunshades for Tesla Model 3 2025, Upgraded 3.0 Sunroof Shade Sunshade Roof Sun…

  • UFO
    I SHREDDED Alien's Belongings in VR! – Blinnk and the Vacuum of Space VR

    I SHREDDED Alien's Belongings in VR! – Blinnk and the Vacuum of Space VR

    Mind Blowing Encounters with Spiritual Beings and Astral Realms – With Erik Unger P-2

    Mind Blowing Encounters with Spiritual Beings and Astral Realms – With Erik Unger P-2

    Katie’s Bumpers Frequent Flyer UFO Yellow – FF7YEL

    Katie’s Bumpers Frequent Flyer UFO Yellow – FF7YEL

    Did Ancient astronauts visit Earth?? new evidence fuels extraterrestrial Theories! #viral #history

    Did Ancient astronauts visit Earth?? new evidence fuels extraterrestrial Theories! #viral #history

    INFUNLY 4pcs Solar System Patches Iron on Sequin Planet Embroidery Patch Rainbow UFO Patch Space Sew on Patch Spacecraft Patch Celestial Applique for DIY Clothing Jeans Bags Jacket Backpack Hat

    INFUNLY 4pcs Solar System Patches Iron on Sequin Planet Embroidery Patch Rainbow UFO Patch Space Sew on Patch Spacecraft Patch Celestial Applique for DIY Clothing Jeans Bags Jacket Backpack Hat

    UFO Cover Up – They Want You Confused About the Truth!

    UFO Cover Up – They Want You Confused About the Truth!

    Nitro Green for Men – 3.4 oz EDP Spray

    Nitro Green for Men – 3.4 oz EDP Spray

    Argentinian Town Has One Of The Best Documented Mass UFO Sightings | The Unexplained Files

    Football Fan Patch Trucker Hat – Netted Snapback Baseball Cap with Team Design for Men & Women

    Football Fan Patch Trucker Hat – Netted Snapback Baseball Cap with Team Design for Men & Women

No Result
View All Result
  • TC
  • AI
    Artificial Intelligence

    Amazon Nova Lite enables Bito to offer a free tier option for its AI-powered code reviews

    Artificial Intelligence

    Bridging the Gap: New Datasets Push Recommender Research Toward Real-World Scale

    Artificial Intelligence

    7 Python Errors That Are Actually Features

    Artificial Intelligence

    10 Awesome OCR Models for 2025

    Artificial Intelligence

    5 Error Handling Patterns in Python (Beyond Try-Except)

    Artificial Intelligence

    Top 5 Alternative Data Career Paths and How to Learn Them for Free

    Artificial Intelligence

    Implementing Machine Learning Pipelines with Apache Spark

    Artificial Intelligence

    Learn Power BI for Free This Week

    Artificial Intelligence

    Build GraphRAG applications using Amazon Bedrock Knowledge Bases

  • Crypto
    Report: Justin Sun’s Tron Aims for Nasdaq Listing in High-Stakes Merger Deal

    Report: Justin Sun’s Tron Aims for Nasdaq Listing in High-Stakes Merger Deal

    Best Presales to Buy Today – Which Coins Are Poised for a Breakout?

    2025’s Breakout Meme Coin? Why Everyone’s Rushing to Get a Piece of $AKE

    Metaplanet Acquires Additional 1,112 Bitcoin, Total Holdings Reach 10,000 BTC

    Metaplanet Acquires Additional 1,112 Bitcoin, Total Holdings Reach 10,000 BTC

    Crypto to “Become Part of All Sectors” Under Trump: Kevin O’Leary

    Metaplanet Issues Fresh $210M Bonds to Evo Fund

    Bitcoin Going to $1M: Saylor’s Call Revives Interest in Adam Back’s 21M BTC Order

    Bitcoin Going to $1M: Saylor’s Call Revives Interest in Adam Back’s 21M BTC Order

    Bitcoin Eyes $30T Treasury Store of Value Market, Says Bitwise CEO

    Bitcoin Eyes $30T Treasury Store of Value Market, Says Bitwise CEO

    ZKJ Token Plummets More Than 60% in Flash Crash Amid Rug-Pull Allegations

    ZKJ Token Plummets More Than 60% in Flash Crash Amid Rug-Pull Allegations

    Bitcoin Holding $105K During War Is Bullish for Crypto

    Bitcoin Holding $105K During War Is Bullish for Crypto

    Saylor Signals Another Bitcoin Buy—Orange Dots Strike Again

    Saylor Signals Another Bitcoin Buy—Orange Dots Strike Again

  • Cybersecurity
    Cybersecurity

    AI Agents Run on Secret Accounts — Learn How to Secure Them in This Webinar

    Cybersecurity

    How to Address the Expanding Security Risk

    Cybersecurity

    ConnectWise to Rotate ScreenConnect Code Signing Certificates Due to Security Risks

    Cybersecurity

    5 Lessons from River Island

    Cybersecurity

    INTERPOL Dismantles 20,000+ Malicious IPs Linked to 69 Malware Variants in Operation Secure

    Cybersecurity

    SinoTrack GPS Devices Vulnerable to Remote Vehicle Control via Default Passwords

    Cybersecurity

    Researchers Uncover 20+ Configuration Risks, Including Five CVEs, in Salesforce Industry Cloud

    Cybersecurity

    Adobe Releases Patch Fixing 254 Vulnerabilities, Closing High-Severity Security Gaps

    Cybersecurity

    Researcher Found Flaw to Discover Phone Numbers Linked to Any Google Account

  • Deals
    Lexar 128GB (2-PK) Professional SILVER PRO SD Card, UHS-II, C10, U3, V60, Full HD, 4K,…

    Lexar 128GB (2-PK) Professional SILVER PRO SD Card, UHS-II, C10, U3, V60, Full HD, 4K,…

    SABRENT 2.5 Inch SATA to USB 3.0 Tool Free External Hard Drive Enclosure [Optimized for…

    SABRENT 2.5 Inch SATA to USB 3.0 Tool Free External Hard Drive Enclosure [Optimized for…

    B221000 Black Toner Cartridge B/MB2236 Replacement for Lexmark B221000 Toner Cartridge…

    B221000 Black Toner Cartridge B/MB2236 Replacement for Lexmark B221000 Toner Cartridge…

    Lexar 1TB Professional Go Portable SSD w/Hub, Supports Apple 4K 60fps ProRes, Up to…

    Lexar 1TB Professional Go Portable SSD w/Hub, Supports Apple 4K 60fps ProRes, Up to…

    Kingston NV3 1TB M.2 2280 NVMe SSD | PCIe 4.0 Gen 4×4 | Up to 6000 MB/s | SNV3S/1000G

    Kingston NV3 1TB M.2 2280 NVMe SSD | PCIe 4.0 Gen 4×4 | Up to 6000 MB/s | SNV3S/1000G

    Intel Core Ultra 7 Desktop Processor 265K – 20 cores (8 P-cores + 12 E-cores) up to 5.5…

    Intel Core Ultra 7 Desktop Processor 265K – 20 cores (8 P-cores + 12 E-cores) up to 5.5…

    Hitachi FIJ0038 Fuel Injector

    Hitachi FIJ0038 Fuel Injector

    EVGA Supernova 1300 P+, 80+ Platinum 1300W, Fully Modular, 10 Year Warranty, Includes…

    EVGA Supernova 1300 P+, 80+ Platinum 1300W, Fully Modular, 10 Year Warranty, Includes…

    Logitech G502 X Plus Wireless Gaming Mouse – LIGHTSPEED Optical, LIGHTFORCE Switches,…

    Logitech G502 X Plus Wireless Gaming Mouse – LIGHTSPEED Optical, LIGHTFORCE Switches,…

  • Gaming
    Fortnite CHAPTER 6 SEASON 3 – Trailer

    Fortnite CHAPTER 6 SEASON 3 – Trailer

    Minions Paradise – Gameplay Walkthrough Part 1 – Level 1-3 (iOS, Android)

    Minions Paradise – Gameplay Walkthrough Part 1 – Level 1-3 (iOS, Android)

    The new Windows 11 Insider release has a weird bug where it plays the Windows Vista start-up music instead of the current one

    The new Windows 11 Insider release has a weird bug where it plays the Windows Vista start-up music instead of the current one

    Flip 7 Review – Is It The Greatest Card Game of All Time?

    Flip 7 Review – Is It The Greatest Card Game of All Time?

    NEW GAME TRAILERS 2021 |PART 1| |FOR THE LOVE OF GAMING|

    NEW GAME TRAILERS 2021 |PART 1| |FOR THE LOVE OF GAMING|

    WWE 2K25 Review – Two Steps Forward, One Step Back

    WWE 2K25 Review – Two Steps Forward, One Step Back

    Honest Game Trailers | WoW: Wrath of the Lich King

    Honest Game Trailers | WoW: Wrath of the Lich King

    Hello Neighbor – Finland Story | Full Game Walkthrough

    Hello Neighbor – Finland Story | Full Game Walkthrough

    Elden Ring NIGHTREIGN Early Reviews Say It All….

    Elden Ring NIGHTREIGN Early Reviews Say It All….

  • Tesla
    Winch Stopper,Winch Accessories,Car Accessories Winch Cable Stopper,Rubber Winch…

    Winch Stopper,Winch Accessories,Car Accessories Winch Cable Stopper,Rubber Winch…

    LUCKEASY 2PCS Storage Box Compatible with Tesla Cybertruck 2024 2023 Center Console…

    LUCKEASY 2PCS Storage Box Compatible with Tesla Cybertruck 2024 2023 Center Console…

    Tesla on ‘self-driving’ gets stuck on train track and hit by train

    Tesla on ‘self-driving’ gets stuck on train track and hit by train

    Level 1/2 Tesla Charger – 16A 3.84KW Mobile EV Charging with 240V NEMA 6-20 Plug, 5-15…

    Level 1/2 Tesla Charger – 16A 3.84KW Mobile EV Charging with 240V NEMA 6-20 Plug, 5-15…

    Upgrade fit Tesla Model Y (2019-2023) Center Console Wireless Charger Mat – Silicone…

    Upgrade fit Tesla Model Y (2019-2023) Center Console Wireless Charger Mat – Silicone…

    Torx Plus Socket, 5-External Torx Socket 1/4″ Dr 10EPR Compatible With Tesla Model 3…

    Torx Plus Socket, 5-External Torx Socket 1/4″ Dr 10EPR Compatible With Tesla Model 3…

    Car Seat Organizers,Multi-functional Back Seat Protectors, Storage Pouches, and Tray…

    Car Seat Organizers,Multi-functional Back Seat Protectors, Storage Pouches, and Tray…

    AOHI USB C Car Charger, PD 45W&QC 30W 2 Port Type-C Fast Charging Car Charger Lighter…

    AOHI USB C Car Charger, PD 45W&QC 30W 2 Port Type-C Fast Charging Car Charger Lighter…

    Roof Sunshades for Tesla Model 3 2025, Upgraded 3.0 Sunroof Shade Sunshade Roof Sun…

    Roof Sunshades for Tesla Model 3 2025, Upgraded 3.0 Sunroof Shade Sunshade Roof Sun…

  • UFO
    I SHREDDED Alien's Belongings in VR! – Blinnk and the Vacuum of Space VR

    I SHREDDED Alien's Belongings in VR! – Blinnk and the Vacuum of Space VR

    Mind Blowing Encounters with Spiritual Beings and Astral Realms – With Erik Unger P-2

    Mind Blowing Encounters with Spiritual Beings and Astral Realms – With Erik Unger P-2

    Katie’s Bumpers Frequent Flyer UFO Yellow – FF7YEL

    Katie’s Bumpers Frequent Flyer UFO Yellow – FF7YEL

    Did Ancient astronauts visit Earth?? new evidence fuels extraterrestrial Theories! #viral #history

    Did Ancient astronauts visit Earth?? new evidence fuels extraterrestrial Theories! #viral #history

    INFUNLY 4pcs Solar System Patches Iron on Sequin Planet Embroidery Patch Rainbow UFO Patch Space Sew on Patch Spacecraft Patch Celestial Applique for DIY Clothing Jeans Bags Jacket Backpack Hat

    INFUNLY 4pcs Solar System Patches Iron on Sequin Planet Embroidery Patch Rainbow UFO Patch Space Sew on Patch Spacecraft Patch Celestial Applique for DIY Clothing Jeans Bags Jacket Backpack Hat

    UFO Cover Up – They Want You Confused About the Truth!

    UFO Cover Up – They Want You Confused About the Truth!

    Nitro Green for Men – 3.4 oz EDP Spray

    Nitro Green for Men – 3.4 oz EDP Spray

    Argentinian Town Has One Of The Best Documented Mass UFO Sightings | The Unexplained Files

    Football Fan Patch Trucker Hat – Netted Snapback Baseball Cap with Team Design for Men & Women

    Football Fan Patch Trucker Hat – Netted Snapback Baseball Cap with Team Design for Men & Women

No Result
View All Result
Techcratic
No Result
View All Result
Home Hacker News

Solving LinkedIn Queens with APL

Hacker News by Hacker News
June 16, 2025
in Hacker News
Reading Time: 9 mins read
124 6
A A
0

2025-06-14 08:09:00
pitr.ca

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.

Queens game screenshot

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:

⎕ ← b

0 0 0 0 0 0 0 0
0 0 1 1 1 1 2 0
0 0 1 3 3 1 2 0
0 0 3 3 3 1 2 2
0 4 4 3 1 1 2 2
0 4 5 5 1 6 6 2
4 4 5 5 5 5 6 6
4 4 4 5 7 5 5 6

When solving the puzzle, we’ll use 0 to mark queens, so later in the solution we will increment all numbers by 1 using a simple b + 1 expression. More on that later.

Breadth-first Search

Next, algorithm choise: depth-first vs breadth-first search. While depth-first is a somewhat obvious choice (and works beautifully for N‑Queens, as seen in this video), I chose breadth-first search, inspired by a Sudoku solution video I love.

In our case, the search tree depth equals the number of colors. Each step expands the current solution space by enumerating valid queen positions for a new color. Here’s a simplified mock-up (color order is chosen strategically):

initial state
 0 1 1 1 1
 2 3 2 1 2
 2 3 2 2 2
 2 2 2 4 4
 2 2 2 2 2

place all allowed queens for color 4
 0 1 1 1 1   0 1 1 1 1
 2 3 2 1 2   2 3 2 1 2
 2 3 2 2 2   2 3 2 2 2
 2 2 2 ♕ 4   2 2 2 4 ♕
 2 2 2 2 2   2 2 2 2 2

place all allowed queens for color 3
 0 1 1 1 1   0 1 1 1 1   0 1 1 1 1   0 1 1 1 1
 2 ♕ 2 1 2   2 3 2 1 2   2 ♕ 2 1 2   2 3 2 1 2
 2 3 2 2 2   2 ♕ 2 2 2   2 3 2 2 2   2 ♕ 2 2 2
 2 2 2 ♕ 4   2 2 2 ♕ 4   2 2 2 4 ♕   2 2 2 4 ♕
 2 2 2 2 2   2 2 2 2 2   2 2 2 2 2   2 2 2 2 2

place all allowed queens for color 0
notice that solution space is shrinking as some positions are invalid
 ♕ 1 1 1 1   ♕ 1 1 1 1
 2 3 2 1 2   2 3 2 1 2
 2 ♕ 2 2 2   2 ♕ 2 2 2
 2 2 2 ♕ 4   2 2 2 4 ♕
 2 2 2 2 2   2 2 2 2 2

place all allowed queens for color 1, at this point only a single board is valid
 ♕ 1 1 1 1
 2 3 2 ♕ 2
 2 ♕ 2 2 2
 2 2 2 4 ♕
 2 2 2 2 2

place all allowed queens for the last color 2
 ♕ 1 1 1 1
 2 3 2 ♕ 2
 2 ♕ 2 2 2
 2 2 2 4 ♕
 2 2 ♕ 2 2

Let’s imagine we created an infix function fills that takes a color and current solution space, and produces a new solution space. We start with the board as an initial solution space, and fill color 4 with 4 fills b. Since APL is executed right-to-left, we can then fill color 3 with 3 fills 4 fills b. And so forth… the whole solution would be the result of 2 fills 1 fills 0 fills 3 fills 4 fills b.

For those familiar with functional programming, this will look like a use case for a fold, specifically foldr (right fold). In APL this is such a common operation that it is shortened to a single symbol – /. The above becomes fills / 2 1 0 3 4 b.

So far, we’ve been designing the solution using mock output and pseudo code. However, the top-level function for our actual solution will look very similar to the code we used, by first building that list and then folding it. In fact, here it is:

solve ← {0=⊃fills/(∪,1+⍵),⊂⊂1+⍵}

Let’s see how it works when built up slowly. Comments start with ⍝ symbol (a light bulb).

⍝ an anonymous function that just returns the argument
⍝ ⍵ is a symbol for right argument
⎕ ← {⍵} b
 0 1 1 1 1
 2 3 2 1 2
 2 3 2 2 2
 2 2 2 4 4
 2 2 2 2 2

⍝ increment by 1, reserving 0 for queens
⎕ ← {1+⍵} b
 1 2 2 2 2
 3 4 3 2 3
 3 4 3 3 3
 3 3 3 5 5
 3 3 3 3 3

⍝ flatten the board
⎕ ← {,1+⍵} b
 1 2 2 2 2 3 4 3 2 3 3 4 3 3 3 3 3 3 5 5 3 3 3 3 3

⍝ unique list of colors
⎕ ← {∪,1+⍵} b
 1 2 3 4 5

⍝ board again, incremented by 1
⎕ ← {1+⍵} b
 1 2 2 2 2
 3 4 3 2 3
 3 4 3 3 3
 3 3 3 5 5
 3 3 3 3 3

⍝ enclosed twice, making a solution space with one boxed element
⎕ ← {⊂⊂1+⍵} b
   1 2 2 2 2
   3 4 3 2 3
   3 4 3 3 3
   3 3 3 5 5
   3 3 3 3 3

⍝ create a list that we will fold over as explained earlier
⎕ ← {(∪,1+⍵),⊂⊂1+⍵} b
 1 2 3 4 5  1 2 2 2 2
            3 4 3 2 3
            3 4 3 3 3
            3 3 3 5 5
            3 3 3 3 3

⍝ actually fold using our fills function
⎕ ← {fills / (∪,1+⍵),⊂⊂1+⍵} b
   0 2 2 2 2
   3 4 3 0 3
   3 0 3 3 3
   3 3 3 5 0
   3 3 0 3 3

⍝ disclose twice
⎕ ← {⊃⊃fills/(∪,1+⍵),⊂⊂1+⍵} b
 0 2 2 2 2
 3 4 3 0 3
 3 0 3 3 3
 3 3 3 5 0
 3 3 0 3 3

⍝ pretty print the result
⎕ ← {'♕0123456789'[⍵]} {0=⊃⊃fills/(∪,1+⍵),⊂⊂1+⍵} b
 ♕ 1 1 1 1
 2 3 2 ♕ 2
 2 ♕ 2 2 2
 2 2 2 4 ♕
 2 2 ♕ 2 2

Helpers

Now we are ready to actually implement the fills function. But first let’s define some helpers.

The first helper is a place function that places a 0 (queen) on the board. It’s called like this: 1 2 place b. We will use an At operator, represented by symbol @:

⍝ ⍺ is the left argument
place ← {0@(⊂⍺)⊢⍵}

⎕ ← 5 5⍴1
 1 1 1 1 1
 1 1 1 1 1
 1 1 1 1 1
 1 1 1 1 1
 1 1 1 1 1

⎕ ← 1 2 place 5 5⍴1
 1 1 1 1 1
 1 1 0 1 1
 1 1 1 1 1
 1 1 1 1 1
 1 1 1 1 1

Easy enough!

Note: APL allows overriding index origin. The default is 1-based; however, the place function doesn’t work there for surprisingly complicated reasons – it involved the behaviour of Each with empty lists, prototypes, and @ primitive failing when asked to update index (0,0) in 1-based origin system. So this function assumes that the origin is setup with ⎕IO ← 0. The rest of the code doesn’t care about index origin.

Now, let’s build the function – we will call it avl – that returns valid queen positions for a specific color. We will call it with color and board as such – 4 avl b:

avl ← {
    ⍝ find positions of all existing queens
    q ← ⍸0=⍵

    ⍝ find positions of a particular color
    p ← ⍸⍺=⍵

    ⍝ boolean mask over p that have row or column conflict with any existing queen
    rc ← ∨⌿1∊¨q∘.=p

    ⍝ boolean mask over p that are next to any existing queen
    nx ← ∨⌿∧/¨1≥|q∘.-p

    ⍝ select color positions that are covered by neither mask using a Nor.
    ⍝ here slash symbol is a select, not fold
    (rc⍱nx)/p
}

Last line in this function implicitly returns the result – list of legal positions for a queen in the color region. I leave deeper understanding of this function as an exercise to the reader. For those unfamiliar with APL primitives, APL Wiki has great pages for each, such as ⍸ – indices function.

And now we are ready to implement the fills function. We will split it into two functions – fills that works on a solution space and fill that works on a single instance of a board. Left argument for both is always the color.

⍝ places a queen on each available position of a board
fill ← {(⍺ avl ⍵) place¨ ⊂⍵}

⍝ calls fill for each board, then merged the results
fills ← {⊃,/⍺ fill¨ ⍵}

And that’s it!

Full Solution

The whole solution is this:

place ← {0@(⊂⍺)⊢⍵}
avl ← {
    q ← ⍸0=⍵
    p ← ⍸⍺=⍵
    rc ← ∨⌿1∊¨q∘.=p
    nx ← ∨⌿∧/¨1≥|q∘.-p
    (rc⍱nx)/p
}
fill ← {(⍺ avl ⍵) place¨ ⊂⍵}
fills ← {⊃,/⍺ fill¨ ⍵}
solve ← {⊃⊃fills/(∪,1+⍵),⊂⊂1+⍵}

11 lines of code that have zero external dependencies, not even APL’s built-in libraries. Just the primitives. avl can be minified to much fewer lines, but I see no reason to do that.

There are heuristics that could be used, such as ordering colors by number of positions (fill smaller regions first). However, the current solution runs in a few milliseconds already. Still, there might be edge case boards where this solution doesn’t perform well, but I do not have many data points.

Let’s solve the large example:

⎕ ← board
 0 0 0 0 0 0 0 0
 0 0 1 1 1 1 2 0
 0 0 1 3 3 1 2 0
 0 0 3 3 3 1 2 2
 0 4 4 3 1 1 2 2
 0 4 5 5 1 6 6 2
 4 4 5 5 5 5 6 6
 4 4 4 5 7 5 5 6

⎕ ← solve board
 ♕.......
 .....♕..
 ...♕....
 .......♕
 .♕......
 ......♕.
 ..♕.....
 ....♕...

The End

My hope is that this has piqued your interest in APL, at least from the perspective of expanding your programming toolbox. APL is a very powerful language that allows you to express complex algorithms in a very concise way. If you want to learn more, I recommend checking out APL Wiki and TryAPL.


Discussion: https://lobste.rs/s/9gjyi0

home |
github |
twitch |
linkedin

Source Link


Keep your files stored safely and securely with the SanDisk 2TB Extreme Portable SSD. With over 69,505 ratings and an impressive 4.6 out of 5 stars, this product has been purchased over 8K+ times in the past month. At only $129.99, this Amazon’s Choice product is a must-have for secure file storage.

Help keep private content private with the included password protection featuring 256-bit AES hardware encryption. Order now for just $129.99 on Amazon!


Start your free Amazon Prime trial
today and unlock unlimited streaming and more!

Help Power Techcratic’s Future – Scan To Support

If Techcratic’s content and insights have helped you, consider giving back by supporting the platform with crypto. Every contribution makes a difference, whether it’s for high-quality content, server maintenance, or future updates. Techcratic is constantly evolving, and your support helps drive that progress.

As a solo operator who wears all the hats, creating content, managing the tech, and running the site, your support allows me to stay focused on delivering valuable resources. Your support keeps everything running smoothly and enables me to continue creating the content you love. I’m deeply grateful for your support, it truly means the world to me! Thank you!

BITCOIN

Bitcoin Logo

Bitcoin QR Code

bc1qlszw7elx2qahjwvaryh0tkgg8y68enw30gpvge

Scan the QR code with your crypto wallet app

DOGECOIN

Dogecoin Logo

Dogecoin QR Code

D64GwvvYQxFXYyan3oQCrmWfidf6T3JpBA

Scan the QR code with your crypto wallet app

ETHEREUM

Ethereum Logo

Ethereum QR Code

0xe9BC980DF3d985730dA827996B43E4A62CCBAA7a

Scan the QR code with your crypto wallet app

Please read the Privacy and Security Disclaimer on how Techcratic handles your support.

Disclaimer: As an Amazon Associate, Techcratic may earn from qualifying purchases.

Tags: Hacker News
Previous Post

Yet another European government is ditching Microsoft for Linux – here’s why

Next Post

Did Ancient astronauts visit Earth?? new evidence fuels extraterrestrial Theories! #viral #history

Hacker News

Hacker News

Stay updated with Hacker News, where technology meets entrepreneurial spirit. Get the latest on tech trends, startup news, and discussions from the tech community. Read the latest updates here at Techcratic.

Related Posts

ccbikai/ssh-ai-chat: Chat with AI over SSH.
Hacker News

ccbikai/ssh-ai-chat: Chat with AI over SSH.

June 16, 2025
1.3k
rorosen/zeekstd: Rust implementation of the Zstandard Seekable Format
Hacker News

rorosen/zeekstd: Rust implementation of the Zstandard Seekable Format

June 16, 2025
1.3k
KAIST NEWS CENTER
Hacker News

KAIST NEWS CENTER

June 15, 2025
1.3k
How fast can the RPython GC allocate?
Hacker News

How fast can the RPython GC allocate?

June 15, 2025
1.3k
Biofuels Policy, a Mainstay of American Agriculture, Has Been a Failure for the Climate, a New Report Claims
Hacker News

Biofuels Policy, a Mainstay of American Agriculture, Has Been a Failure for the Climate, a New Report Claims

June 15, 2025
1.3k
SakanaAI/text-to-lora: Hypernetworks that adapt LLMs for specific benchmark tasks using only textual task description as the input
Hacker News

SakanaAI/text-to-lora: Hypernetworks that adapt LLMs for specific benchmark tasks using only textual task description as the input

June 15, 2025
1.3k
tanelp/tiny-diffusion: A minimal PyTorch implementation of probabilistic diffusion models for 2D datasets.
Hacker News

tanelp/tiny-diffusion: A minimal PyTorch implementation of probabilistic diffusion models for 2D datasets.

June 15, 2025
1.3k
How we investigated Amsterdam’s attempt to build a ‘fair’ fraud detection model
Hacker News

How we investigated Amsterdam’s attempt to build a ‘fair’ fraud detection model

June 14, 2025
1.3k
Load More
Next Post
Did Ancient astronauts visit Earth?? new evidence fuels extraterrestrial Theories! #viral #history

Did Ancient astronauts visit Earth?? new evidence fuels extraterrestrial Theories! #viral #history

Smartphone

Android 16 is sprucing up the Pixel Camera app with a slick new look

PNY Duo Link V3 offers fast USB-C and USB-A transfers

PNY Duo Link V3 offers fast USB-C and USB-A transfers

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Your Tech Resources

  • 30 Second Tech ™
  • AI
  • App Zone ™
  • Apple
  • Ars Technica
  • CNET
  • ComputerWorld
  • Crypto News
  • Cybersecurity
  • Endgadget
  • Forbes
  • Fossbytes
  • Gaming
  • GeekWire
  • Gizmodo
  • Google News
  • Hacker News
  • Harvard Tech
  • I Like Cats ™
  • I Like Dogs ™
  • LifeHacker
  • MacRumors
  • Macworld
  • Mashable
  • Microsoft
  • MIT Tech
  • PC World
  • Photofocus
  • Physics
  • Random Tech
  • Retro Rewind ™
  • Robot Report
  • SiliconANGLE
  • SlashGear
  • Smartphone
  • StackSocial
  • Tech Art
  • Tech Careers
  • Tech Deals
  • Techcratic ™
  • TechCrunch
  • Techdirt
  • TechRepublic
  • Techs Got To Eat ™
  • TechSpot
  • Tesla
  • The Verge
  • TNW
  • Trusted Reviews
  • UFO
  • VentureBeat
  • Visual Capitalist
  • Wired
  • ZDNet

Tech News

  • 30 Second Tech ™
  • AI
  • Apple Insider
  • Ars Technica
  • CNET
  • ComputerWorld
  • Crypto News
  • Cybersecurity
  • Endgadget
  • ExtremeTech
  • Fossbytes
  • Gaming
  • GeekWire
  • Gizmodo

Tech News

  • Harvard Tech
  • MacRumors
  • Macworld
  • Mashable
  • Microsoft
  • MIT Tech
  • Physics
  • PC World
  • Random Tech
  • Retro Rewind ™
  • SiliconANGLE
  • SlashGear
  • Smartphone
  • StackSocial
  • Tech Careers

Tech News​

  • Tech Art
  • TechCrunch
  • Techdirt
  • TechRepublic
  • Techs Got To Eat ™
  • TechSpot
  • Tesla
  • The Verge
  • TNW
  • Trusted Reviews
  • UFO
  • VentureBeat
  • Visual Capitalist
  • Wired
  • ZDNet

Site Links

  • About Techcratic
  • Affiliate Disclaimer
  • Affiliate Link Policy
  • Contact Techcratic
  • Dealors Discount Store
  • Privacy and Security Disclaimer
  • Privacy Policy
  • RSS Feed
  • Site Map
  • Support Techcratic
  • Techcratic
  • Tech Deals
  • TOS
  • 𝕏
Click For A Secret Deal

Techcratic – Your All In One Tech Hub © 2020 – 2025
All Rights Reserved
∞

No Result
View All Result
  • 30 Second Tech ™
  • AI
  • App Zone ™
  • Apple
  • Ars Technica
  • CNET
  • Crypto News
  • Cybersecurity
  • Endgadget
  • Gaming
  • I Like Cats ™
  • I Like Dogs ™
  • MacRumors
  • Macworld
  • Tech Deals
  • Techcratic ™
  • Techs Got To Eat ™
  • Tesla
  • UFO
  • Wired