Skip to content

Instantly share code, notes, and snippets.

@greenkey
Last active May 31, 2017 16:18
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 greenkey/9a81413351ee224a57434ab9a96723df to your computer and use it in GitHub Desktop.
Save greenkey/9a81413351ee224a57434ab9a96723df to your computer and use it in GitHub Desktop.
My solution for the Problem A of the qualification of 2017's edition of Google Code Jam: Oversized Pancake Flipper Raw
#! /usr/bin/env python
import sys
def solve(line):
if len(line) == 1:
return line
prev = "0"
for i, digit in enumerate(line):
if digit < prev:
left_part = str(int(line[:i])-1)
right_part = "9" * (len(line) - i)
return solve(left_part + right_part)
prev = digit
return int(line)
if __name__ == "__main__":
with file(sys.argv[1]) as f:
cases = int(f.readline())
for i in range(cases):
line = f.readline().strip()
print("Case #%d: %s" % (i+1, solve(line)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment