https://hrubos.tech/blogy/content/images/20251231225720-minimal_777_number_9_sticks_number_is.png
from itertools import product
# num of sticks for every digit
sticks = {
'0':6, '1':2, '2':5, '3':5, '4':4, '5':5, '6':6, '7':3, '8':7, '9':6
}
target_sticks = 9 # 3x7 sticks
# finds all combinations 1,2,3-digit numbers, which has together 9 sticks
results = []
# trying 1 to 3 digit combinations
for n in range(1, 4):
for combo in product(sticks.keys(), repeat=n):
if sum(sticks[d] for d in combo) == target_sticks:
results.append(''.join(combo))
print(results)
print(f"Total: {len(results)}")
print(f"Minimal number is: {results[0]}")
Dlhšia možnosť, kde nejdem hrubou silou, ale presne chcem len použiť 3 paličky od gpt:
from itertools import product
# Počet paličiek pre každú číslicu
sticks = {'0':6, '1':2, '2':5, '3':5, '4':4, '5':5, '6':6, '7':3, '8':7, '9':6}
target_sticks = 9
# Generujeme všetky čísla s 9 paličkami (1–3 cifry)
all_numbers = []
for n in range(1, 4):
for combo in product(sticks.keys(), repeat=n):
if sum(sticks[d] for d in combo) == target_sticks:
all_numbers.append(''.join(combo))
# Funkcia, ktorá zistí, či sa dá číslo previesť na iné presunom n paličiek
def can_transform(from_num, to_num, moves=3):
from_sticks = [sticks[d] for d in from_num]
to_sticks = [sticks[d] for d in to_num]
# Ak majú rôznu dĺžku, doplníme nuly na začiatok kratšieho
max_len = max(len(from_sticks), len(to_sticks))
from_sticks = [0]*(max_len - len(from_sticks)) + from_sticks
to_sticks = [0]*(max_len - len(to_sticks)) + to_sticks
# Presun = rozdiel v počte paličiek
total_diff = sum(abs(f - t) for f, t in zip(from_sticks, to_sticks))
# Každý presun môže zmeniť pozíciu len jednej paličky
return total_diff // 2 <= moves
# Nájdeme minimálne číslo vznikajúce presunom 3 paličiek
minimal_number = None
for target in all_numbers:
for source in all_numbers:
if can_transform(source, target, moves=3):
if minimal_number is None or int(target) < int(minimal_number):
minimal_number = target
print(f"Minimálne číslo presunom 3 paličiek je: {minimal_number}")

https://hrubos.tech/blogy/content/images/20251231233951-minimal_777_number_9_sticks_number_is_b.png

Comments “Aké minimálne číslo sa dá stvoriť z čísla 777, ktoré obsahuje 9 palíčiek len presunom týchto palíčiek? A dokážeme to nakódiť s gpt?”