Skip to content

Instantly share code, notes, and snippets.

@ashaindlin
Created July 26, 2017 08:30
Show Gist options
  • Save ashaindlin/17a2c45c2b3ed7c71d25696bb8568ec7 to your computer and use it in GitHub Desktop.
Save ashaindlin/17a2c45c2b3ed7c71d25696bb8568ec7 to your computer and use it in GitHub Desktop.
Calculate how far along you are in a knitting project, assuming linear rate of increases
#!/usr/bin/env python3
def calculate(castOn: int, bindOff: int, totalRows: int, curRow: int):
incPerRow = (bindOff - castOn)/totalRows; # stitches increased per row
totalStitches = sum([castOn + incPerRow*r for r in range(1, totalRows)])
stitchesKnit = sum([castOn + incPerRow*r for r in range(1, curRow)])
return int(100 * stitchesKnit / totalStitches)
if __name__ == "__main__":
c = int(input("Stitches cast on: "))
b = int(input("Final stitch count: "))
t = int(input("Total rows: "))
r = int(input("Current row: "))
print("You are roughly " + str(calculate(c, b, t, r)) + "% of the way done.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment