We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Crosswords-101
Crosswords-101
Sort by
recency
|
19 Discussions
|
Please Login in order to post a comment
Such a brilliant puzzle! I like that kind. My solution with F# is not concise at all. Full text is about 100 lines. Here is the heart without I/O:
Parsing placeholders:
Finding a solution (just a consequent recoursive "trying" of each word for each next placeholder with checking letters in "joint" points):
Such a brilliant puzzle! I like that kind. My solution with F# is not concise at all. Full text is about 108 lines. Here is the heart without I/O:
Parsing placeholders:
Finding a solution (just a consequent recoursive "trying" of each word for each next placeholder with checking letters in "joint" points):
Nice problem for list-monad in Haskell
Wow I actually did it!
How my algorithm works: Try putting the word at the front of your list in the board at all possible positions. (No, actually.
i <- [0..9]; j <- [0..9]
) For each successful placement, continue with the rest of the list of words. I ended up using do notation on lists andmaybeToList
ing some information.I'm super proud of it! On the other hand, I'm really glad we don't have hacking on ... uh, on HackerRank ... unlike some other platforms, like CodeForces ... hm.
Here it is! Sorry for the
hiding
, I'm lazier than Haskell.This really was challenging! I spent almost 3 (partial days). Here's my solution in 80 lines of Clojure:
I used
(map-indexed)
to associate each grid character with a column number (from 0 to 9); then I used(partition-by)
to separate out sequences of+
and-
. I discarded the+
sequences and any sequence shorter than 2. I also dropped the now superfluous-
characters. Then I used(map-indexed)
again to give each blank position a y coordinate as well. Then I did the same thing with the grid rotated by 90°, and so I ended up with (usually) 4 word slots represented by sequences of x,y coordinates.Matching (e.g.) 4 words against (e.g.) 4 word slots is simple enough for a brute force approach: I matched all possible permutations of those words against the slots, punting on length mismatches. When matching words, I created a map of coordinates and contained letters, so if I encountered the same coordinate again it was a crossing and I had to ensure the new letter was the same as the one already at that location.
Printing out the completed map was simply printing, for each x,y, the character in my assignment map or a
+
if not found.