Wordiff: Difference between revisions
m
syntax highlighting fixup automation
(J) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 43:
{{trans|Python}}
<
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</
{{out}}
Line 148:
=={{header|Arturo}}==
<
validAnswer?: function [answer][
Line 182:
current: (current=playerA)? -> playerB -> playerA
print ""
]</
{{out}}
Line 213:
=={{header|J}}==
<
wordiff=: {{
words=: cutLF tolower fread'unixdict.txt'
Line 248:
end.
echo c2,' wins'
}}</
Example game:<
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</
=={{header|Julia}}==
<
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()
</
<pre>
Time limit (min) or 0 for none: 0.7
Line 342:
=={{header|Nim}}==
{{trans|Python}}
<
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</
{{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.
<!--<
<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>
<!--</
{{out}}
A quick timed-out game:
Line 823:
=={{header|Perl}}==
Borrowed code from [[Levenshtein_distance]].
<
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.";</
{{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.
<
from typing import List, Tuple, Dict, Set
Line 1,002:
print("Could have used:",
', '.join(islice(could_have_got(wordiffs, dic), 10)), '...')
break</
{{out}}
Line 1,033:
=={{header|Raku}}==
<syntaxhighlight lang="raku"
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.";</
{{out|Sample output}}
<pre>Hello player one, what is your name? Burtram Redneck
Line 1,179:
=={{header|REXX}}==
<
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</
{{out|output|text= when using the default inputs:}}
<pre>
Line 1,338:
=={{header|Vlang}}==
<syntaxhighlight lang="text">import os
import rand
import time
Line 1,435:
}
}
</syntaxhighlight>
{{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.
<
import "/ioutil" for File, Input
import "/str" for Str
Line 1,541:
return
}
}</
{{out}}
|