OT: Brute force vs. coding
OT
I am looking for opinions and rationales on the following question: when designing a system that executes the same atomic operation over multiple values, at what size process would you choose to switch from a brute-force approach to an algorithmic approach? And the followup (or alternative) question is how and/or why and/or in what situations would you make that choice?
Thanks in advance for any response.
For example
If I was doing a one-off design then I might consider it straightforward to use brute force all the way up to 16 stations and beyond, and to make it easier for maintenance to debug down the line. But if I worked for a company that built, installed, and commissioned tripper conveyors, I might lean toward the algorithmic approach because I could then write the code with an integer containing number of stations stored in the program, and all I have to do for each installation is change that number to match the local process and
voila the code works at every installation with minimal effort beyond the I/O check.
Specific case - the current tripper conveyor
The code below shows two ways to transfer the raw inputs for this thread's process, which are in bits 0 to 3 of N7:0, into integer buffers. The top case does it in rung 0002 and writes either a zero if multiple bits are set, or the single-set-bit N7:0 value, to integer N7:10; the bottom case in rungs 0003 and 004 uses a loop and writes the same result to integer N7:20. I chose the GaryS-style inputs* for simplicity, but this question could apply to any input scheme**. With only four inputs, I would think the top method is preferred: it is certainly cleaner***.
At how many stations, or in what situation(s), does it make sense to switch to the bottom method. Or is the bottom case just too ugly and/or such a maintenance headache that it is better to assign the coding of the brute force method to next summer's low-wage intern?
* N7:0 = 1/2/4/8 for stations 1/2/3/4, respectively, i.e. exactly 1 bit on, and the other three bits off, when the cart is at each station; all bits off when the cart is between (or beyond) stations.
** E.g. if the environment was so dusty or noisy that single-bit errors were not rare in between stations, then a system where two bits give the position, plus a parity bit, plus an at-station bit, could be implemented to make a more
*** not that I think I wrote the cleanest looping construct, but for the sake of argument assume I had.