Skip to content

Instantly share code, notes, and snippets.

@zonble
Created August 31, 2011 16:23
Show Gist options
  • Select an option

  • Save zonble/1183940 to your computer and use it in GitHub Desktop.

Select an option

Save zonble/1183940 to your computer and use it in GitHub Desktop.
寫好玩的
import math
def solve(x):
left = []; right = []; nums = [1]; i = 0
while x > sum(nums): i += 1; nums.append(3 ** i)
for num in nums:
r = int(math.ceil(float(x - sum(nums[:nums.index(num)])) / num)) % 3
if r == 1: left.append(num)
elif r == 2: right.append(num)
return sorted(left), sorted(right)
for i in range(0, 101):
print '%d -> %s' % (i, str(solve(i)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment