Coding challenge #1

Soldato
Joined
28 Oct 2006
Posts
12,456
Location
Sufferlandria
Will find some good challenges and create some threads this evening or tomorrow when I get time

Looks like @Steedie hasn't had time yet, so i'll kick it off whilst I have both time and an idea:

I want to build a contraption for cutting screw threads into wood dowels. The cutting head is moved along the workpiece on a 1.25mm pitch (pitch = distance between threads) threaded rod. If I want to cut a 1.25mm pitch thread into the wood, I need to rotate the wood dowel and the threaded rod together at a 1:1 ratio.
If I want to cut other thread pitches into the wood, i'll need some cogs to rotate the parts at different speeds.

If i want a 2.5mm pitch thread in the wood, the threaded rod needs to rotate at twice the speed that the wood dowel is rotating at. This means I'd use something like an 11tooth cog meshing with a 22tooth cog to give the correct gear ratio.

So, I want some code which can take in a thread pitch (in mm) and output a corresponding set of cogs which will give me the desired ratio.

Some rules:
Obviously, cogs can only have integer numbers of teeth.
2.5% variation is acceptable for the ratio.
Max cog size is 100teeth, min is 9 - if no combination of integer numbered cogs within that range can produce the required ratio, output an error.
It's preferable but not essential to have an odd number of total teeth between the 2 cogs (my example of 11 and 22 teeth cogs give a total of 33 teeth, which is better than using 10 and 20 cogs which would have given the same ratio)

edit: added minimum cog size
 
Last edited:
Soldato
OP
Joined
28 Oct 2006
Posts
12,456
Location
Sufferlandria
Is 1.25mm the minimum pitch size? (i.e. is the first cog always going to have the same teeth or less than the second cog)
Yes. In this scenario, the first cog will always have equal or less than the second.

Do you want the result to be a single pair of cogs, or all pairs of cogs which could be used?
Is there any preference, other than an odd number of teeth, of which pair to return on a multiple match? E.g. your example of a 1:2 ratio could be 9:18, 10:20, 11:22, 12:24 etc. Would you want the first, smallest, odd teethed pair to match?

If there are multiple different combinations of cogs which would all result in exactly the same ratio, you could either output all combinations or select one to output - your choice.

If there is a pair which is not exact but within the 2.5% variation, but a larger pair which is exact, would you like back the smaller inexact pair or the most accurate? If the inexact pair has odd teeth, and the exact has even teeth, which would be preferred?
Ratio is most important so the closest cog combination to the ratio would be best.


My order of preference would be:
1. Ratio. Accurate cutting is the most important requirement.
2. Odd number of teeth (with an even number of teeth, it means that there can be a pattern where same individual teeth on the 2 cogs always interface with each other and causes increased wear)
3. Favour smaller toothed cogs. Smaller cogs are more likely to fit into multiple different combinations with different ratios so I can change the gearing without having to buy as many cogs.
 
Soldato
OP
Joined
28 Oct 2006
Posts
12,456
Location
Sufferlandria
Interesting challenge. I'm not a developer so won't be attempting this

Here's an alternative which is a bit simpler but still requires some thought and a bit of programming knowledge:

Use the same scenario as above and for every possible cog combination (between 9 and 100 teeth on first cog, also between 9-100 teeth on second cog) calculate the ratio and display the combination on screen if it's within 2.5% of the desired ratio.


And here's a more complex version for those who need more of a challenge:
Again, use the same scenario as above but if a solution can't be found from the combination of 2 cogs, add another cog in between to get a solution. This could be a single cog which interfaces with both original cogs or something like the picture below which has a different number of teeth on the input and output:
SjJf8DS.jpg
Dont worry about rotational direction when adding extra cogs into the system.
 
Soldato
OP
Joined
28 Oct 2006
Posts
12,456
Location
Sufferlandria
I didn't entirely understand this when I first looked it over, I think all the pitch and cogs talk threw me, but a second look and I think I get it.
To simplify it without the backstory:

The ratio required is X:1.25 where X is input by the user.
You need to replicate this ratio by using only integer numbers.
So it's quite a simple calculation: [integer1] = [integer2]*(x/1.25)
The difficult part will be finding numbers which fit into the calculation (or within 2.5% if no exact matches)
 
Soldato
OP
Joined
28 Oct 2006
Posts
12,456
Location
Sufferlandria
Adding to the rules:
the smallest ratio required will be 1.25:1.25
the largest ratio will be 12.7:1.25

You can round the user input value to 2 decimal places.
 
Soldato
OP
Joined
28 Oct 2006
Posts
12,456
Location
Sufferlandria
Yeah, I know, now it's been done though, I've lost the urge! I've gone back to my own coding. :)

OK then, here's AndyCr15's personal challenge!
Choose 1 of:

1- Solve the problem in OP using a different language

2- Solve the problem in OP without use of loops.
Maybe recursive functions?

3- Calculate ratios of all possible cog combinations and store them somewhere (database?) and use that to return a matching ratio to the user's request.
 
Last edited:
Back
Top Bottom