Jump to content




Game - LuckyLaunch



  • You cannot reply to this topic
6 replies to this topic

#1 Lua.is.the.best

  • Members
  • 76 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 by Lua.is.the.best, 20 March 2014 - 12:24 AM.


#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 20 March 2014 - 12:19 AM

Moved to Ask a Pro.

#3 Lua.is.the.best

  • Members
  • 76 posts

Posted 20 March 2014 - 12:23 AM

It didn't need to be moved.. xD
I forgot to add Known Bugs..

#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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!")


#5 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 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!")


#6 Lua.is.the.best

  • Members
  • 76 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!

View PostLyqyd, on 20 March 2014 - 12:38 AM, said:

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..

#7 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 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.





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users