Wordiff: Difference between revisions
Added Arturo implementation
m (→{{header|Phix}}: added libheader) |
Drkameleon (talk | contribs) (Added Arturo implementation) |
||
Line 145:
Could have used: are, bare, cadre, cafe, cage, cake, came, cane, cape, car ...
</pre>
=={{header|Arturo}}==
<lang rebol>wordset: map read.lines relative "unixdict.txt" => strip
validAnswer?: function [answer][
if not? contains? wordset answer [
prints "\tNot a valid dictionary word."
return false
]
if contains? pastWords answer [
prints "\tWord already used."
return false
]
if 1 <> levenshtein answer last pastWords [
prints "\tNot a correct wordiff."
return false
]
return true
]
playerA: input "player A: what is your name? "
playerB: input "player B: what is your name? "
pastWords: new @[sample select wordset 'word [ contains? [3 4] size word ]]
print ["\nThe initial word is: " last pastWords "\n"]
current: playerA
while ø [
neww: strip input ~"|current|, what is the next word? "
while [not? validAnswer? neww][
neww: strip input " Try again: "
]
'pastWords ++ neww
current: (current=playerA)? -> playerB -> playerA
print ""
]</lang>
{{out}}
<pre>player A: what is your name? John
player B: what is your name? Bill
The initial word is: rare
John, what is the next word? bare
Bill, what is the next word? care
John, what is the next word? mares
Not a valid dictionary word. Try again: mare
Bill, what is the next word? bare
Word already used. Try again: dare
John, what is the next word? dares
Not a valid dictionary word. Try again: dire
Bill, what is the next word? dime
John, what is the next word? mime
Not a valid dictionary word. Try again: dame
Bill, what is the next word? famous
Not a correct wordiff. Try again: fame</pre>
=={{header|Julia}}==
|