Skip to content

Instantly share code, notes, and snippets.

@APIUM
Last active March 2, 2017 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save APIUM/ca1fa9e5dbbccb2a99de26e85d1cbfd0 to your computer and use it in GitHub Desktop.
Save APIUM/ca1fa9e5dbbccb2a99de26e85d1cbfd0 to your computer and use it in GitHub Desktop.
dailyProgrammer 303 Easy
# Daily Programmer 303
hwv = input("Please enter h, w and v seperated by space > ").split(' ')
height,width,velocity = int(hwv[0]),int(hwv[1]),int(hwv[2])
position = [0,height]
moves = 0
bounces = 0
def start():
tick = time.clock()
global moves
moves += 1
position[0] += 1
position[1] -= 1
downright()
def downright():
global bounces
global moves
if wallCheck() == 1:
bounces += 1
upright()
elif wallCheck() == 2:
bounces += 1
downleft()
else:
position[0] += 1
position[1] -= 1
moves += 1
downright()
def upright():
global bounces
global moves
if wallCheck() == 2:
bounces += 1
upleft()
elif wallCheck == 3:
bounces += 1
downright()
else:
position[0] += 1
position[1] += 1
moves += 1
upright()
def upleft():
global bounces
global moves
if wallCheck() == 3:
bounces += 1
downleft()
elif wallCheck() == 0:
bounces += 1
upright()
else:
position[0] -= 1
position[1] += 1
moves += 1
upleft()
def downleft():
global bounces
global moves
if wallCheck() == 0:
bounces += 1
downright()
elif wallCheck() == 1:
bounces += 1
upleft()
else:
position[0] -= 1
position[1] -= 1
moves += 1
downleft()
def end():
print("END!")
print("Position: ",position)
print("Bounces: ", bounces)
print("Moves: ", moves)
print("Time: ",moves/velocity)
tok = time.clock()
print(tok-tik)
quit()
def wallCheck():
if position[0] == 0:
if position[1] == 0 or position[1] == height:
end()
else:
return 0
elif position[0] == width:
if position[1] == 0 or position[1] == height:
end()
else:
return 2
elif position[1] == 0:
if position[0] == 0 or position[0] == width:
end()
else:
return 1
elif position[1] == height:
if position[0] == 0 or position[0] == width:
end()
else:
return 3
start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment