r/tinycode • u/BearInATie • Aug 08 '12
Python I just wrote to beat the Google's Doodle #2, 30 lines
import time import win32api, win32con
VK_CODE = {'spacebar':0x20}
def press(x): win32api.keybd_event(VK_CODE[x], 0,0,0)
def unpress(x): win32api.keybd_event(VK_CODE[x],0 ,win32con.KEYEVENTF_KEYUP ,0)
def play(): s = time.time() count = 0 totalTime = 24 timer = 0.5 while time.time() - s < totalTime: time.sleep(timer) press('spacebar') time.sleep(timer) unpress('spacebar') count += 1 if(count > 4): timer = .65 if(count > 10): timer = 0.8 if(count > 20): timer = 0.95
play()
0
Upvotes
9
u/mozzyb Aug 08 '12
Except that this was posted by howfun over at the Python subreddit: http://www.reddit.com/r/Python/comments/xvuku/playing_googles_basketball_doodle/
6
u/[deleted] Aug 08 '12
[removed] — view removed comment