I am given my C class homework, which is:
A hyperloop track is built of individual pipe segments of certain length. The track starts and ends with a bulkhead, and there is a bulkhead in-between each two pipe segments. The segments are produced by two different manufacturers(s1 and s2). Lengths of the segments(s1,s2), bulkheads(b), and of the desired track(l) are given. The task is to develop a function that will, based on these 4 parameters, decide whether there are valid combinations of segments and bulkheads that will result in the exact length of the desired track, and, if there are, output the number of these combinations.
Note: two different segments may be equal in their lengths, the length of a bulkhead may also be equal to zero.
My opinion is that I should solve a linear equation with 3 variables:
(m)*s1 + (n)*s2 + (m+n+1)*b = l
But I have no idea which method I should use to write an efficient code.
Equation provides criteria for finding combinations. When writing c code for this, it will only require iterating for m and n and checking if it meets l length. Below is pseudo code that can provide combinations