Word wheel: Difference between revisions
m
→{{header|Wren}}: Minor tidy
m (→{{header|Wren}}: Minor tidy) |
|||
(23 intermediate revisions by 8 users not shown) | |||
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,133:
claremont with central letter a
spearmint with central letter a
</pre>
===Without external libraries===
<syntaxhighlight lang="c++">
#include <algorithm>
#include <cstdint>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
int main() {
const std::string word_wheel_letters = "ndeokgelw";
const std::string middle_letter = word_wheel_letters.substr(4, 1);
std::vector<std::string> words;
std::fstream file_stream;
file_stream.open("../unixdict.txt");
std::string word;
while ( file_stream >> word ) {
words.emplace_back(word);
}
std::vector<std::string> correct_words;
for ( const std::string& word : words ) {
if ( 3 <= word.length() && word.length() <= 9 &&
word.find(middle_letter) != std::string::npos &&
word.find_first_not_of(word_wheel_letters) == std::string::npos ) {
correct_words.emplace_back(word);
}
}
for ( const std::string& correct_word : correct_words ) {
std::cout << correct_word << std::endl;
}
int32_t max_words_found = 0;
std::vector<std::string> best_words9;
std::vector<char> best_central_letters;
std::vector<std::string> words9;
for ( const std::string& word : words ) {
if ( word.length() == 9 ) {
words9.emplace_back(word);
}
}
for ( const std::string& word9 : words9 ) {
std::vector<char> distinct_letters(word9.begin(), word9.end());
std::sort(distinct_letters.begin(), distinct_letters.end());
distinct_letters.erase(std::unique(distinct_letters.begin(), distinct_letters.end()), distinct_letters.end());
for ( const char& letter : distinct_letters ) {
int32_t words_found = 0;
for ( const std::string& word : words ) {
if ( word.length() >= 3 && word.find(letter) != std::string::npos ) {
std::vector<char> letters = distinct_letters;
bool valid_word = true;
for ( const char& ch : word ) {
std::vector<char>::iterator iter = std::find(letters.begin(), letters.end(), ch);
int32_t index = ( iter == letters.end() ) ? -1 : std::distance(letters.begin(), iter);
if ( index == -1 ) {
valid_word = false;
break;
}
letters.erase(letters.begin() + index);
}
if ( valid_word ) {
words_found++;
}
}
}
if ( words_found > max_words_found ) {
max_words_found = words_found;
best_words9.clear();
best_words9.emplace_back(word9);
best_central_letters.clear();
best_central_letters.emplace_back(letter);
} else if ( words_found == max_words_found ) {
best_words9.emplace_back(word9);
best_central_letters.emplace_back(letter);
}
}
}
std::cout << "\n" << "Most words found = " << max_words_found << std::endl;
std::cout << "The nine letter words producing this total are:" << std::endl;
for ( uint64_t i = 0; i < best_words9.size(); ++i ) {
std::cout << best_words9[i] << " with central letter '" << best_central_letters[i] << "'" << std::endl;
}
}
</syntaxhighlight>
<pre>
eke
elk
keel
keen
keg
kellogg
ken
kennel
keno
knee
kneel
knell
knew
knoll
know
knowledge
known
kong
kowloon
leek
look
nook
onlook
week
weekend
wok
woke
Most words found = 215
The nine letter words producing this total are:
claremont with central letter 'a'
spearmint with central letter 'a'
</pre>
Line 1,139 ⟶ 1,265:
{{libheader| System.Classes}}
{{Trans|Wren}}
<syntaxhighlight lang="delphi">
program Word_wheel;
Line 1,192 ⟶ 1,318:
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 ⟶ 1,349:
=={{header|Factor}}==
{{works with|Factor|0.99 2020-07-03}}
<
math.statistics prettyprint sequences sorting ;
Line 1,243 ⟶ 1,369:
[ words ] keepd [ can-make? ] curry filter ;
"ndeokgelw" "unixdict.txt" solve [ length ] sort-with .</
{{out}}
<pre style="height:20ex">
Line 1,268 ⟶ 1,394:
=={{header|FreeBASIC}}==
<
#include "file.bi"
Line 1,368 ⟶ 1,494:
print matches;" matches"
Sleep
</syntaxhighlight>
{{out}}
<pre>
Line 1,391 ⟶ 1,517:
Overall time taken 0.02187220007181168 seconds
17 matches
</pre>
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
#plist NSAppTransportSecurity @{NSAllowsArbitraryLoads:YES}
include "NSLog.incl"
local fn CountCharacterInString( string as CFStringRef, character as CFStringRef ) as NSUInteger
end fn = len(string) - len( fn StringByReplacingOccurrencesOfString( string, character, @"" ) )
local fn IsLegal( wordStr as CFStringRef ) as BOOL
NSUInteger i, count = len( wordStr )
CFStringRef letters = @"ndeokgelw"
if count < 3 || fn StringContainsString( wordStr, @"k" ) == NO then exit fn = NO
for i = 0 to count - 1
if fn CountCharacterInString( letters, mid( wordStr, i, 1 ) ) < fn CountCharacterInString( wordStr, mid( wordStr, i, 1 ) )
exit fn = NO
end if
next
end fn = YES
local fn ArrayOfDictionaryWords as CFArrayRef
CFURLRef url = fn URLWithString( @"http://wiki.puzzlers.org/pub/wordlists/unixdict.txt" )
CFStringRef string = lcase( fn StringWithContentsOfURL( url, NSUTF8StringEncoding, NULL ) )
CFArrayRef wordArr = fn StringComponentsSeparatedByCharactersInSet( string, fn CharacterSetNewlineSet )
end fn = wordArr
void local fn FindWheelWords
CFArrayRef wordArr = fn ArrayOfDictionaryWords
CFStringRef wordStr
CFMutableStringRef mutStr = fn MutableStringNew
for wordStr in wordArr
if fn IsLegal( wordStr ) then MutableStringAppendFormat( mutStr, fn StringWithFormat( @"%@\n", wordStr ) )
next
NSLog( @"%@", mutStr )
end fn
fn FindWheelWords
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
eke
elk
keel
keen
keg
ken
keno
knee
kneel
knew
know
knowledge
kong
leek
week
wok
woke
</pre>
=={{header|Go}}==
{{trans|Wren}}
<
import (
Line 1,508 ⟶ 1,698:
fmt.Println(mostWords9[i], "with central letter", string(mostLetters[i]))
}
}</
{{out}}
Line 1,538 ⟶ 1,728:
=={{header|Haskell}}==
<
import Data.List (sort)
import System.IO (readFile)
Line 1,571 ⟶ 1,761:
. gridWords ["NDE", "OKG", "ELW"]
. lines
)</
{{Out}}
<pre>eke
Line 1,590 ⟶ 1,780:
wok
woke</pre>
=={{header|J}}==
<syntaxhighlight lang="j">require'stats'
wwhe=: {{
ref=. /:~each words=. cutLF tolower fread 'unixdict.txt'
y=.,y assert. 9=#y
ch0=. 4{y
chn=. (<<<4){y
r=. ''
for_i.2}.i.9 do.
target=. <"1 ~./:~"1 ch0,.(i comb 8){chn
;:inv r=. r,words #~ ref e. target
end.
}}</syntaxhighlight>
Task example:<syntaxhighlight lang="j"> wwhe'ndeokgelw'
eke elk keg ken wok keel keen keno knee knew know kong leek week woke kneel knowledge</syntaxhighlight>
=={{header|Java}}==
<syntaxhighlight lang="java">
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
public final class WordWheelExtended {
public static void main(String[] args) throws IOException {
String wordWheel = "N D E"
+ "O K G"
+ "E L W";
String url = "http://wiki.puzzlers.org/pub/wordlists/unixdict.txt";
InputStream stream = URI.create(url).toURL().openStream();
BufferedReader reader = new BufferedReader( new InputStreamReader(stream) );
List<String> words = reader.lines().toList();
reader.close();
String allLetters = wordWheel.toLowerCase().replace(" ", "");
String middleLetter = allLetters.substring(4, 5);
Predicate<String> firstFilter = word -> word.contains(middleLetter) && 2 < word.length() && word.length() < 10;
Predicate<String> secondFilter = word -> word.chars().allMatch( ch -> allLetters.indexOf(ch) >= 0 );
Predicate<String> correctWords = firstFilter.and(secondFilter);
words.stream().filter(correctWords).forEach(System.out::println);
int maxWordsFound = 0;
List<String> bestWords9 = new ArrayList<String>();
List<Character> bestCentralLetters = new ArrayList<Character>();
List<String> words9 = words.stream().filter( word -> word.length() == 9 ).toList();
for ( String word9 : words9 ) {
List<Character> distinctLetters = word9.chars().mapToObj( i -> (char) i ).distinct().toList();
for ( char letter : distinctLetters ) {
int wordsFound = 0;
for ( String word : words ) {
if ( word.length() >= 3 && word.indexOf(letter) >= 0 ) {
List<Character> letters = new ArrayList<Character>(distinctLetters);
boolean validWord = true;
for ( char ch : word.toCharArray() ) {
final int index = letters.indexOf(ch);
if ( index == -1 ) {
validWord = false;
break;
}
letters.remove(index);
}
if ( validWord ) {
wordsFound += 1;
}
}
}
if ( wordsFound > maxWordsFound ) {
maxWordsFound = wordsFound;
bestWords9.clear();
bestWords9.add(word9);
bestCentralLetters.clear();
bestCentralLetters.add(letter);
} else if ( wordsFound == maxWordsFound ) {
bestWords9.add(word9);
bestCentralLetters.add(letter);
}
}
}
System.out.println(System.lineSeparator() + "Most words found = " + maxWordsFound);
System.out.println("The nine letter words producing this total are:");
for ( int i = 0; i < bestWords9.size(); i++ ) {
System.out.println(bestWords9.get(i) + " with central letter '" + bestCentralLetters.get(i) + "'");
}
}
}
</syntaxhighlight>
<pre>
eke
elk
keel
keen
keg
kellogg
ken
kennel
keno
knee
kneel
knell
knew
knoll
know
knowledge
known
kong
kowloon
leek
look
nook
onlook
week
weekend
wok
woke
Most words found = 215
The nine letter words producing this total are:
claremont with central letter 'a'
spearmint with central letter 'a'
</pre>
=={{header|JavaScript}}==
A version using local access to the dictionary, through the macOS JavaScript for Automation API.
{{Works with|JXA}}
<
"use strict";
Line 1,688 ⟶ 2,012:
// MAIN ---
return main();
})();</
{{Out}}
<pre>eke
Line 1,707 ⟶ 2,031:
wok
woke</pre>
=={{header|jq}}==
{{works with|jq}}
'''Also works with gojq, the Go implementation of jq, and with fq''' provided `keys_unsorted` is replaced `by keys`
<syntaxhighlight lang=jq>
# remove words with fewer than 3 or more than 9 letters
def words: inputs | select(length | . > 2 and . < 10);
# The central letter in `puzzle` should be the central letter of the word wheel
def solve(puzzle):
def chars: explode[] | [.] | implode;
def profile(s): reduce s as $c (null; .[$c] += 1);
profile(puzzle[]) as $profile
| def ok($prof): all($prof|keys_unsorted[]; . as $k | $prof[$k] <= $profile[$k]);
(puzzle | .[ (length - 1) / 2]) as $central
| words
| select(index($central) and ok( profile(chars) )) ;
"The solutions to the puzzle are as follows:",
solve( ["d", "e", "e", "g", "k", "l", "n", "o", "w"] )
</syntaxhighlight>
'''Invocation''': < unixdict.txt jq -Rnr -f word-wheel.jq
{{output}}
<pre>
The solutions to the puzzle are as follows:
eke
elk
keel
keen
keg
ken
keno
knee
kneel
knew
know
knowledge
kong
leek
week
wok
woke
</pre>
=={{header|Julia}}==
<
const tfile = download("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt")
Line 1,730 ⟶ 2,097:
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,746 ⟶ 2,113:
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,774 ⟶ 2,142:
print(word)
end
end</
{{out}}
<pre>eke
Line 1,795 ⟶ 2,163:
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
possible[letters_List][word_String] := Module[{c1, c2, m},
c1 = Counts[Characters@word];
Line 1,809 ⟶ 2,177:
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,836 ⟶ 2,204:
if count > gridCount[ch]:
break checkWord
echo word</
{{out}}
Line 1,859 ⟶ 2,227:
=={{header|Pascal}}==
{{works with|Free Pascal}}
<syntaxhighlight lang="pascal">
program WordWheel;
Line 1,918 ⟶ 2,286:
search('NDE' + 'OKG' + 'ELW');
end.
</syntaxhighlight>
{{out}}
<pre>
Line 1,943 ⟶ 2,311:
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,963 ⟶ 2,331:
my @words = $file =~ /$valid/g;
print @words . " words for\n$_\n@words\n" =~ s/.{60}\K /\n/gr;</
{{out}}
<pre>
Line 1,976 ⟶ 2,344:
=={{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,057 ⟶ 2,425:
<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,072 ⟶ 2,440:
=={{header|Picat}}==
<
MinLen = 3,
MaxLen = 9,
Line 2,108 ⟶ 2,476:
foreach(E in L)
D.put(E,D.get(E,0)+1)
end.</
{{out}}
Line 2,115 ⟶ 2,483:
'''Optimal word(s)''':
<
WordList = "unixdict.txt",
MinLen = 3,
Line 2,138 ⟶ 2,506:
end,
println(maxLResen=MaxResLen),
println(maxWord=MaxResWord).</
{{out}}
Line 2,147 ⟶ 2,515:
=={{header|PureBasic}}==
<
Shared letters$
If Len(word$)<3 Or FindString(word$,"k")<1
Line 2,179 ⟶ 2,547:
Input()
EndIf
End</
{{out}}
<pre>eke
Line 2,202 ⟶ 2,570:
=={{header|Python}}==
<
from collections import Counter
Line 2,228 ⟶ 2,596:
chars = ''.join(GRID.strip().lower().split())
found = solve(chars, dictionary=getwords())
print('\n'.join(found))</
{{out}}
Line 2,251 ⟶ 2,619:
Or, using a local copy of the dictionary, and a recursive test of wheel fit:
<
from os.path import expanduser
Line 2,320 ⟶ 2,688:
# MAIN ---
if __name__ == '__main__':
main()</
{{Out}}
<pre>eke
Line 2,339 ⟶ 2,707:
wok
woke</pre>
=={{header|Quackery}}==
<syntaxhighlight lang="Quackery"> [ over find swap found ] is has ( $ c --> b )
[ over find
split 1 split
swap drop join ] is remove ( $ c --> $ )
$ "rosetta/unixdict.txt" sharefile
drop nest$
[] swap
witheach
[ dup size 3 < iff drop done
dup size 9 > iff drop done
dup char k has not iff drop done
dup $ "ndeokgelw"
witheach remove
$ "" != iff drop done
nested join ]
30 wrap$</syntaxhighlight>
{{out}}
<pre>eke elk keel keen keg ken keno knee
kneel knew know knowledge kong leek week
wok woke
</pre>
=={{header|q}}==
<
lc:ce group@ / letter count
dict:"\n"vs .Q.hg "http://wiki.puzzlers.org/pub/wordlists/unixdict.txt"
Line 2,349 ⟶ 2,745:
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,366 ⟶ 2,762:
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]
=={{header|Raku}}==
Line 2,386 ⟶ 2,779:
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,408 ⟶ 2,801:
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,431 ⟶ 2,824:
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,481 ⟶ 2,874:
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,541 ⟶ 2,934:
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,612 ⟶ 3,005:
=={{header|Ruby}}==
<
middle, wheel_size = wheel[4], wheel.size
Line 2,624 ⟶ 3,017:
puts res
</syntaxhighlight>
{{out}}
<pre>eke
Line 2,646 ⟶ 3,039:
=={{header|Transd}}==
<
MainModule: {
Line 2,656 ⟶ 3,049:
procGrid: (λ grid String() cent String() subs Bool()
(with cnt 0 (sort grid)
(for w in dict where (and (neq (
(match w "^[[:alpha:]]+$")) do
(if (is-subset grid (sort (cp w))) (+= cnt 1)
Line 2,665 ⟶ 3,058:
)),
_start: (λ locals: res 0 maxRes 0
(with fs FileStream()
(open-r fs "/mnt/proj/res/unixdict.txt")
Line 2,683 ⟶ 3,076:
(lout "New max. number: " maxRes ", word: " w ", central letter: " centl)
) ) ) )
}</
{{out}}
<pre>
Line 2,709 ⟶ 3,102:
New max. number: 215, word: spearmint, central letter: a
</pre>
=={{header|VBScript}}==
<syntaxhighlight lang="vb">
Const wheel="ndeokgelw"
Sub print(s):
On Error Resume Next
WScript.stdout.WriteLine (s)
If err= &h80070006& Then WScript.Echo " Please run this script with CScript": WScript.quit
End Sub
Dim oDic
Set oDic = WScript.CreateObject("scripting.dictionary")
Dim cnt(127)
Dim fso
Set fso = WScript.CreateObject("Scripting.Filesystemobject")
Set ff=fso.OpenTextFile("unixdict.txt")
i=0
print "reading words of 3 or more letters"
While Not ff.AtEndOfStream
x=LCase(ff.ReadLine)
If Len(x)>=3 Then
If Not odic.exists(x) Then oDic.Add x,0
End If
Wend
print "remaining words: "& oDic.Count & vbcrlf
ff.Close
Set ff=Nothing
Set fso=Nothing
Set re=New RegExp
print "removing words with chars not in the wheel"
re.pattern="[^"& wheel &"]"
For Each w In oDic.Keys
If re.test(w) Then oDic.remove(w)
Next
print "remaining words: "& oDic.Count & vbcrlf
print "ensuring the mandatory letter "& Mid(wheel,5,1) & " is present"
re.Pattern=Mid(wheel,5,1)
For Each w In oDic.Keys
If Not re.test(w) Then oDic.remove(w)
Next
print "remaining words: "& oDic.Count & vbcrlf
print "checking number of chars"
Dim nDic
Set nDic = WScript.CreateObject("scripting.dictionary")
For i=1 To Len(wheel)
x=Mid(wheel,i,1)
If nDic.Exists(x) Then
a=nDic(x)
nDic(x)=Array(a(0)+1,0)
Else
nDic.add x,Array(1,0)
End If
Next
For Each w In oDic.Keys
For Each c In nDic.Keys
ndic(c)=Array(nDic(c)(0),0)
Next
For ii = 1 To len(w)
c=Mid(w,ii,1)
a=nDic(c)
If (a(0)=a(1)) Then
oDic.Remove(w):Exit For
End If
nDic(c)=Array(a(0),a(1)+1)
Next
Next
print "Remaining words "& oDic.count
For Each w In oDic.Keys
print w
Next
</syntaxhighlight>
{{out}}
<small>
<pre>
reading words of 3 or more letters
remaining words: 24945
removing words with chars not in the wheel
remaining words: 163
ensuring the mandatory letter k is present
remaining words: 27
checking number of chars
Remaining words 17
eke
elk
keel
keen
keg
ken
keno
knee
kneel
knew
know
knowledge
kong
leek
week
wok
woke
</pre>
</small>
=={{header|Wren}}==
{{libheader|Wren-sort}}
{{libheader|Wren-seq}}
<
import "./sort" for Sort, Find
import "./seq" for Lst
var letters = ["d", "e", "e", "g", "k", "l", "n", "o","w"]
Line 2,784 ⟶ 3,288:
for (i in 0...mostWords9.count) {
System.print("%(mostWords9[i]) with central letter '%(mostLetters[i])'")
}</
{{out}}
Line 2,814 ⟶ 3,318:
=={{header|XPL0}}==
<
int I, Set, HasK, HasOther, HasDup, ECnt, Ch;
char Word(25);
Line 2,839 ⟶ 3,343:
];
until Ch = EOF;
]</
{{out}}
|