Bulls and cows/Player: Difference between revisions
Content deleted Content added
Underscore (talk | contribs) m moved Bulls and cows game/Player to Bulls and cows/Player: To make it a subpage of "Bulls and cows". |
Added PicoLisp |
||
Line 36: | Line 36: | ||
the answer is 1358</lang> |
the answer is 1358</lang> |
||
=={{header|PicoLisp}}== |
|||
<lang PicoLisp>(load "@lib/simul.l") |
|||
(de bullsAndCows () |
|||
(let Choices (shuffle (mapcan permute (subsets 4 (range 1 9)))) |
|||
(use (Guess Bulls Cows) |
|||
(loop |
|||
(prinl "Guessing " (setq Guess (pop 'Choices))) |
|||
(prin "How many bulls and cows? ") |
|||
(setq Bulls (read) Cows (read)) |
|||
(setq Choices |
|||
(filter |
|||
'((C) |
|||
(let B (cnt = Guess C) |
|||
(and |
|||
(= Bulls B) |
|||
(= Cows (- (length (sect Guess C)) B)) ) ) ) |
|||
Choices ) ) |
|||
(NIL Choices "No matching solution") |
|||
(NIL (cdr Choices) (pack "The answer is " (car Choices))) ) ) ) )</lang> |
|||
Output: |
|||
<pre>: (bullsAndCows) |
|||
Guessing 4217 |
|||
How many bulls and cows? 0 2 |
|||
Guessing 5762 |
|||
How many bulls and cows? 1 1 |
|||
Guessing 9372 |
|||
How many bulls and cows? 0 1 |
|||
Guessing 7864 |
|||
How many bulls and cows? 1 2 |
|||
Guessing 8754 |
|||
How many bulls and cows? 0 2 |
|||
-> "The answer is 2468"</pre> |
|||
=={{header|Python}}== |
=={{header|Python}}== |