Bulls and cows: Difference between revisions
Content added Content deleted
(→{{header|Groovy}}: Added Groovy) |
|||
Line 3,975: | Line 3,975: | ||
</pre> |
</pre> |
||
=={{header|Mathematica}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
⚫ | |||
<lang Mathematica> |
|||
⚫ | |||
codes=ToCharacterCode[StringJoin[ToString/@digits]]; |
codes=ToCharacterCode[StringJoin[ToString/@digits]]; |
||
Module[{r,bulls,cows}, |
Module[{r,bulls,cows}, |
||
Line 3,988: | Line 3,987: | ||
bulls=Count[userCodes-codes,0];cows=Length@Intersection[codes,userCodes]-bulls; |
bulls=Count[userCodes-codes,0];cows=Length@Intersection[codes,userCodes]-bulls; |
||
Print[r<>": "<>ToString[bulls]<>"bull(s), "<>ToString@cows<>"cow(s)."], |
Print[r<>": "<>ToString[bulls]<>"bull(s), "<>ToString@cows<>"cow(s)."], |
||
Print["Guess four digits."]]]]]]] |
Print["Guess four digits."]]]]]]]</lang> |
||
</lang> |
|||
Output: |
Output: |
||
<pre> |
<pre>{8, 2, 6, 1} |
||
{8, 2, 6, 1} |
|||
3432: 0 bull(s), 1 cow(s). |
3432: 0 bull(s), 1 cow(s). |
||
Illegal input. |
Illegal input. |
||
8261: You got it! |
8261: You got it!</pre> |
||
</pre> |
|||
=={{header|MATLAB}}== |
=={{header|MATLAB}}== |