Skip to content

Instantly share code, notes, and snippets.

@74togo
Created July 16, 2015 17:45
Show Gist options
  • Save 74togo/fca852e59d56ff3437ed to your computer and use it in GitHub Desktop.
Save 74togo/fca852e59d56ff3437ed to your computer and use it in GitHub Desktop.
Solution to weights problem
from math import log
def toList(num):
return toList(num // 3) + [["L"], ["-"], ["R"]][num % 3] if num else []
def solution(n):
return toList(n + sum(3**x for x in range(1 + int(log(n*2, 3)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment