Python question
Jan. 22nd, 2016 05:43 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
I am playing with code to learn Python moar, because I really learn better by using stuff than by trying to memorize abstract things, and even moar when it feels useful.
So yes.
It is going well except I'm trying to do a Thing which feels like it should feel simple except maybe I don't know the search term for what it's called or maybe in actual programming it's not simple? So I thought I'd ask the hive mind here and then if no luck maybe move on to Python forums hivemind or something.
Basically I am making a program that automates making a hat recipe, because I know a lot of math-phobic people who don't make up their own hat patterns because math.
I have a lot of the input features programmed and if/then boolean type stuff.
My conundrum is, I am looking for some sort of thing that goes something like:
here are several possible number of stitches to cast on; they work with a given pattern repeat, gauge, and head size (that coding is already done)
here are several integers (7, 8. 9, 10, 11, 12, let's say)
which of those integers go into the stitch totals with a remainder of zero?
give me those integers-cast on combos, that will be your choice of decreases-cast on pattern combos
(then I can insert it into a pre-scripted pattern text which is on Ravelry or something)
I've been looking at sets and conditional statements and lists and I started to look at regular expressions but by then my brain had hit "no more concentration for you tonight, also you keep snapping at people who interrupt your train of thought." so yup.
any feedback appreciated!
So yes.
It is going well except I'm trying to do a Thing which feels like it should feel simple except maybe I don't know the search term for what it's called or maybe in actual programming it's not simple? So I thought I'd ask the hive mind here and then if no luck maybe move on to Python forums hivemind or something.
Basically I am making a program that automates making a hat recipe, because I know a lot of math-phobic people who don't make up their own hat patterns because math.
I have a lot of the input features programmed and if/then boolean type stuff.
My conundrum is, I am looking for some sort of thing that goes something like:
here are several possible number of stitches to cast on; they work with a given pattern repeat, gauge, and head size (that coding is already done)
here are several integers (7, 8. 9, 10, 11, 12, let's say)
which of those integers go into the stitch totals with a remainder of zero?
give me those integers-cast on combos, that will be your choice of decreases-cast on pattern combos
(then I can insert it into a pre-scripted pattern text which is on Ravelry or something)
I've been looking at sets and conditional statements and lists and I started to look at regular expressions but by then my brain had hit "no more concentration for you tonight, also you keep snapping at people who interrupt your train of thought." so yup.
any feedback appreciated!
no subject
Date: 2016-01-22 10:57 pm (UTC)no subject
Date: 2016-01-22 10:59 pm (UTC)no subject
Date: 2016-01-22 11:00 pm (UTC)So 4 % 2, for example, will return a result of 0, because 4 / 2 has a remainder of 0.
Thus you'll want something that looks like (in terrible psuedocode, because it's ages since I did any Python):
for int in range(7,12):
if int % stitch-total == 0:
[ whatever you want to do with it here ]
I can't remember exactly how Python does for-loops, so like I said, horrible psuedocode...
Let me know if that wasn't clear enough? I have a bit of brain fog going on, sorry.
no subject
Date: 2016-01-23 04:12 am (UTC)no subject
Date: 2016-01-23 02:55 pm (UTC)I would probably code it as two loops, but there's probably a way to smash it together into one statement.
for total in stitch_total:
for integer in MODULO_INTEGERS:
if total % integer == 0:
working_combinations.push(total)
end
end
end