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

No errors, But something is wrong?

Started by AndreWalia, 17 November 2012 - 03:56 PM
AndreWalia #1
Posted 17 November 2012 - 04:56 PM
for some reason i feel like making a script that prints rly big numbers, so far i got;



nothing = 1
googolplex = 1
googolVal = 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
googol = 1
function getValues()
zero = 0
for i = 1,100 do
  nothing = nothing + 1
  googol = ""..googol..""..zero..""
end
for x = 1,googolVal do
  googolplex = ""..googolplex.."0"
end
end
function enterToContinue()
print("Press Enter to continue...")
i = io.read()
end
getValues()
start = 1
print("Say googol to see googol,  say googolplex to see googolplex.")
print("Warning, May blow up")
awnser = io.read()
if awnser == "googolplex" then
print("WARNING LARGE NUMBER WOULD YOU LIKE TO CONTINUE?? y/n")
awnser2 = io.read()
if awnser2 == "y" then
  print(googolplex)
  enterToContinue()
end
end
if awnser == "googol" then
print(googol)
enterToContinue()
end
Gogol was working fine before i added Gogolplex but now when i run it nothing happens for a few seconds then it says too long withought yeilding. Lol, is gogolplex just to big for it to print?? pls reply
EDIT: the reason im not letting lua print googolval is becuz it says 100x10 or something scientificy
kazagistar #2
Posted 17 November 2012 - 05:34 PM

googolVal = 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
for x = 1,googolVal do
How many times do you think that loop will run? This has nothing to do with printing. The problem is that the computer can do somewhere between a few million and a few billion operations per second, so finishing this will take approximately forever.
AfterLifeLochie #3
Posted 17 November 2012 - 05:36 PM
Gogol was working fine before i added Gogolplex but now when i run it nothing happens for a few seconds then it says too long withought yeilding. Lol, is gogolplex just to big for it to print?? pls reply
EDIT: the reason im not letting lua print googolval is becuz it says 100x10 or something scientificy
The "Too long without yielding" indicates your program hasn't called a function which causes ComputerCraft to go and yield to collect events, possibly because it's tied up joining together obscenely large numbers. Programs that don't yield in order to collect events get terminated by ComputerCraft automatically.
Kingdaro #4
Posted 17 November 2012 - 05:38 PM
The magnitude of googolplex doesn't make simply printing it possible.

Unless you were to put a sleep() in your loop, but, as kazagi said, it would take ages.

A tip, though, you can produce repeated sequences of numbers with string.rep(). So if I wanted a string of 100 zeroes, I could do

local hundredZeroes = 1 .. string.rep('0', 100)
GopherAtl #5
Posted 17 November 2012 - 05:43 PM
lets do some math here. A googol is 10^100. You loop from 1 to googol. If each pass through the loop takes 1 instruction, that's 10^100 instructions. It will take more than 1, of course, but we'll assume 1. If your computer's processor runs at 10ghz - which it almost certainly doesn't, but again, lets assume - that means, rounding down, 10^10 instructions per second. based on these very generous assumptions, your computer would take 10^90 seconds to run this loop. That's more than 10^88 minutes, which is more than 10^86 hours, which is a lot more than 10^87 days, which is a lot more than 10^85 years. That'd be 10^69 times the current age of the universe.

Basically, what I'm saying is, you're gonna want to take a coffee break while that loop runs.
immibis #6
Posted 17 November 2012 - 06:41 PM
This program does the same thing and doesn't crash: (and is indented)

print("Say googol to see googol,  say googolplex to see googolplex.")
print("Warning, May blow up")
awnser = io.read()
if awnser == "googolplex" then
 print("WARNING LARGE NUMBER WOULD YOU LIKE TO CONTINUE?? y/n")
 if io.read() == "y" then
  local width, height = term.getSize()
  for k=1,height do
   term.setCursorPos(1, k)
   term.write(string.rep("0", width))
  end
  while true do
   sleep(10000)
  end
 end
end
if awnser == "googol" then
 print("1" .. string.rep("0", 100))
 print("Press Enter to continue...")
 io.read()
end
AndreWalia #7
Posted 18 November 2012 - 05:19 AM
lets do some math here. A googol is 10^100. You loop from 1 to googol. If each pass through the loop takes 1 instruction, that's 10^100 instructions. It will take more than 1, of course, but we'll assume 1. If your computer's processor runs at 10ghz - which it almost certainly doesn't, but again, lets assume - that means, rounding down, 10^10 instructions per second. based on these very generous assumptions, your computer would take 10^90 seconds to run this loop. That's more than 10^88 minutes, which is more than 10^86 hours, which is a lot more than 10^87 days, which is a lot more than 10^85 years. That'd be 10^69 times the current age of the universe.

Basically, what I'm saying is, you're gonna want to take a coffee break while that loop runs.

Damn