Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
12
Task/Bulls-and-cows/Mathematica/bulls-and-cows.math
Normal file
12
Task/Bulls-and-cows/Mathematica/bulls-and-cows.math
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
digits=Last@FixedPointList[If[Length@Union@#==4,#,Table[Random[Integer,{1,9}],{4}]]&,{}]
|
||||
codes=ToCharacterCode[StringJoin[ToString/@digits]];
|
||||
Module[{r,bulls,cows},
|
||||
While[True,
|
||||
r=InputString[];
|
||||
If[r===$Canceled,Break[],
|
||||
With[{userCodes=ToCharacterCode@r},
|
||||
If[userCodes===codes,Print[r<>": You got it!"];Break[],
|
||||
If[Length@userCodes==Length@codes,
|
||||
bulls=Count[userCodes-codes,0];cows=Length@Intersection[codes,userCodes]-bulls;
|
||||
Print[r<>": "<>ToString[bulls]<>"bull(s), "<>ToString@cows<>"cow(s)."],
|
||||
Print["Guess four digits."]]]]]]]
|
||||
Loading…
Add table
Add a link
Reference in a new issue