How to resolve the algorithm Word wheel step by step in the XPL0 programming language
How to resolve the algorithm Word wheel step by step in the XPL0 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 XPL0 programming language
Source code in the xpl0 programming language
string 0; \use zero-terminated strings
int I, Set, HasK, HasOther, HasDup, ECnt, Ch;
char Word(25);
def LF=$0A, CR=$0D, EOF=$1A;
[FSet(FOpen("unixdict.txt", 0), ^I);
OpenI(3);
repeat I:= 0; HasK:= false; HasOther:= false;
ECnt:= 0; Set:= 0; HasDup:= false;
loop [repeat Ch:= ChIn(3) until Ch # CR; \remove possible CR
if Ch=LF or Ch=EOF then quit;
Word(I):= Ch;
I:= I+1;
if Ch = ^k then HasK:= true;
case Ch of ^k,^n,^d,^e,^o,^g,^l,^w: [] \assume all lowercase
other HasOther:= true;
if Ch = ^e then ECnt:= ECnt+1
else [if Set & 1<<(Ch-^a) then HasDup:= true;
Set:= Set ! 1<<(Ch-^a);
];
];
Word(I):= 0; \terminate string
if I>=3 & HasK & ~HasOther & ~HasDup & ECnt<=2 then
[Text(0, Word); CrLf(0);
];
until Ch = EOF;
]
You may also check:How to resolve the algorithm Animation step by step in the smart BASIC programming language
You may also check:How to resolve the algorithm Benford's law step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Find limit of recursion step by step in the Delphi programming language
You may also check:How to resolve the algorithm Bitmap step by step in the FBSL programming language
You may also check:How to resolve the algorithm Terminal control/Dimensions step by step in the Sidef programming language