Increase Over Row

My least favorite part of making a bottom-up sweater is when I get to the end of the ribbing and the instructions say, “Increase X number of stitches evenly across the row.” How many stitches do I put in between the increase stitches?! Much as I love knitting, I am not a whiz at math. Luckily, Debbie Stoller provides the arithmetic in Stitch ’n Bitch. The math works as follows.

  • Add 1 to the number of stitches you are supposed to increase
  • Divide the stitches on your needle by that number

Example

  • I have 10 stitches on my needle
  • The instructions read, “Increase by 4 stitches distributed evenly over the row.”
  • Add 1 to 4. The result is 5.
  • Divide 10 by 5. The result is 2.
  • (Work 2 stitches, inc 1) 4 times, work 2 stitches
Picture of stitches

The result of increasing 4 stitches distributed evenly over a row of 10 stitches

However, sometimes I cannot do even that simple math. Or I forget the formula. Or the result isn’t an even number. What’s a knitter to do?! I decided to build this little app to solve the problem.




Note: The plus sign indicates the increase stitch.

My deep gratitude goes to G, who helped me figure out how to do this. Thank you, G!

{ 6 comments… add one }

  • G January 8, 2013 at 2:50 pm

    Please don’t forget to accept an answer (and maybe a upvote), someone worked 4 hours on that custom script for you 🙂

    edit
  • Janet January 8, 2013 at 3:50 pm

    Oh dear. I thought I did that–I clicked the button that said that the answer was helpful to me! I’ll go back and fix it by accepting the answer. I tried to upvote it, but I lost all my points on Stack Overflow with the switch in their login system. So I’m back to Student level (which is actually accurate for me anyhow!) Thank you very, very much for your help with the code. I’m deeply appreciative.

    edit
  • G January 8, 2013 at 3:01 pm

    PLEASE NOTE: I had a small error in the script: replaced “crr=0;” with “crr=0,” this has now been corrected in the jsfiddle and the code placed in my answer.

    edit
  • Janet January 8, 2013 at 3:50 pm

    Awesome. Thank you SO MUCH!

    edit
  • G January 9, 2013 at 1:12 am

    No problem, I enjoyed answering it! Or should I say, figuring out and solving the puzzle. If I’d known a distribution algorithm, then it would have taken me a lot less time, but I always like to crack things myself: then at least I understand them haha.

    Originally I wanted to understand your question and the more I understood (after reading this page) the more intrigued I was. I understood you essentially where looking for a distribution algorithm, but finding one proved harder than I thought: the few examples I could find where already tailored to a specific demand, so in order to understand them I then had to understand their specific purpose (and I didn’t feel like doing that).

    So then I decided to try and help to the question, saving others the time required to understand your question, so that in turn someone might provide with a answer that also explained the math behind it (so my curiosity would be satisfied to).

    In doing the –+– ‘truth table’-thing to visually explain it further, I wanted to place the + signs on the correct place (not making a fool out of myself haha).
    So I needed number sequences and whipped up a rudimentary script. When I saw the numbers I suddenly saw a pattern: If I round them and take the difference between them, then I had the output you needed. And I could simply place the – and + signs in the correct place for the clarification it all started with.

    And that’s how the answer was born.

    For your learning aid, I did another version jsfiddle.net/RrEd9/3/ making the code even smaller.
    The differences are: tmp did not need to be set; it is set every while loop (saves some characters). In javascript the function’s arguments are variables local to that function, so one using that you can save the var statement inside the function’s body. Of course, you could also use just one letter per variable name, and I incorporated that to.

    Then finally I went wild haha. If you have a modern browser that supports HTML 5 Canvas, you can even create a needle with stitches in javascript. See jsfiddle.net/RrEd9/5/ or fiddle.jshell.net/RrEd9/5/show/ to see it fullscreen (without the code).

    NOTE: in the last one, I filtered out possible zero’s, there is no point in having ‘5 + 0 + 4 +’ and so forth (for instance, rows 13, add 20) in the output. You might want to do that to.

    Enjoy!!

    edit
  • Janet January 9, 2013 at 9:44 am

    OMG! You are totally awesome. You took this to the exact place I planned to go with it, i.e.: a visual output of the stitches on the needle, and some thought on error catching for zeroes. Thank you a bazillion times.

    I spent yesterday evening puzzling through the first fiddle. Now I know what I’ll be doing this evening. You’ve have my undying gratitude!

    edit

Previous post: