Skip to content

Instantly share code, notes, and snippets.

@JonathanVeg
Created October 14, 2022 13:09
Show Gist options
  • Save JonathanVeg/8f01e80434fcd78d9aa27636c7ad277f to your computer and use it in GitHub Desktop.
Save JonathanVeg/8f01e80434fcd78d9aa27636c7ad277f to your computer and use it in GitHub Desktop.
import random
line = [ i for i in range(100)]
rabbit = random.choice(line)
hunter = 0
def printLine():
for i in range(len(line)):
if i == rabbit:
print(" R ", end="")
elif i == hunter:
print(" H ", end="")
else:
print(" _ ", end="")
print()
def is_rabbit_here(i): return i == rabbit
def move_rabbit():
global rabbit
rabbit = random.choice([rabbit-1, rabbit+1])
if rabbit < 0:
rabbit = 0
elif rabbit > len(line):
rabbit = len(line)
def move_hunter(i):
global hunter
hunter = i
places_to_look = [0, 1, 1, 2, 1, 2]
interactions = 0
while True:
interactions += 1
found = False
for i in places_to_look:
printLine()
if is_rabbit_here(i):
print("Rabit is here in the {} hole and it took {} interactions".format(i, interactions))
found = True
break
else:
# print("rabbit is not here it is at {} and I looked at {}".format(rabbit, i))
move_rabbit()
move_hunter(i)
if found:
break
places_to_look = [(i + 1)%len(line) for i in places_to_look ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment