Bulls and cows: Difference between revisions
Content added Content deleted
Line 6,624: | Line 6,624: | ||
main</lang> |
main</lang> |
||
=={{header|Transd}}== |
|||
{{trans|C++}} |
|||
<lang scheme> |
|||
#lang transd |
|||
MainModule: { |
|||
contains-duplicates: (λ s String() -> Bool() |
|||
(with str String(s) (sort str) |
|||
(ret (neq (find-adjacent str) (end str)))) |
|||
), |
|||
play: (λ |
|||
syms "0123456789" |
|||
len 4 |
|||
thenum String() |
|||
guess String() |
|||
(shuffle syms) |
|||
(= thenum (substr syms 0 len)) |
|||
(textout "Your guess: ") |
|||
(while (getline guess) |
|||
(if (eq guess "q") break) |
|||
(if (or (neq (size guess) len) |
|||
(neq (find-first-not-of guess syms) -1) |
|||
(contains-duplicates guess)) |
|||
(lout guess " is not valid guess") |
|||
(textout "Your guess: ") |
|||
continue |
|||
) |
|||
(with bulls 0 cows 0 pl 0 |
|||
(for i in Range(len) do |
|||
(= pl (find thenum (subn guess i))) |
|||
(if (eq pl i) (+= bulls 1) |
|||
elsif (neq pl -1) (+= cows 1)) |
|||
) |
|||
(lout "bulls: " bulls ", cows: " cows) |
|||
(if (eq bulls len) |
|||
(lout "Congratulations! You have found out the number!") |
|||
(ret null) |
|||
else (textout "Your guess: ")) |
|||
) |
|||
) |
|||
(lout "You quit the game.") |
|||
), |
|||
_start: (λ s String() |
|||
(lout "Welcome to \"Bulls and cows\"!") |
|||
(while true |
|||
(while true |
|||
(textout "Do you want to play? (yes|no) : ") |
|||
(textin s 3) |
|||
(if (not (size s)) |
|||
(lout "Didn't receive an answer. Exiting.") (exit) |
|||
elsif (== (sub (tolower s) 0 1) "n") (lout "Bye!")(exit) |
|||
elsif (== (sub (tolower s) 0 1) "y") break |
|||
else (lout "(Hint: \"yes\" or \"no\".)")) |
|||
) |
|||
(play) |
|||
(lout "Another game?") |
|||
) |
|||
) |
|||
} |
|||
</lang> |
|||
=={{header|TUSCRIPT}}== |
=={{header|TUSCRIPT}}== |