for n in range(1, 300): s = '0' * n + '1' * n while '00' in s: s = s.replace('01', '220', 1) s = s.replace('03', '120', 1) if s.count('1') == 13 and s.count('2') == 18: print(n) break Python for n in range(1, 300): s = '0' * n + '1' * n while '00' in s: s = s.replace('01', '220', 1) s = s.replace('03', '120', 1) if s.count('1') == 13 and s.count('2') == 18: print(n) break while накосячил :Р
так у тебя любые цифры могут быть а не только 1 --- Сообщение объединено с предыдущим 6 июн 2025 в 20:26 from itertools import product def process_string(x, y, z): num = '0' + '1'*x + '2'*y + '3'*z + '0' while '00' not in num: num = num.replace('01', '220', 1).replace('02', '1013', 1).replace('03', '120', 1) return x + y + z if num.count('1') == 13 and num.count('2') == 18 else None A = [result for x, y, z in product(range(20, -1, -1), repeat=3) if (result := process_string(x, y, z)) is not None] print(min(A) + 2) Python from itertools import product def process_string(x, y, z): num = '0' + '1'*x + '2'*y + '3'*z + '0' while '00' not in num: num = num.replace('01', '220', 1).replace('02', '1013', 1).replace('03', '120', 1) return x + y + z if num.count('1') == 13 and num.count('2') == 18 else None A = [result for x, y, z in product(range(20, -1, -1), repeat=3) if (result := process_string(x, y, z)) is not None] print(min(A) + 2)
nums = [] for x in range(15,-1,-1): for y in range(15,-1,-1): for z in range(15,-1,-1): i = '0' + '1'*x + '2'*y + '3'*z +'0' while '00' not in i: i = i.replace('01','220',1).replace('02','1013',1).replace('03','120',1) if i.count('1') == 13 and i.count('2') == 18: nums.append(x + y + z) print(min(nums) + 2) Python nums = [] for x in range(15,-1,-1): for y in range(15,-1,-1): for z in range(15,-1,-1): i = '0' + '1'*x + '2'*y + '3'*z +'0' while '00' not in i: i = i.replace('01','220',1).replace('02','1013',1).replace('03','120',1) if i.count('1') == 13 and i.count('2') == 18: nums.append(x + y + z) print(min(nums) + 2)