I think I've got it down thanks to Hydroxide.
My record for running this program is 1000. See what you can get without altering the code. :p
import random
class Range(object):
def __init__(self, txt, end):
self.txt = txt-1
self.end = end
self.count = 0
def add(self):
self.txt += 1
self.count += 1
def kill_digit(self):
self.txt = int(str(self.txt)[1:])
def add_digit(self):
self.txt = int(str(random.randrange(0,10))+str(self.txt))
def randomize(self):
self.txt += random.randrange(0, 10)
def run(self):
while series.txt != series.end:
self.add()
if self.txt > 991:
self.kill_digit()
elif self.txt < 100:
self.add_digit()
else:
self.randomize()
series = Range(1, 1000) ; series.run()
print "Took", series.count, "tries to get to", "%s%s"%(series.txt,".")
I modified it to loop through and return the least amount of tries it needed to do: 8. :eek:
import random
class Range(object):
def __init__(self, txt, end):
self.txt = txt-1
self.end = end
self.count = 0
def add(self):
self.txt += 1
self.count += 1
def kill_digit(self):
self.txt = int(str(self.txt)[1:])
def add_digit(self):
self.txt = int(str(random.randrange(0,10))+str(self.txt))
def randomize(self):
self.txt += random.randrange(0, 10)
def run(self):
while series.txt != series.end:
self.add()
if self.txt > 991:
self.kill_digit()
elif self.txt < 100:
self.add_digit()
else:
self.randomize()
x=[]
for a in range(100):
series = Range(1, 1000) ; series.run()
x.append(series.count)
smallest = 9999999
biggest = 0
for a in range(len(x)):
if x[a] < smallest: smallest = x[a]
if x[a] > biggest : biggest = x[a]
print "%d and %d are the smallest and biggest amount of triest to get to %s."%(smallest, biggest, series.txt)