This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Lua.is.the.best's profile picture

Game - LuckyLaunch

Started by Lua.is.the.best, 19 March 2014 - 10:07 PM
Lua.is.the.best #1
Posted 19 March 2014 - 11:07 PM
LuckyLaunch is a program that is simple: Launch the program, and test your luck!
If you see Lucky, the C value in the 3rd line of the code is 12.
Create a program called "ll" and type this code in:

local random = math.random
A=random(1,2)+random(2,3)
B=random(3,4)+random(4,5)
C=A+B
if C==12 then print("Lucky!")
else print ("Unlucky!")
end
Edit 1: Bug fixed :P/> This can be moved back to Programs.
Edited on 19 March 2014 - 11:24 PM
Lyqyd #2
Posted 20 March 2014 - 12:19 AM
Moved to Ask a Pro.
Lua.is.the.best #3
Posted 20 March 2014 - 12:23 AM
It didn't need to be moved.. xD
I forgot to add Known Bugs..
theoriginalbit #4
Posted 20 March 2014 - 12:27 AM
why not just

if math.random(1,14) == 12 then
  print("Lucky!")
else
  print("Unlucky!")
end
or a one line version

print(math.random(1,14) == 12 and "Lucky!" or "Unlucky!")
Lyqyd #5
Posted 20 March 2014 - 12:38 AM
Actually, due to the addition operations, there are sixteen possible results for C, ranging from 10 to 14. 6 of those 16 are 12, so it would be a better match for the one-line solution to be:


print(math.random(1,16) <= 6 and "Lucky!" or "Unlucky!")
Lua.is.the.best #6
Posted 20 March 2014 - 01:48 AM
Looks like it has more bytes worth of saving then my 3-line way..
Anyways, I can still have all of that 3 lines of code on 1 line with it working!

Actually, due to the addition operations, there are sixteen possible results for C, ranging from 10 to 14. 6 of those 16 are 12, so it would be a better match for the one-line solution to be:


print(math.random(1,16) <= 6 and "Lucky!" or "Unlucky!")
That would do it for 6, 5, 4, 3, 2, 1.
Sorry if I am wrong but I dont know Lua that good..
Lyqyd #7
Posted 20 March 2014 - 02:25 AM
Yes, but it has the same probability of showing "Lucky!" as your code does; 6/16 times, or a 3 in 8 chance.