Wordiff: Difference between revisions

21,515 bytes added ,  2 months ago
Added FreeBASIC
(J)
(Added FreeBASIC)
 
(9 intermediate revisions by 5 users not shown)
Line 43:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">V dict_fname = ‘unixdict.txt’
 
F load_dictionary(String fname = dict_fname)
Line 131:
print(‘YOU HAVE LOST ’name‘!’)
print(‘Could have used: ’(could_have_got(wordiffs, dic)[0.<10]).join(‘, ’)‘ ...’)
L.break</langsyntaxhighlight>
 
{{out}}
Line 148:
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">wordset: map read.lines relative "unixdict.txt" => strip
 
validAnswer?: function [answer][
Line 182:
current: (current=playerA)? -> playerB -> playerA
print ""
]</langsyntaxhighlight>
 
{{out}}
Line 211:
Bill, what is the next word? famous
Not a correct wordiff. Try again: fame</pre>
 
=={{header|C++}}==
<syntaxhighlight lang="c++">
#include <algorithm>
#include <cstdint>
#include <fstream>
#include <iostream>
#include <random>
#include <string>
#include <vector>
 
std::vector<std::string> request_player_names() {
std::vector<std::string> player_names;
std::string player_name;
for ( uint32_t i = 0; i < 2; ++i ) {
std::cout << "Please enter the player's name: ";
std::getline(std::cin, player_name);
player_names.emplace_back(player_name);
}
return player_names;
}
 
bool is_letter_removed(const std::string& previous_word, const std::string& current_word) {
for ( uint64_t i = 0; i < previous_word.length(); ++i ) {
if ( current_word == previous_word.substr(0, i) + previous_word.substr(i + 1) ) {
return true;
}
}
return false;
}
 
bool is_letter_added(const std::string& previous_word, const std::string& current_word) {
return is_letter_removed(current_word, previous_word);
}
 
bool is_letter_changed(const std::string& previous_word, const std::string& current_word) {
if ( previous_word.length() != current_word.length() ) {
return false;
}
 
uint32_t difference_count = 0;
for ( uint64_t i = 0; i < current_word.length(); ++i ) {
difference_count += ( current_word[i] == previous_word[i] ) ? 0 : 1;
}
return difference_count == 1;
}
 
bool is_wordiff(const std::string& current_word,
const std::vector<std::string>& words_used,
const std::vector<std::string>& dictionary) {
if ( std::find(dictionary.begin(), dictionary.end(), current_word) == dictionary.end()
|| std::find(words_used.begin(), words_used.end(), current_word) != words_used.end() ) {
return false;
}
 
std::string previous_word = words_used.back();
return is_letter_changed(previous_word, current_word)
|| is_letter_removed(previous_word, current_word) || is_letter_added(previous_word, current_word);
}
 
std::vector<std::string> could_have_entered(const std::vector<std::string>& words_used,
const std::vector<std::string>& dictionary) {
std::vector<std::string> result;
for ( const std::string& word : dictionary ) {
if ( std::find(words_used.begin(), words_used.end(), word) == words_used.end()
&& is_wordiff(word, words_used, dictionary) ) {
result.emplace_back(word);
}
}
return result;
}
 
int main() {
std::vector<std::string> dictionary;
std::vector<std::string> starters;
std::fstream file_stream;
file_stream.open("../unixdict.txt");
std::string word;
while ( file_stream >> word ) {
dictionary.emplace_back(word);
if ( word.length() == 3 || word.length() == 4 ) {
starters.emplace_back(word);
}
}
 
std::random_device rand;
std::mt19937 mersenne_twister(rand());
std::shuffle(starters.begin(), starters.end(), mersenne_twister);
std::vector<std::string> words_used;
words_used.emplace_back(starters[0]);
 
std::vector<std::string> player_names = request_player_names();
bool playing = true;
uint32_t playerIndex = 0;
std::string current_word;
std::cout << "The first word is: " << words_used.back() << std::endl;
 
while ( playing ) {
std::cout << player_names[playerIndex] << " enter your word: ";
std::getline(std::cin, current_word);
if ( is_wordiff(current_word, words_used, dictionary) ) {
words_used.emplace_back(current_word);
playerIndex = ( playerIndex == 0 ) ? 1 : 0;
} else {
std::cout << "You have lost the game, " << player_names[playerIndex] << std::endl;
std::vector<std::string> missed_words = could_have_entered(words_used, dictionary);
std::cout << "You could have entered: [";
for ( uint64_t i = 0; i < missed_words.size() - 1; ++i ) {
std::cout << missed_words[i] << ", ";
}
std::cout << missed_words.back() << "]" << std::endl;
playing = false;
}
}
}
</syntaxhighlight>
{{ out }}
<pre>
Please enter the player's name: Alice
Please enter the player's name: Bob
The first word is: her
Alice enter your word: hem
Bob enter your word: hemp
Alice enter your word: temp
You have lost the game, Alice
You could have entered: [heap, help, hump, kemp]
</pre>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="vbnet">REM Wordiff ' 10 march 2024 '
 
'--- Declaración de variables globales ---
Dim Shared As String words()
Dim Shared As String used()
Dim Shared As String player1
Dim Shared As String player2
Dim Shared As String player
Dim Shared As String prevWord
Dim Shared As Integer prevLen
 
'--- SUBrutinas y FUNCiones ---
Sub loadWords
Dim As Integer i, j, numLines
Dim As String linea
Open "unixdict.txt" For Input As #1
While Not Eof(1)
Line Input #1, linea
If Len(linea) = 3 Or Len(linea) = 4 Then
Redim Preserve words(numLines)
words(numLines) = linea
numLines += 1
End If
Wend
Close #1
End Sub
 
Sub Intro
Cls
Color 10, 0 '10, black
Locate 10, 30 : Print "---WORDIFF---"
Locate 12, 5 : Print "Por turnos, teclear nuevas palabras del "
Locate 13, 5 : Print "diccionario de tres o mas caracteres que "
Locate 14, 5 : Print "se diferencien de la anterior en una letra."
Color 14
Locate 16, 5 : Input "Player 1, please enter your name: ", player1
Locate 17, 5 : Input "Player 2, please enter your name: ", player2
If player2 = player1 Then player2 &= "2"
Color 7
End Sub
 
 
Function wordExists(word As String) As Boolean
For i As Integer = 0 To Ubound(words)
If words(i) = word Then Return True
Next i
Return False
End Function
 
Function wordUsed(word As String) As Boolean
For i As Integer = 0 To Ubound(used)
If used(i) = word Then Return True
Next i
Return False
End Function
 
Sub addUsedWord(word As String)
Redim Preserve used(Ubound(used) + 1)
used(Ubound(used)) = word
End Sub
 
Sub MenuPrincipal
Dim As String word
Dim As Integer i, changes, longi
Dim As Boolean ok
Cls
prevWord = words(Int(Rnd * Ubound(words)))
prevLen = Len(prevWord)
player = player1
Print "The first word is ";
Color 15 : Print prevWord : Color 7
Do
Color 7 : Print player; ", plays:";
Color 15 : Input " ", word
word = Lcase(word)
longi = Len(word)
ok = False
Color 12
If longi < 3 Then
Print "Words must be at least 3 letters long."
Elseif wordExists(word) = 0 Then
Print "Not in dictionary."
Elseif wordUsed(word) <> 0 Then
Print "Word has been used before."
Elseif word = prevWord Then
Print "You must change the previous word."
Elseif longi = prevLen Then
changes = 0
For i = 1 To longi
If Mid(word, i, 1) <> Mid(prevWord, i, 1) Then changes += 1
Next i
If changes > 1 Then
Print "Only one letter can be changed."
Else
ok = True
End If
Else
Print "Invalid change."
End If
If ok Then
prevLen = longi
prevWord = word
addUsedWord(word)
player = Iif(player = player1, player2, player1)
Else
Print "So, sorry "; player; ", you've lost!"
Dim As String KBD
Do: KBD = Inkey: Loop While KBD = ""
Exit Do
End If
Loop
End Sub
 
'--- Programa Principal ---
Randomize Timer
Intro
loadWords
MenuPrincipal
End
'--------------------------</syntaxhighlight>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
output file "Wordiff" ' 27 november 2022 '
 
#plist NSAppTransportSecurity @{NSAllowsArbitraryLoads:YES}
 
begin enum 1
_playerLabel : _playerInput : _wordLabel : _wordInPlay : _playsLabel
_scrlView : _textView
_resignBtn : _againBtn : _quitBtn
end enum
 
begin globals
CFMutableArrayRef gWords, gNames, gUsed
gWords = fn MutableArrayWithCapacity( 0 )
gNames = fn MutableArrayWithCapacity( 0 )
gUsed = fn MutableArrayWithCapacity( 0 )
CFMutableStringRef gTxt
gTxt = fn MutableStringWithCapacity( 0 )
end globals
 
void local fn BuildInterface
window 1, @"Wordiff", ( 0, 0, 400, 450 ), NSWindowStyleMaskTitled + NSWindowStyleMaskClosable
// Fields for labels and input
textlabel _playerLabel, @"The players:", ( 0, 370, 148, 24 )
textlabel _wordLabel, @"Word in play:", ( 68, 409, 100, 24 )
textlabel _playsLabel, , ( 113, 370, 150, 24 )
textfield _playerInput, Yes, , ( 160, 372, 150, 24 )
textfield _wordInPlay, No, @". . .", ( 160, 412, 148, 24 )
ControlSetAlignment( _playerLabel, NSTextAlignmentRight )
ControlSetAlignment( _playerInput, NSTextAlignmentCenter )
ControlSetAlignment( _wordInPlay, NSTextAlignmentCenter )
ControlSetFormat( _playerInput, @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", YES, 8, _formatCapitalize )
TextFieldSetTextColor( _wordLabel, fn ColorLightGray )
TextFieldSetTextColor( _wordInPlay, fn ColorLightGray )
TextFieldSetSelectable( _wordInPlay, No )
// Fields for computer feedback
scrollview _scrlView, ( 20, 60, 356, 300 ), NSBezelBorder
textview _textView, , _scrlView, , 1
ScrollViewSetHasVerticalScroller( _scrlView, YES )
TextViewSetTextContainerInset( _textView, fn CGSizeMake( 3, 3 ) )
TextSetFontWithName( _textView, @"Menlo", 12 )
TextSetColor( _textView, fn colorLightGray )
TextSetString( _textView, @"First, enter the name of each player and press Return to confirm. ¬
When done, press Return to start the game." )
// Buttons and menus
button _resignBtn, No, , @"Resign", ( 251, 15, 130, 32 )
button _againBtn, No, , @"New game", ( 114, 15, 130, 32 )
button _quitBtn, Yes, , @"Quit", ( 15, 15, 92, 32 )
filemenu 1 : menu 1, , No ' Nothing to file
editmenu 2 : menu 2, , No ' Nothing to edit
WindowMakeFirstResponder( 1, _playerInput ) ' Activate player input field
end fn
 
void local fn LoadWords
CFURLRef url
CFStringRef words, string
CFArrayRef tmp
CFRange range
// Fill the gWords list with just the lowercase words in unixdict
url = fn URLWithString( @"http://wiki.puzzlers.org/pub/wordlists/unixdict.txt" )
words = fn StringWithContentsOfURL( url, NSUTF8StringEncoding, NULL )
tmp = fn StringComponentsSeparatedByCharactersInSet( ( words ), fn CharacterSetNewlineSet )
for string in tmp
range = fn StringRangeOfStringWithOptions( string, @"^[a-z]+$", NSRegularExpressionSearch )
if range.location != NSNotFound then MutableArrayAddObject( gWords, string )
next
end fn
 
void local fn Say(str1 as CFStringRef, str2 as CFStringRef )
// Add strings to the computer feedback
fn MutableStringAppendString( gTxt, str1 )
fn MutableStringAppendString( gTxt, str2 )
TextSetString( _textView, gTxt )
TextScrollRangeToVisible( _textView, fn CFRangeMake( len( fn TextString( _textView ) ), 0) )
end fn
 
local fn CompareEqual( wrd1 as CFStringRef, wrd2 as CFStringRef ) as short
NSInteger i, k
CFStringRef a, b
//Find the number of differences in two strings
k = 0
for i = 0 to len( wrd1 ) - 1
a = mid( wrd1, i, 1 ) : b = mid( wrd2, i, 1 )
if fn StringIsEqual( a, b ) == No then k++
next
end fn = k
 
 
local fn ChopAndStitch( sShort as CFStringRef, sLong as CFStringRef ) as CFStringRef
NSInteger i, k
CFStringRef a, b
// Find the extra letter in the long string and remove it
k = 0
for i = 0 to len( sLong ) - 1
a = mid( sShort, i, 1 ) : b = mid( sLong, i, 1 )
if fn StringIsEqual( a, b ) == No then k = i : break ' Found it
next
a = left( sLong, k ) : b = mid( sLong, k + 1 ) 'Removed it
end fn = fn StringByAppendingString( a, b )
 
 
local fn WordiffWords( wrd1 as CFStringRef, wrd2 as CFStringRef ) as short
Short err = 0
// If a letter was added or removed, the strings should be identical after
// we remove the extra letter from the longest string.
// If they are the same length, the strings may differ at just one place.
select case
case len( wrd2 ) > len( wrd1 )
wrd2 = fn ChopAndStitch( wrd1, wrd2 )
if fn CompareEqual( wrd1, wrd2 ) != 0 then err = 1 ' Words identical?
case len( wrd1 ) > len( wrd2 )
wrd1 = fn ChopAndStitch( wrd2, wrd1 )
if fn CompareEqual( wrd1, wrd2 ) != 0 then err = 2
case len( wrd2 ) = len( wrd1 )
if fn CompareEqual( wrd1, wrd2 ) != 1 then err = 3 ' Only one change?
end select
end fn = err
 
local fn CheckWord( wrd1 as CFStringRef, wrd2 as CFStringRef ) as short
Short err = 0
// Preliminary tests to generate error codes
select case
case fn StringIsEqual( wrd1, wrd2 ) : err = 1
case len( wrd2 ) < 3 : err = 2
case len( wrd2 ) - len( wrd1 ) > 1 : err = 3
case len( wrd1 ) - len( wrd2 ) > 1 : err = 4
case fn ArrayContainsObject( gUsed, wrd2 ) == Yes : err = 5
case fn ArrayContainsObject( gWords, wrd2 ) == No : err = 6
end select
// Report error. If no error, check against Wordiff rules
select err
case 1 : fn Say( @"Don't be silly.", @"\n" )
case 2 : fn Say( @"New word must be three or more letters.", @"\n" )
case 3 : fn Say( @"Add just one letter, please.", @"\n" )
case 4 : fn Say( @"Delete just one letter, please.", @"\n" )
case 5 : fn Say( fn StringCapitalizedString( wrd2 ), @" was already used.\n" )
case 6 : fn Say( fn StringCapitalizedString( wrd2 ), @" is not in the dictionary.\n")
case 0
err = fn WordiffWords ( wrd1, wrd2 )
select err
case 1 : fn Say( @"Either change or add a letter.", @"\n" )
case 2 : fn Say( @"Either change or delete a letter.", @"\n" )
case 3 : fn Say( @"Don't change more than one letter.", @"\n")
end select
end select
end fn = err
 
void local fn ShowAllPossible
CFMutableArrayRef poss
CFStringRef wrd1, wrd2
NSUInteger i
// Check all words in dictionary, ignore error messages
poss = fn MutableArrayWithCapacity( 0 )
wrd1 = fn ControlStringValue( _wordInPlay )
for i = 0 to fn ArrayCount( gWords ) - 1
wrd2 = fn ArrayObjectAtIndex( gWords, i )
if fn fabs( len( wrd1 ) - len( wrd2 ) ) < 2 ' Not too long or short?
if len( wrd2 ) > 2 ' Has more than 2 chars?
if fn ArrayContainsObject( gUsed, wrd2 ) == No ' Not used before?
if ( fn WordiffWords( wrd1, wrd2 ) == 0 ) ' According to rules?
MutableArrayAddObject( poss, wrd2 ) ' Legal, so add to the pot
end if
end if
end if
end if
next
// Display legal words
fn Say( @"\n", fn ControlStringValue( _playerLabel ) )
if fn ArrayCount( poss ) > 0 ' Any words left?
fn Say( @" resigns, but could have chosen:", @"\n" )
fn MutableStringAppendString( gTxt, fn ArrayComponentsJoinedByString( poss, @", or " ) )
TextSetString( _textView, gTxt )
else
fn Say(@" resigns, there were no words left to play. ", @"New game?\n" )
end if
textfield _playerInput, No ' Just to be safe
end fn
 
void local fn Play
CFStringRef old, new, name
NSUInteger n
// Gather the info
name = fn ControlStringValue( _playerLabel )
new = fn ControlStringValue( _playerInput )
old = fn ArrayLastObject( gUsed )
if len( new ) == 0 then exit fn ' Just to be safe
fn Say(new, @"\n" )
if fn CheckWord( old, new ) == 0
// Input OK, so get ready next player
n = ( ( fn ArrayIndexOfObject( gNames, name ) + 1 ) mod fn ArrayCount( gNames ) )
name = fn ArrayObjectAtIndex( gNames, n )
textlabel _playerLabel, name
textfield _wordInPlay, , new
MutableArrayAddObject( gUsed, new )
end if
fn Say( name, @" plays: " )
textfield _playerInput, , @""
end fn
 
void local fn StartNewGame
CFStringRef name, wrd
NSUInteger n
// Pick a first player
n = rnd( fn ArrayCount( gNames ) )
name = fn ArrayObjectAtIndex( gNames, n - 1 )
// Pick a first word
MutableArrayRemoveAllObjects( gUsed )
do
n = rnd( fn ArrayCount( gWords ) ) - 1
wrd = fn ArrayObjectAtIndex( gWords, n )
until ( len( wrd ) = 3 ) or ( len( wrd ) = 4 )
MutableArrayAddObject( gUsed, wrd )
// Update window
ControlSetFormat( _playerInput, @"abcdefghijklmnopqrstuvwxyz", YES, 0, _formatLowercase )
fn Say( @"\n", @"Word in play: " ) : fn Say( wrd, @"\n" )
fn Say( name, @" plays: " )
textfield _wordInPlay, Yes, wrd
textlabel _playerLabel, name, (0, 370, 110, 24 )
textlabel _playsLabel, @"plays:"
textfield _playerInput, Yes
button _againBtn, Yes
button _resignBtn, Yes
WindowMakeFirstResponder( 1, _playerInput )
end fn
 
void local fn AskNames
CFStringRef name
name = fn ControlStringValue( _playerInput )
if len( name ) > 0 ' Another player?
MutableArrayAddObject( gNames, name )
fn Say( @"Welcome, ", name )
fn Say( @"!", @"\n" )
textfield _playerInput, YES, @""
else
if fn ArrayFirstObject( gNames ) != Null ' Just to be safe
fn StartNewGame
end if
end if
end fn
 
void local fn DoDialog( evt as Long, tag as Long )
select evt
case _btnClick
select tag
case _againBtn
fn MutableStringSetString( gTxt, @"" )
fn StartNewGame
case _resignBtn
button _resignBtn, No
fn ShowAllPossible
case _quitBtn : end
end select
case _textFieldDidEndEditing
if fn ArrayCount( gUsed ) == 0
fn AskNames
else
fn Play
end if
case _windowShouldClose : end
end select
end fn
 
on dialog fn DoDialog
 
fn BuildInterface
fn LoadWords
 
handleevents
</syntaxhighlight>
{{output}}
[[File:Wordiff FutureBasic.png]]
 
=={{header|J}}==
<langsyntaxhighlight Jlang="j">require'general/misc/prompt'
wordiff=: {{
words=: cutLF tolower fread'unixdict.txt'
Line 248 ⟶ 773:
end.
echo c2,' wins'
}}</langsyntaxhighlight>
 
Example game:<langsyntaxhighlight Jlang="j"> wordiff''
Name of contestant 1: Jack
Name of contestant 2: Jill
Line 264 ⟶ 789:
Pick a new word Jill: slap
slap has already been picked
Jack wins</langsyntaxhighlight>
 
=={{header|Java}}==
<syntaxhighlight lang="java">
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
 
public final class Wordiff {
 
public static void main(String[] args) throws IOException {
List<String> dictionary = Files.lines(Path.of("unixdict.txt")).toList();
List<String> starters = dictionary.stream()
.filter( word -> word.length() == 3 || word.length() == 4 ).collect(Collectors.toList());
Collections.shuffle(starters);
List<String> wordsUsed = new ArrayList<String>();
wordsUsed.add(starters.get(0));
Scanner scanner = new Scanner(System.in);
List<String> playerNames = requestPlayerNames(scanner);
boolean playing = true;
int playerIndex = 0;
System.out.println("The first word is: " + wordsUsed.get(wordsUsed.size() - 1));
while ( playing ) {
System.out.println(playerNames.get(playerIndex) + " enter your word: ");
String currentWord = scanner.nextLine();
if ( isWordiff(currentWord, wordsUsed, dictionary) ) {
wordsUsed.add(currentWord);
playerIndex = ( playerIndex == 0 ) ? 1 : 0;
} else {
System.out.println("You have lost the game, " + playerNames.get(playerIndex));
System.out.println("You could have entered: " + couldHaveEntered(wordsUsed, dictionary));
playing = false;
}
}
scanner.close();
}
private static boolean isWordiff(String currentWord, List<String> wordsUsed, List<String> dictionary) {
if ( ! dictionary.contains(currentWord) || wordsUsed.contains(currentWord) ) {
return false;
}
String previousWord = wordsUsed.get(wordsUsed.size() - 1);
return isLetterChanged(previousWord, currentWord)
|| isLetterRemoved(previousWord, currentWord) || isLetterAdded(previousWord, currentWord);
}
private static boolean isLetterRemoved(String previousWord, String currentWord) {
for ( int i = 0; i < previousWord.length(); i++ ) {
if ( currentWord.equals(previousWord.substring(0, i) + previousWord.substring(i + 1)) ) {
return true;
}
}
return false;
}
private static boolean isLetterAdded(String previousWord, String currentWord) {
return isLetterRemoved(currentWord, previousWord);
}
 
private static boolean isLetterChanged(String previousWord, String currentWord) {
if ( previousWord.length() != currentWord.length() ) {
return false;
}
int differenceCount = 0;
for ( int i = 0; i < currentWord.length(); i++ ) {
differenceCount += ( currentWord.charAt(i) == previousWord.charAt(i) ) ? 0 : 1;
}
return differenceCount == 1;
}
private static List<String> couldHaveEntered(List<String> wordsUsed, List<String> dictionary) {
List<String> result = new ArrayList<String>();
for ( String word : dictionary ) {
if ( ! wordsUsed.contains(word) && isWordiff(word, wordsUsed, dictionary) ) {
result.add(word);
}
}
return result;
}
private static List<String> requestPlayerNames(Scanner scanner) {
List<String> playerNames = new ArrayList<String>();
for ( int i = 0; i < 2; i++ ) {
System.out.print("Please enter the player's name: ");
String playerName = scanner.nextLine().trim();
playerNames.add(playerName);
}
return playerNames;
}
 
}
</syntaxhighlight>
{{ out }}
<pre>
Please enter the player's name: Alice
Please enter the player's name: Bob
The first word is: tnt
Alice enter your word:
tent
Bob enter your word:
teat
Alice enter your word:
team
Bob enter your word:
steam
Alice enter your word:
steamy
Bob enter your word:
steams
You have lost the game, Bob
You could have entered: [seamy, steady]
</pre>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">isoneless(nw, ow) = any(i -> nw == ow[begin:i-1] * ow[i+1:end], eachindex(ow))
isonemore(nw, ow) = isoneless(ow, nw)
isonechanged(x, y) = length(x) == length(y) && count(i -> x[i] != y[i], eachindex(y)) == 1
Line 317 ⟶ 963:
 
wordiff()
</langsyntaxhighlight>{{out}}
<pre>
Time limit (min) or 0 for none: 0.7
Line 342 ⟶ 988:
=={{header|Nim}}==
{{trans|Python}}
<langsyntaxhighlight Nimlang="nim">import httpclient, sequtils, sets, strutils, sugar
from unicode import capitalize
 
Line 460 ⟶ 1,106:
echo "You could have used: ", possibleWords[0..min(possibleWords.high, 20)].join(" ")
break
iplayer = (iplayer + 1) mod players.len</langsyntaxhighlight>
 
{{out}}
Line 477 ⟶ 1,123:
{{libheader|Phix/pGUI}}
Doubtless this could be improved in umpteen ways. Not quite yet working under pwa/p2js, but not too far off.
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Wordiff.exw</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 783 ⟶ 1,429:
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</langsyntaxhighlight>-->
{{out}}
A quick timed-out game:
Line 823 ⟶ 1,469:
=={{header|Perl}}==
Borrowed code from [[Levenshtein_distance]].
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
Line 875 ⟶ 1,521:
if (@possibles) { say "\nSorry $name,${already} one of <@possibles> would have continued the game." }
else { say "\nGood job $name,${already} there were no possible words to play." }
say "You made it through $rounds rounds.";</langsyntaxhighlight>
{{out}}
<pre>What is your name? Sir Lancelot of Camelot
Line 896 ⟶ 1,542:
=={{header|Python}}==
This is without timing, but ends by showing some wordiffs from the dictionary that could have worked on failure.
<langsyntaxhighlight lang="python"># -*- coding: utf-8 -*-
 
from typing import List, Tuple, Dict, Set
Line 1,002 ⟶ 1,648:
print("Could have used:",
', '.join(islice(could_have_got(wordiffs, dic), 10)), '...')
break</langsyntaxhighlight>
 
{{out}}
Line 1,033 ⟶ 1,679:
 
=={{header|Raku}}==
<syntaxhighlight lang="raku" perl6line>my @words = 'unixdict.txt'.IO.slurp.lc.words.grep(*.chars > 2);
 
my @small = @words.grep(*.chars < 6);
Line 1,087 ⟶ 1,733:
say "\nGood job{$name}{$already} there were no possible words to play."
}
say "You made it through $rounds rounds.";</langsyntaxhighlight>
{{out|Sample output}}
<pre>Hello player one, what is your name? Burtram Redneck
Line 1,179 ⟶ 1,825:
 
=={{header|REXX}}==
<langsyntaxhighlight lang="rexx">/*REXX program acts as a host and allows two or more people to play the WORDIFF game.*/
signal on halt /*allow the user(s) to halt the game. */
parse arg iFID seed . /*obtain optional arguments from the CL*/
Line 1,274 ⟶ 1,920:
end /*#*/
if r>100 & starters> 10 then return /*is the dictionary satisfactory ? */
call ser 'Dictionary file ' _ iFID _ "wasn't found or isn't satisfactory."; exit 13</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 1,337 ⟶ 1,983:
</pre>
 
=={{header|V (Vlang)}}==
<syntaxhighlight lang="text">import os
import rand
import time
Line 1,435 ⟶ 2,081:
}
}
</syntaxhighlight>
</lang>
{{out}}
<pre>Time limit (sec) or 0 for none: 40
Line 1,457 ⟶ 2,103:
{{libheader|Wren-sort}}
Due to a bug in the System.clock method (basically it gets suspended whilst waiting for user input), it is not currently possible to add timings.
<langsyntaxhighlight ecmascriptlang="wren">import "random" for Random
import "./ioutil" for File, Input
import "./str" for Str
import "./sort" for Find
 
var rand = Random.new()
Line 1,541 ⟶ 2,187:
return
}
}</langsyntaxhighlight>
 
{{out}}
2,134

edits