Word wheel: Difference between revisions
m
syntax highlighting fixup automation
m (→{{header|J}}) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 51:
{{trans|Python}}
<
‘N D E
O K G
Line 79:
V chars = GRID.lowercase().split_py().join(‘’)
V found = solve(chars, dictionary' getwords())
print(found.join("\n"))</
{{out}}
Line 108:
(the given ~206kb <code>unixdict.txt</code> works fine).
<
fopen: equ 15 ; CP/M syscall to open a file
fread: equ 20 ; CP/M syscall to read from file
Line 218:
wheel: ds 9 ; Room for wheel
wcpy: ds 9 ; Copy of wheel (to mark characters used)
word: equ $ ; Room for current word</
{{out}}
Line 244:
=={{header|APL}}==
{{works with|Dyalog APL}}
<
words←((~∊)∘⎕TC⊆⊢) 80 ¯1⎕MAP ⍵
match←{
Line 255:
words←(⍺∘match¨words)/words
(⍺⍺≤≢¨words)/words
}</
{{out}}
<pre> 'ndeokgelw' (3 wordwheel) 'unixdict.txt'
eke elk keel keen keg ken keno knee kneel knew know knowledge kong leek week wok woke </pre>
=={{header|AppleScript}}==
<
use framework "Foundation"
use scripting additions
Line 642:
return lst
end tell
end zipWith</
{{Out}}
<pre>17 matches:
Line 665:
=={{header|AutoHotkey}}==
<
FileRead, wList, % A_Desktop "\unixdict.txt"
Line 687:
}
return oRes
}</
{{out}}
<pre>eke
Line 710:
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f WORD_WHEEL.AWK letters unixdict.txt
# the required letter must be first
Line 747:
exit(0)
}
</syntaxhighlight>
{{out}}
<pre>
Line 755:
=={{header|BASIC}}==
<
20 DATA "ndeokgelw","unixdict.txt"
30 READ WH$, F$
Line 770:
140 C=0: FOR I=1 TO LEN(C$): C=C-(MID$(C$,I,1)="@"): NEXT
150 IF C>=3 THEN PRINT W$,
160 GOTO 50</
{{out}}
<pre>eke elk keel keen keg
Line 779:
=={{header|BCPL}}==
<
// Read word from selected input
Line 830:
writef("%S*N", word)
endread()
$)</
{{out}}
<pre>eke
Line 851:
=={{header|C}}==
<
#include <stdio.h>
Line 898:
fclose(in);
return 0;
}</
{{out}}
Line 924:
{{libheader|Boost}}
The puzzle parameters can be set with command line options. The default values are as per the task description.
<
#include <iostream>
#include <fstream>
Line 1,118:
}
return EXIT_SUCCESS;
}</
{{out}}
Line 1,139:
{{libheader| System.Classes}}
{{Trans|Wren}}
<syntaxhighlight lang="delphi">
program Word_wheel;
Line 1,192:
end.
</syntaxhighlight>
=={{header|F_Sharp|F#}}==
<
// Word Wheel: Nigel Galloway. May 25th., 2021
let fG k n g=g|>Seq.exists(fun(n,_)->n=k) && g|>Seq.forall(fun(k,g)->Map.containsKey k n && g<=n.[k])
let wW n g=let fG=fG(Seq.item 4 g)(g|>Seq.countBy id|>Map.ofSeq) in seq{use n=System.IO.File.OpenText(n) in while not n.EndOfStream do yield n.ReadLine()}|>Seq.filter(fun n->2<(Seq.length n)&&(Seq.countBy id>>fG)n)
wW "unixdict.txt" "ndeokgelw"|>Seq.iter(printfn "%s")
</syntaxhighlight>
{{out}}
<pre>
Line 1,223:
=={{header|Factor}}==
{{works with|Factor|0.99 2020-07-03}}
<
math.statistics prettyprint sequences sorting ;
Line 1,243:
[ words ] keepd [ can-make? ] curry filter ;
"ndeokgelw" "unixdict.txt" solve [ length ] sort-with .</
{{out}}
<pre style="height:20ex">
Line 1,268:
=={{header|FreeBASIC}}==
<
#include "file.bi"
Line 1,368:
print matches;" matches"
Sleep
</syntaxhighlight>
{{out}}
<pre>
Line 1,395:
=={{header|Go}}==
{{trans|Wren}}
<
import (
Line 1,508:
fmt.Println(mostWords9[i], "with central letter", string(mostLetters[i]))
}
}</
{{out}}
Line 1,538:
=={{header|Haskell}}==
<
import Data.List (sort)
import System.IO (readFile)
Line 1,571:
. gridWords ["NDE", "OKG", "ELW"]
. lines
)</
{{Out}}
<pre>eke
Line 1,592:
=={{header|J}}==
<
wwhe=: {{
ref=. /:~each words=. cutLF tolower fread 'unixdict.txt'
Line 1,603:
;:inv r=. r,words #~ ref e. target
end.
}}</
Task example:<
eke elk keg ken wok keel keen keno knee knew know kong leek week woke kneel knowledge</
=={{header|JavaScript}}==
A version using local access to the dictionary, through the macOS JavaScript for Automation API.
{{Works with|JXA}}
<
"use strict";
Line 1,705:
// MAIN ---
return main();
})();</
{{Out}}
<pre>eke
Line 1,726:
=={{header|Julia}}==
<
const tfile = download("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt")
Line 1,747:
println(wordwheel("ndeokgelw", "k"))
</
<pre>
["ken", "keg", "eke", "elk", "wok", "keno", "knee", "keen", "knew", "kong", "know", "woke", "keel", "leek", "week", "kneel", "knowledge"]
</pre>
===Faster but less general version===
<
const wordarraylist = [[string(c) for c in w] for w in split(read(tfile, String), r"\s+")]
Line 1,763:
println(wordwheel2("ndeokgelw", "k"))
</
<pre>
["eke", "elk", "keel", "keen", "keg", "ken", "keno", "knee", "kneel", "knew", "know", "knowledge", "kong", "leek", "week", "wok", "woke"]
</pre>
=={{header|Lua}}==
<
new = function(self, word)
local t = { word=word, letters={} }
Line 1,791:
print(word)
end
end</
{{out}}
<pre>eke
Line 1,812:
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
possible[letters_List][word_String] := Module[{c1, c2, m},
c1 = Counts[Characters@word];
Line 1,826:
words //= Select[StringMatchQ[Repeated[Alternatives @@ chars]]];
words //= Select[possible[chars]];
words</
{{out}}
<pre>{eke,elk,keel,keen,keg,ken,keno,knee,kneel,knew,know,knowledge,kong,leek,week,wok,woke}</pre>
=={{header|Nim}}==
<
const Grid = """N D E
Line 1,853:
if count > gridCount[ch]:
break checkWord
echo word</
{{out}}
Line 1,876:
=={{header|Pascal}}==
{{works with|Free Pascal}}
<syntaxhighlight lang="pascal">
program WordWheel;
Line 1,935:
search('NDE' + 'OKG' + 'ELW');
end.
</syntaxhighlight>
{{out}}
<pre>
Line 1,960:
UPDATED: this version builds a single regex that will select all valid words
straight from the file string.
<
use strict; # https://rosettacode.org/wiki/Word_wheel
Line 1,980:
my @words = $file =~ /$valid/g;
print @words . " words for\n$_\n@words\n" =~ s/.{60}\K /\n/gr;</
{{out}}
<pre>
Line 1,993:
=={{header|Phix}}==
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #7060A8;">requires</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"1.0.1"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- (fixed another glitch in unique())</span>
Line 2,074:
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</
{{out}}
<small>(Only the first three lines are shown under pwa/p2js)</small>
Line 2,089:
=={{header|Picat}}==
<
MinLen = 3,
MaxLen = 9,
Line 2,125:
foreach(E in L)
D.put(E,D.get(E,0)+1)
end.</
{{out}}
Line 2,132:
'''Optimal word(s)''':
<
WordList = "unixdict.txt",
MinLen = 3,
Line 2,155:
end,
println(maxLResen=MaxResLen),
println(maxWord=MaxResWord).</
{{out}}
Line 2,164:
=={{header|PureBasic}}==
<
Shared letters$
If Len(word$)<3 Or FindString(word$,"k")<1
Line 2,196:
Input()
EndIf
End</
{{out}}
<pre>eke
Line 2,219:
=={{header|Python}}==
<
from collections import Counter
Line 2,245:
chars = ''.join(GRID.strip().lower().split())
found = solve(chars, dictionary=getwords())
print('\n'.join(found))</
{{out}}
Line 2,268:
Or, using a local copy of the dictionary, and a recursive test of wheel fit:
<
from os.path import expanduser
Line 2,337:
# MAIN ---
if __name__ == '__main__':
main()</
{{Out}}
<pre>eke
Line 2,358:
=={{header|q}}==
<
lc:ce group@ / letter count
dict:"\n"vs .Q.hg "http://wiki.puzzlers.org/pub/wordlists/unixdict.txt"
Line 2,366:
solve:{[grid;dict]
i:where(grid 4)in'dict;
dict i where all each 0<=(lc grid)-/:lc each dict i }[;d39]</
<
`eke`elk`keel`keen`keg`ken`keno`knee`kneel`knew`know`knowledge`kong`leek`week`wok`woke</
A naive solution to the second question is simple
<
grids:distinct raze(til 9)rotate\:/:dict where(ce dict)=9;
wc:(count solve@)each grids;
grids where wc=max wc }</
but inefficient. Better:
<
dlc:lc each dict; / letter counts of dictionary words
ig:where(ce dict)=9; / find grids (9-letter words)
Line 2,383:
ml:4 rotate'dict ig; / mid letters for each grid
wc:ce raze igw inter/:'iaz ml; / word counts for grids
distinct grids where wc=max wc } / grids with most words</
<
"ntclaremo"
"tspearmin"
q)ce solve each w
215 215</
Full discussion at [https://code.kx.com/q/learn/pb/word-wheel/ code.kx.com]
Line 2,403:
Using [https://modules.raku.org/search/?q=Terminal%3A%3ABoxer Terminal::Boxer] from the Raku ecosystem.
<syntaxhighlight lang="raku"
my %*SUB-MAIN-OPTS = :named-anywhere;
Line 2,425:
say "{sum %words.values».elems} words found";
printf "%d letters: %s\n", .key, .value.sort.join(', ') for %words.sort;</
{{out}}
;Using defaults
<syntaxhighlight lang="text">raku word-wheel.raku</
<pre>Using ./unixdict.txt, minimum 3 letters.
╭───┬───┬───╮
Line 2,448:
Using the much larger dictionary '''words.txt''' file from '''https://github.com/dwyl/english-words'''
<syntaxhighlight lang="text">raku word-wheel.raku --dict=./words.txt</
<pre>Using ./words.txt, minimum 3 letters.
Line 2,498:
Additional information is also provided concerning how many words have been skipped due to
the various filters.
<
parse arg grid minL iFID . /*obtain optional arguments from the CL*/
if grid==''|grid=="," then grid= 'ndeokgelw' /*Not specified? Then use the default.*/
Line 2,558:
do n=1 for length(aa); p= pos( substr(aa,n,1), gg); if p==0 then return 1
gg= overlay(., gg, p) /*"rub out" the found character in grid*/
end /*n*/; return 0 /*signify that the AA passed the test*/</
{{out|output|text= when using the default inputs:}}
<pre>
Line 2,629:
=={{header|Ruby}}==
<
middle, wheel_size = wheel[4], wheel.size
Line 2,641:
puts res
</syntaxhighlight>
{{out}}
<pre>eke
Line 2,663:
=={{header|Transd}}==
<
MainModule: {
Line 2,700:
(lout "New max. number: " maxRes ", word: " w ", central letter: " centl)
) ) ) )
}</
{{out}}
<pre>
Line 2,730:
{{libheader|Wren-sort}}
{{libheader|Wren-seq}}
<
import "/sort" for Sort, Find
import "/seq" for Lst
Line 2,801:
for (i in 0...mostWords9.count) {
System.print("%(mostWords9[i]) with central letter '%(mostLetters[i])'")
}</
{{out}}
Line 2,831:
=={{header|XPL0}}==
<
int I, Set, HasK, HasOther, HasDup, ECnt, Ch;
char Word(25);
Line 2,856:
];
until Ch = EOF;
]</
{{out}}
|