Skip to content

Instantly share code, notes, and snippets.

@HollyGurza
Last active December 27, 2015 03: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 HollyGurza/7261085 to your computer and use it in GitHub Desktop.
Save HollyGurza/7261085 to your computer and use it in GitHub Desktop.
walls = [2,3,4,0,1,3,1,5,4,3,4,0,1,2,0,1,0,2,0,4]
lmax=0;
total=0;
copen=0;
buff=0;
print "\n-----------BEGIN ALG-----------\n"
if walls[0]>walls[1]:
lmax=walls[0];
copen=1;
for i in range(1, len(walls)):
if walls[i]<walls[i-1]:
copen=1;
buff=buff+(lmax-walls[i]);
else:
if walls[i]<lmax:
buff=buff+(lmax-walls[i]);
buff=buff-(copen*(walls[i]-walls[i-1]));
total=total+(copen*(walls[i]-walls[i-1]));
copen=copen+1;
else:
total=total+buff;
buff=0;
copen=1;
lmax=walls[i];
print "step "+str(i)+": total = " +str(total) + " buff = " +str(buff);
print "\nTOTAL = "+str(total);
print "\n-----------END ALG-----------\n"
@chrisdone
Copy link

walls = [2,5,1,2,3,4,7,7,6] → 10
walls = [6,7,7,4,3,2,1,5,2] → 4

Another broken algorithm that depends on order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment