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

GuessNumber

Started by NanoBob, 07 May 2013 - 09:46 AM
NanoBob #1
Posted 07 May 2013 - 11:46 AM
hey guys!

just a little program for you guys i made in 10 minutes.
you have to type in a maximum number, and you will have to guess a random number between 1 and the maximum.
you will be given tips like:"Higher" and "Lower".
ass you get it the program will tell you how many tries you had
to get it in game type:

pastebin get BkcuBCB8 Guessnumber
Now I have a special challenge, check the spoiler!

Challenge:
SpoilerUse the maximum number 2000000 (2 million)
and try and get it in least as possible tries.
then post a screenshot (in a spoiler) at this topic, I will make a top 10 leaderboard.
my best is 18 tries (won't put it in the leaderboard)

Code:
Spoiler



print[[
---------------------------------------------------
Welcome to Guess the number
---------------------------------------------------]]
print("")
print("You are going to have to type in a maximum number.")
print("You will have to guess the number between 1 and your input, it will say wheter you have to guess higher, or lower")
write("Maximum number : ")
z=0
p=read()
n=math.random(p)
print("Guess the number, it's between 1 and "..p)
repeat
  z=z+1
  k=tonumber(read())
  if k<n then
    print("Higher")
  elseif k>n then
    print("Lower")
  end
until  k==n
print("")
print("---------------------------------------------------")
print("You guessed the code!")
print("Your max number was: "..p)
write("And you did it in ")write(z)write(" attempts!")
print("---------------------------------------------------")

Pastebin link:
Spoilerhttp://pastebin.com/BkcuBCB8

Leaderboard:
Spoiler1.
2.
3.
4.
5.
6.
7.
8.
9.
10.

video:
Spoiler[media]http://www.youtube.com/watch?v=coGMuJuADqs&feature=youtu.be[/media]
Ichigo #2
Posted 08 May 2013 - 08:50 PM
How do i use the Pastebin get part if i use a reg or Adv computer It doesnt work do i need a special API or something?
Kingdaro #3
Posted 08 May 2013 - 10:32 PM
How do i use the Pastebin get part if i use a reg or Adv computer It doesnt work do i need a special API or something?
You need to enable the http API. http://computercraft.&#46;&#46;/wiki/HTTP_(API) (the bit in bold in the little box at the top)
NanoBob #4
Posted 09 May 2013 - 04:31 AM
Fixed some code , first it said higher even when you guessed the number
Ichigo #5
Posted 10 May 2013 - 10:24 PM
Here is my 1-2 million try https://www.facebook...&amp;type=1 58 Attempts