Skip to content

Instantly share code, notes, and snippets.

@ClarkAlmazan
Last active October 18, 2017 17:39
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 ClarkAlmazan/385e9a90975616769dcc10af3a8f0fee to your computer and use it in GitHub Desktop.
Save ClarkAlmazan/385e9a90975616769dcc10af3a8f0fee to your computer and use it in GitHub Desktop.
I don't get what kind of parameters are to be used in the Coderbyte exercise, but I "think" I managed to solve the actual problem anyways. So here's a Scale Balancing function that accepts a list containing two lists. The first list contains the two weights of the scales, while the second list holds the available weights to use. Sample input for…
def ScaleBalancing(strArr):
# code goes here
balance = int(strArr[0][0]) - int(strArr[0][1]) #if negative, right is heavier, else left is heavier
weights = []
need = 1
for i in strArr[1]: #see if one weight can fix the imbalance
if abs(balance)-int(i)==0:
weights.append(i)
return weights
for i in range(0, len(strArr[1])): #else look for a combination of two different weights that can fix the imbalance
for j in range(i+1, len(strArr[1])):
if abs(balance)-int(strArr[1][i])-int(strArr[1][j])==0:
weights.append(strArr[1][i])
weights.append(strArr[1][j])
return weights
return "not possible" #otherwise declare problem is impossible to solve
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment