Wordiff: Difference between revisions

m
→‎{{header|Julia}}: add new length > 2 requirement
m (→‎{{header|REXX}}: changed REXX program to restrict words to at least three characters.)
m (→‎{{header|Julia}}: add new length > 2 requirement)
Line 45:
print(prompt)
ans = strip(readline())
println()
end
return ans
Line 51 ⟶ 50:
 
function wordiff(dictfile = "unixdict.txt")
wordlist = [w for w in split(read(dictfile, String), r"\s+") if !occursin(r"\W", w) && length(w) > 2]
starters = [w for w in wordlist if 3 <= length(w) <= 4]
 
Line 58 ⟶ 57:
players = split(askprompt("Enter players' names. Separate by commas: "), r"\s*,\s*")
times, word = Dict(player => Float32[] for player in players), rand(starters)
used, totalsecs, timestart = [word], timelimit * 60, time()
totalsecs, timestart = timelimit * 60, time()
while length(players) > 1
player = popfirst!(players)
Line 72 ⟶ 70:
push!(times[player], time() - playertimestart)
else
println("Wordiff choice incorrentincorrect. Player $player exits game.")
end
else # out of time
Line 82 ⟶ 80:
break
end
sleep(rand() * 103)
end
length(players) < 2 && println("Player $(first(players)) is the only one left, and wins the game.")
Line 90 ⟶ 88:
</lang>{{out}}
<pre>
Time limit (min) or 0 for none: 0.4
 
Enter players' names. Separate by commas: sam,mary,ann,ron
 
sam, your move. The current word is shod. Your worddiff? shot
 
#=
Time limit (min) or 0 for none: 0.47
Enter players' names. Separate by commas: samAnn,mary Betty,ann Sam,ron Ron, Kim
samAnn, your move. The current word is shodcity. Your worddiff? shotcite
Correct.
maryBetty, your move. The current word is shotcite. Your worddiff? hotkite
 
Correct.
annSam, your move. The current word is hotkite. Your worddiff? hogkit
 
Correct.
ronRon, your move. The current word is hogkit. Your worddiff? logsit
Correct.
 
Kim, your move. The current word is sit. Your worddiff? it
Wordiff choice incorrect. Player Kim exits game.
Ann, your move. The current word is sit. Your worddiff? site
Correct.
Betty, your move. The current word is site. Your worddiff? mite
Sorry, time was up. Timing ranks for remaining players:
annRon: 34.1134 seconds average
maryAnn: 46.573265 seconds average
samSam: 6.4479189997 seconds average
</pre>
 
4,103

edits