The Setup
Most of us are familiar with crossword numbering, which follows three basic rules:
- in a character grid consisting of blacks and whites (see below), any maximal contiguous horizontal or vertical chain of whites with length ≥ 2 is considered a word
- any white at the leftmost end of a horizontal word and/or at the topmost end of a vertical word is called a "starter"
- starters are assigned numbers (sequential integers starting with 1) scanning through the grid in standard English reading order (starting at the top left of the grid, scanning right-fast, down-slow to the bottom right of the grid)
A "crossword" generally refers to any n-by-n square grid of blacks and whites, with n ≥ 2, containing at least one black and at least one word, and containing no whites that do not belong to at least one word.
Some additional properties that a crossword may or may not possess:
- a crossword is called singly connected if every white in the grid can be connected to every other white in the grid by moving north, east, south, and west (not diagonally) along a path consisting entirely of whites
- a crossword is called proper if every white belongs to exactly two words (one horizontal, one vertical)
- a crossword is called symmetric if for all x = 1..n, y = 1..n, the grid cell at (x,y) is a white if and only if the grid cell at (n+1-x,n+1-y) is a white, given 1-based indexing
Most run-of-the-mill cryptic crosswords are singly-connected and symmetric, but not proper. Many newspaper crosswords are proper, singly-connected, and symmetric. The figure below also shows a proper, singly-connected, symmetric crossword.
Crossword
w/o #s w/ #s (mod 10)
################## 12##################
# ###### #### 3 45#678######90####
# #### 1 2 #34567 ####
### ###### 8 ###9 ######
## #### #### ##0 123####456####
# # ## ## #7 #8 ##90 12##
## ## # 3 ##4 ##5 #6 78
#### ##### 9 ####0 #####1
# ## #### ## #234##5 67####8 ##
# # ## ### #9 01 #2 ##34 ###
### ## # # ###5 ##6 7#8 90#
## #### ## # ##1 ####2 3 ##4 #
##### #### 56 7#####8 ####90
# ## ## 1 #23##4 5##6
## ## # # ##7 8 ##9 #0 #
#### #### ## ####1 ####2 3 ##
###### ### ######45678###9 01
#### # ####23 #45
#### ###### # ####6 ######7 #8
################## ##################9
The Problem
...other than finding a crossword puzzle challenge that hasn't already been done. :P
Recall the crossword numbering challenge from days of yore, which accepts a crossword as input and produces clue numbering as output. Here we consider its younger (and significantly harder) cousin by reversing input and output:
Given a series of across/down clue numbers, generate a crossword puzzle whose numbering (per the canonical rules) yields these clue numbers.
For example, consider the clue numbers as input:
Across 3,5,6,7,8,9
Down 1,2,3,4,5,A
Two crosswords with compliant numbering are:
A B
6x6 7x7
w/o #s w/ #s w/o #s w/ #s
______ ______ _______ _______
|## # #| |##1#2#| |#######| |#######|
|# | |#3 4| |# ## ##| |#1##2##|
| ## | |5 ##6 | |# # # | |# #3 #4|
| ## | |7 ##8 | | # # | |5 #6 # |
| #| |9 A #| | # # | | #7 #8 |
|# # ##| |# # ##| | ## ##| |9 ##A##|
¯¯¯¯¯¯ ¯¯¯¯¯¯ |#### ##| |#### ##|
¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯
Solution A is singly-connected and symmetric, while B is neither. Solution A is also notably more compact, having only 14 blacks, while solution B has 29 blacks.
Note that you do not need to worry about what letters could/would go into any whites. This challenge is purely geometric in nature.
There are of course many trivial ways of generating compliant crosswords, which takes us to the interesting matter of...
Scoring
This 600-textline file contains 300 sets of across/down clue numbers for crosswords in the format
[across clue numbers for set 1, separated by spaces]
[down clue numbers for set 1, separated by spaces]
[across clue numbers for set 2, separated by spaces]
[down clue numbers for set 2, separated by spaces]...
[across clue numbers for set 300, separated by spaces]
[down clue numbers for set 300, separated by spaces]
Your objective is to write a program that generates a valid crossword for each set of across/down clue numbers and computes the resulting number of blacks.
The program should produce all 300 crosswords in 30 minutes or less running on a modern computer.
By setting a constant in the program or passing a command line argument, the program should be able to output the crossword grid (solution) for the kth input set given k ∈ 1..300, and you should display representative output (the black/white grid) for at least k = 1 and k = 300 along with your answer. The output can be text- or graphics-based, with or without clue numbers shown (preferably with, mod 36 for text-based graphics), and with any embellishments you desire. (This is simply for validation and showmanship.)
The output should also indicate whether the crossword is proper, singly-connected, and/or symmetric.
Your program's score is the sum total number of blacks over all 300 solutions. The program that produces the lowest total number of blacks is the winner.
per-crossword Bonuses
For any of the 300 crosswords (solutions) generated by your program:
- if a crossword is proper, multiply its black count by 0.6
- if a crossword is singly connected, multiply its black count by 0.85
- if a crossword is symmetric, multiply its black count by 0.75
- if any two of the above conditions apply for a crossword, multiply its black count by 0.4
- if all three of the above conditions apply for a crossword, multiply its black count by 0.25
You may only claim one bonus per crossword.
The score for each crossword should be rounded up to the nearest integer.
Note that all of the input sets in the problem correspond to randomly-generated small(ish) singly-connected, proper, symmetric crosswords, hence I guarantee the existence of at least one such a solution.
Feel free to raise any questions or concerns in the comments section.
Happy crosswording. :)