How to resolve the algorithm Word wheel step by step in the Nim programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Word wheel step by step in the Nim programming language

Table of Contents

Problem Statement

A "word wheel" is a type of word game commonly found on the "puzzle" page of newspapers. You are presented with nine letters arranged in a circle or 3×3 grid. The objective is to find as many words as you can using only the letters contained in the wheel or grid. Each word must contain the letter in the centre of the wheel or grid. Usually there will be a minimum word length of 3 or 4 characters. Each letter may only be used as many times as it appears in the wheel or grid.

Write a program to solve the above "word wheel" puzzle. Specifically:

A "word" is defined to be any string contained in the file located at   http://wiki.puzzlers.org/pub/wordlists/unixdict.txt. If you prefer to use a different dictionary,   please state which one you have used. Word wheel puzzles usually state that there is at least one nine-letter word to be found. Using the above dictionary, find the 3x3 grids with at least one nine-letter solution that generate the largest number of words of three or more letters.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Word wheel step by step in the Nim programming language

Source code in the nim programming language

import strutils, sugar, tables

const Grid = """N D E
                O K G
                E L W"""

let letters = Grid.toLowerAscii.splitWhitespace.join()

let words = collect(newSeq):
              for word in "unixdict.txt".lines:
                if word.len in 3..9:
                  word

let midLetter = letters[4]

let gridCount = letters.toCountTable
for word in words:
  block checkWord:
    if midLetter in word:
      for ch, count in word.toCountTable.pairs:
        if count > gridCount[ch]:
          break checkWord
      echo word


  

You may also check:How to resolve the algorithm Hash from two arrays step by step in the Amazing Hopper programming language
You may also check:How to resolve the algorithm Rosetta Code/Count examples step by step in the Raku programming language
You may also check:How to resolve the algorithm First-class functions/Use numbers analogously step by step in the JavaScript programming language
You may also check:How to resolve the algorithm String length step by step in the Vala programming language
You may also check:How to resolve the algorithm XML/Input step by step in the VBA programming language