Jump to content

Wordiff: Difference between revisions

m
syntax highlighting fixup automation
(J)
m (syntax highlighting fixup automation)
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 213:
 
=={{header|J}}==
<langsyntaxhighlight Jlang="j">require'general/misc/prompt'
wordiff=: {{
words=: cutLF tolower fread'unixdict.txt'
Line 248:
end.
echo c2,' wins'
}}</langsyntaxhighlight>
 
Example game:<langsyntaxhighlight Jlang="j"> wordiff''
Name of contestant 1: Jack
Name of contestant 2: Jill
Line 264:
Pick a new word Jill: slap
slap has already been picked
Jack wins</langsyntaxhighlight>
=={{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:
 
wordiff()
</langsyntaxhighlight>{{out}}
<pre>
Time limit (min) or 0 for none: 0.7
Line 342:
=={{header|Nim}}==
{{trans|Python}}
<langsyntaxhighlight Nimlang="nim">import httpclient, sequtils, sets, strutils, sugar
from unicode import capitalize
 
Line 460:
echo "You could have used: ", possibleWords[0..min(possibleWords.high, 20)].join(" ")
break
iplayer = (iplayer + 1) mod players.len</langsyntaxhighlight>
 
{{out}}
Line 477:
{{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:
<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:
=={{header|Perl}}==
Borrowed code from [[Levenshtein_distance]].
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
Line 875:
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:
=={{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:
print("Could have used:",
', '.join(islice(could_have_got(wordiffs, dic), 10)), '...')
break</langsyntaxhighlight>
 
{{out}}
Line 1,033:
 
=={{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:
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:
 
=={{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:
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,338:
 
=={{header|Vlang}}==
<syntaxhighlight lang="text">import os
import rand
import time
Line 1,435:
}
}
</syntaxhighlight>
</lang>
{{out}}
<pre>Time limit (sec) or 0 for none: 40
Line 1,457:
{{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 lang="ecmascript">import "random" for Random
import "/ioutil" for File, Input
import "/str" for Str
Line 1,541:
return
}
}</langsyntaxhighlight>
 
{{out}}
10,333

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.