How to resolve the algorithm Word wheel step by step in the Factor programming language
How to resolve the algorithm Word wheel step by step in the Factor 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 Factor programming language
Source code in the factor programming language
USING: assocs io.encodings.ascii io.files kernel math
math.statistics prettyprint sequences sorting ;
! Only consider words longer than two letters and words that
! contain elt.
: pare ( elt seq -- new-seq )
[ [ member? ] keep length 2 > and ] with filter ;
: words ( input-str path -- seq )
[ [ midpoint@ ] keep nth ] [ ascii file-lines pare ] bi* ;
: ?<= ( m n/f -- ? ) dup f = [ nip ] [ <= ] if ;
! Can we make sequence 1 with the elements in sequence 2?
: can-make? ( seq1 seq2 -- ? )
[ histogram ] bi@ [ swapd at ?<= ] curry assoc-all? ;
: solve ( input-str path -- seq )
[ words ] keepd [ can-make? ] curry filter ;
"ndeokgelw" "unixdict.txt" solve [ length ] sort-with .
You may also check:How to resolve the algorithm 2048 step by step in the Elm programming language
You may also check:How to resolve the algorithm Best shuffle step by step in the Lua programming language
You may also check:How to resolve the algorithm Elementary cellular automaton step by step in the D programming language
You may also check:How to resolve the algorithm Factorions step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm DNS query step by step in the Neko programming language