Skip to content

Instantly share code, notes, and snippets.

@ryazwinski
Created November 23, 2010 14:59
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 ryazwinski/711879 to your computer and use it in GitHub Desktop.
Save ryazwinski/711879 to your computer and use it in GitHub Desktop.
weight_calc.py
def rcalc(w):
plates = [ 45, 35, 25, 10, 5, 2.5 ]
if w < plates[-1] * 2:
return (False, [])
for i in plates:
rem = w - (i * 2)
if rem > 0:
(ret, p) = rcalc(rem)
if not ret:
return(False, [])
p.append(i)
return (True, p)
elif rem == 0:
return (True, [i])
# should never bit hit, but for cleanliness
return(False, [])
def calc(w, bar=45):
r = w-bar
if r < 0:
return(False, [])
if r == 0:
return(True, [])
return(rcalc(r))
for i in xrange(0,300, 5):
(r, p) = calc(i)
if r:
p.sort(reverse=True)
print i, p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment