120 posts
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
8543 posts
Posted 20 March 2014 - 12:19 AM
Moved to Ask a Pro.
120 posts
Posted 20 March 2014 - 12:23 AM
It didn't need to be moved.. xD
I forgot to add Known Bugs..
7508 posts
Location
Australia
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!")
8543 posts
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!")
120 posts
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..
8543 posts
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.