So, for a bit I’ve been dicking around with making a function or program that will give you a buildup of gage blocks for a given size. I initially made one that gave a every solution for a given set of blocks but the dataset was HUGE, too big to even store properly especially with a 81pc gage block set. I had something in mind so I wrote a simple-ish function. It was a real mess, it worked but it was a mess. I put it through ChatGPT to simplify it and it’s way better than what I had. Here is the function (in Python).
def gage_blocks(blocks, buildup, maxResults):
blocks.sort(reverse=True)
def helper(remaining, current, result, start):
remaining = round(remaining, 4)
if remaining < 0 or len(result) >= maxResults:
return
elif remaining == 0:
result.append(current)
return
for i in range(start, len(blocks)):
block = blocks[i]
new_current = current[:]
new_current.append(block)
helper(remaining - block, new_current, result, i + 1)
result = []
helper(buildup, [], result, 0)
return result[:maxResults]
block = [0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 0.1001, 0.1002, 0.1003, 0.1004, 0.1005, 0.1006, 0.1007, 0.1008, 0.1009, 0.101, 0.102, 0.103, 0.104, 0.105, 0.106, 0.107, 0.108, 0.109, 0.11, 0.111, 0.112, 0.113, 0.114, 0.115, 0.116, 0.117, 0.118, 0.119, 0.12, 0.121, 0.122, 0.123, 0.124, 0.125, 0.126, 0.127, 0.128, 0.129, 0.13, 0.131, 0.132, 0.133, 0.134, 0.135, 0.136, 0.137, 0.138, 0.139, 0.14, 0.141, 0.142, 0.143, 0.144, 0.145, 0.146, 0.147, 0.148, 0.149, 1, 2, 3, 4]
print(gage_blocks(block, 1., 20))
As you can see, it includes the list of blocks for an 81 pc set. the function takes a list ‘block’, a value to achieve ‘buildup’, and finally maxResults which will limit the number of results. Limiting the results is imperative. If you don’t it’ll take forever on sizes beyond .6. Here is the output if you run the function above. Keep in mind it is using the blocks list, the value of 1.0 and it is limited to 20 results.
[[1], [0.95, 0.05], [0.9, 0.1], [0.85, 0.15], [0.85, 0.1, 0.05], [0.8, 0.2], [0.8, 0.15, 0.05], [0.75, 0.25], [0.75, 0.2, 0.05], [0.75, 0.15, 0.1], [0.75, 0.149, 0.101], [0.75, 0.148, 0.102], [0.75, 0.147, 0.103], [0.75, 0.146, 0.104], [0.75, 0.145, 0.105], [0.75, 0.144, 0.106], [0.75, 0.143, 0.107], [0.75, 0.142, 0.108], [0.75, 0.141, 0.109], [0.75, 0.14, 0.11]]
Seems to work well (I guarantee nothing!!!). Hopefully this works for people. Enjoy!