Nov-24-2023, 12:09 PM
Thinking some more about this, I came up with the ideas below, but I don't know if that is similar to what you are looking for??
Maybe this will give you some ideas on an approach. I was intrigued!
Maybe this will give you some ideas on an approach. I was intrigued!
import re import random # make a random numlist # numlist = [random.randint(1, 8) for i in range(151)] numlist = [random.randint(1, 4) for i in range(51)] total = sum(numlist) print(f"The sum of the numbers is {total}") if total % 8 == 0: print(f"We can make maximum {sum(numlist)/8} groups with a sum total of 8 from the numbers.") else: print(f"We can make maximum {int(sum(numlist)/8)} groups with a sum total of 8 and 1 smaller group from the numbers.") def count8(alist): num = 0 for i in range(len(alist)-1): num = num + alist[i] print('sum =', num) if num + alist[i+1] > 8: return (i, num, alist[0:i+1]) groups = [] while sum(numlist) > 8: group = count8(numlist) print('group:', group) groups.append(group[2]) numlist = numlist[group[0]+1:] for g in groups: print(g)But I am still not sure if that is what you are looking for??