Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,69 @@
numCount = 4 -- number of digits to use
digits = #(1, 2, 3, 4, 5, 6, 7, 8, 9)
num = ""
while num.count < numCount and digits.count > 0 do
(
local r = random 1 digits.count
append num (digits[r] as string)
deleteitem digits r
)
digits = undefined
numGuesses = 0
inf = "Rules: \n1. Choose only % unique digits in any combination"+\
" (0 can't be used).\n2. Only positive integers are allowed."+\
"\n3. For each digit that is in it's place, you get a bull,\n"+\
"\tand for each digit that is not in it's place, you get a cow."+\
"\n4. The game is won when your number matches the number I chose."+\
"\n\nPress [esc] to quit the game.\n\n"
clearlistener()
format inf num.count
while not keyboard.escpressed do
(
local userVal = getkbvalue prompt:"\nEnter your number: "
if (userVal as string) == num do
(
format "\nCorrect! The number is %. It took you % moves.\n" num numGuesses
exit with OK
)
local bulls = 0
local cows = 0
local badInput = false
case of
(
(classof userVal != integer):
(
format "\nThe number must be a positive integer.\n"
badInput = true
)
((userVal as string).count != num.count):
(
format "\nThe number must have % digits.\n" num.count
badInput = true
)
((makeuniquearray (for i in 1 to (userVal as string).count \
collect (userVal as string)[i])).count != (userVal as string).count):
(
format "\nThe number can only have unique digits.\n"
badInput = true
)
)
if not badInput do
(
userVal = userVal as string
i = 1
while i <= userVal.count do
(
for j = 1 to num.count do
(
if userVal[i] == num[j] do
(
if i == j then bulls += 1 else cows += 1
)
)
i += 1
)
numGuesses += 1
format "\nBulls: % Cows: %\n" bulls cows
)
)

View file

@ -0,0 +1,20 @@
OK
Rules:
1. Choose only 4 unique digits in any combination (0 can't be used).
2. Only positive integers are allowed.
3. For each digit that is in it's place, you get a bull,
and for each digit that is not in it's place, you get a cow.
4. The game is won when your number matches the number I chose.
Press [esc] to quit the game.
OK
Enter your number: 2468
Bulls: 0 Cows: 2
Enter your number: 2448
The number can only have unique digits.
Enter your number: 1357
Bulls: 0 Cows: 1