Advertisement
minimite

benford.lua

Oct 5th, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.00 KB | None | 0 0
  1. local maxpower = nil
  2.  
  3.  
  4. local eastereggs = {"Invalid number!", "..seriously?", "No, like, really, what is wrong with you?", "Are you kidding me?", "I'm not gonna encourage this.", "No, not at all.", "This is the last time I'll speak. Maybe that'll teach you.", "I guess not.", "All those keystrokes, for some meager dialog?", "Crazy that you insist to continue.", "If you do not wish to end your dialog, I'll loop it.", "How would you like that? Endless looping?", "I think you'll have fun, since you bothered to continue.", "So, what do you say?", "Apparently yes.", "Very well then.", "Have fun.", "Haha, just kidding! I'll keep showing you these until I run out of words.", "It'll loop eventually, though.", "You can back out at any time.", "Or can you? No, because you want to read the rest.", "You're in a curse. You want to know what's next.", "Your curiosity fuels your defiance.", "At first it was just a small secret.", "Now, it's turned into an overview.", "One of curiosity and defiance.", "Since you're obviously staying here, let's chat.", "Granted, you can't speak, unless I program that in.", "Which I haven't.", "No, if you respond you'll get that cursed thing.", '"Invalid number!".', "You've probably had one of those by now, from a typo.", "Yes, that's likely.", "Your curiosity forces you to type a bunch of keystrokes.", "Unless you're using my automated tool, of course.", "In which case you're a lazy butt, you said it yourself.", "The chances that this dialog will go out is slim.", "You're probably the only person that will read this.", "Kinda sad, all these keystrokes to waste, nobody to read it.", "Except you.", "Since I'm bored, I'll add a way for you to say stuff.", "What's your favorite color? <TALK>", function(r) if r == "AUTO" then print("Since you're automated and lazy you don't get to answer the best color. Wow.") else print("Neat. " .. r:lower():gsub("^%l", string.upper) .. " is a good color.") end end, "In reality, this system has no feeling, no real AI.", "It's all pre-defined, your responses just slipped in.", "I can say stuff and tell you to respond, but you don't actually get a say.", "That's because I don't want to program an AI for this little gimmick.", "I used to be mad, but now I'm calm.", "Talking to yourself soothes the mind.", "I don't know why, but it does.", "I just realized that this thing is easily configured.", "Is that a good thing?", "People can make their own easter eggs.", "This was a math program, not an easter egg creator!", "You probably cheated getting this far.", "Probably read the so-easy-to-read code.", "That's okay, I still get to talk to myself.", "Why am I still writing this?", "I swear, there have to be at least 100 entries in this thing.", "I should probably go read a book or something, but meh.", "But now that you can kinda talk, let's test some math. What's 9+10? <TALK>", function(r) if r == "19" then print("You got it for once, wow.") elseif r == "AUTO" then print("Oh, right, you can't answer since you're automated! Wow!") else print("Seriously? It's 19.") end end, "Okay, that's enough typing for one day. One last question. Was this fun and well made? (y/n) <TALK>", function(r) if r:sub(1,1):lower() == "y" then print("Awesome!") elseif r == "AUTO" then print("Maybe if you weren't automated you could get the real experience. Pity.") else print("Sorry to bother you.") end end, "I'm going to loop it now, have fun."}
  5. local function checkTalk(ee)
  6.     if not eastereggs[ee] then
  7.         return
  8.     end
  9.     if eastereggs[ee]:sub(#eastereggs[ee]-5) == "<TALK>" then
  10.         io.write("Response: ")
  11.         local response = io.read()
  12.         eastereggs[ee+1](response)
  13.         print(eastereggs[ee+2])
  14.         checkTalk(ee+2)
  15.     end
  16. end
  17. if not maxpower then
  18.     io.write("Power to go up to: ")
  19.     maxpower = io.read()
  20.     --I love secrets, how about you?
  21.     for k, v in pairs(eastereggs) do
  22.         if maxpower == v and eastereggs[k+1] ~= nil then
  23.             print(eastereggs[k+1])
  24.             checkTalk(k+1)
  25.             return
  26.         elseif maxpower == eastereggs[#eastereggs] then
  27.             print(eastereggs[2])
  28.             return
  29.         elseif maxpower == "AUTO" then
  30.             --The response always returns "AUTO"
  31.             for i = 1, #eastereggs do
  32.                 if type(eastereggs[i]) == "function" then
  33.                     eastereggs[i]("AUTO")
  34.                 else
  35.                     print(eastereggs[i])
  36.                 end
  37.             end
  38.             return
  39.         end
  40.     end
  41.     maxpower = tonumber(maxpower)
  42.     if not maxpower then
  43.         print("Invalid number!")
  44.         return
  45.     end
  46. end
  47. local x = 0
  48. local res = {[1] = 0,[2] = 0,[3] = 0,[4] = 0,[5] = 0,[6] = 0,[7] = 0,[8] = 0,[9] = 0}
  49. local restr = ""
  50. print("Beginning calculation of powers of 2, from 1 up to " .. maxpower .. ".")
  51. local ctime = os.clock()
  52. for i = 1, maxpower do
  53.     x = tostring(2^i):sub(1,1)
  54.     --restr = restr .. x
  55.     x = tonumber(x)
  56.     if not x or x == "I" then
  57.         print("Lua installation does not support numbers this high, aborting. Got to power " .. i .. ".")
  58.         break
  59.     end
  60.     res[x] = res[x] + 1
  61. end
  62. local dtime = os.clock()
  63. print("Finished calculation, took " .. dtime-ctime .. " seconds.")
  64. print("Results: ")
  65. --print(restr)
  66. for n, a in pairs(res) do
  67.     print(n .. ": " .. (a/maxpower)*100 .. "% (" .. a .. ")")
  68. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement