#
# PYTHON • MyCompiler
# Quebra Cuca | Puzzle
# https://[Log in to view URL]
# Cálculo das Soluções
#
# 2026 Maio Qua, 13 — Sáb, 16
# by
# j
#
import random
import matplotlib.pyplot as plt
import numpy as np
#
# W A R N I N G
#
# Para obter todas as 8105 soluções
# deste puzzle é necessário configurar
# a variável MAX para 5000000; no
# entanto haverá a necessidade de mudar
# a ambiência de execução deste código
# python para evitar o estouro de tempo.
#
# To obtain all 8,105 solutions to this
# puzzle, you must set the MAX variable
# to 5,000,000; however, you will need
# to adjust the execution environment
# for this Python code to avoid a
# timeout.
#
MAX = 20
line = []
def carga():
print("")
print("... Carga Das Triplas ...")
print("")
max = 9
h = 0
for x in range(1,max+1):
for y in range(1,max+1):
for z in range(1,max+1):
s = x + y + z
if (s == 19):
t = str(x) + ':' + str(y) + ':' + str(z)
r = '(' + str(x) + ',' + str(y) + ',' + str(z) + ')'
if not(t in line):
line.append(t)
h += 1
if (h < 45):
print(r,end=',')
else:
print(r)
print("")
print(len(line)," Triplas Carregadas")
print("")
def search(num,pos):
f = True
while (f):
v = random.randint(1,45)
x = int(line[v-1][0])
y = int(line[v-1][2])
z = int(line[v-1][4])
u = ( pos == 1 ) and (x == num)
v = ( pos == 2 ) and (y == num)
h = ( pos == 3 ) and (z == numpy)
if ( u or v or h ):
f = False
t = str(x) + ':' + str(y) + ':' + str(z)
return t
def graf(s):
plt.style.use('dark_background')
leg = "e:d:b:c:i:f:g:a:j:h"
num = []
for i in range(0,10):
num.append(s[0][2*i])
cx = []
cy = []
R = 10
konst = (2*np.pi)/5
delta = 55*np.pi/180
for j in range(0,5):
cx.append(R*np.cos(j*konst+delta))
cy.append(R*np.sin(j*konst+delta))
R = 24
konst = (2*np.pi)/5
delta = 20*np.pi/180
for j in range(0,5):
cx.append(0+R*np.cos(j*konst+delta))
cy.append(0+R*np.sin(j*konst+delta))
x = []
y = []
raio = 1.5
plt.figure(figsize=(6,6))
teta = np.linspace(0, 2*np.pi, 100)
for j in range (0,10):
x.append(cx[j] + raio * np.cos(teta))
y.append(cy[j] + raio * np.sin(teta))
plt.plot(x[j], y[j])
for j in range(0,4):
plt.plot([cx[j],cx[j+1]],[cy[j],cy[j+1]])
plt.plot([cx[4],cx[0]],[cy[4],cy[0]])
plt.plot([cx[4],cx[8]],[cy[4],cy[8]])
plt.plot([cx[4],cx[8]],[cy[4],cy[8]])
plt.plot([cx[0],cx[9]],[cy[0],cy[9]])
plt.plot([cx[1],cx[5]],[cy[1],cy[5]])
plt.plot([cx[2],cx[6]],[cy[2],cy[6]])
plt.plot([cx[3],cx[7]],[cy[3],cy[7]])
for j in range(0,10):
plt.scatter(cx[j],cy[j], s=400, alpha=1, color="black")
plt.text(cx[j]-0.5,cy[j]-0.5,num[j],color="w")
plt.text(cx[j]-0.50,cy[j]-3.25,leg[2*j],color="w")
tit = 'Puzzle | ' + s[0]
plt.axis('equal')
plt.title(tit)
plt.xticks([])
plt.yticks([])
plt.grid(False)
plt.show()
def ultra():
carga()
print("... Solução Ultra ...")
print("")
sol = []
z = 1
while (z < MAX):
v = random.randint(1,45)
a = int(line[v-1][0])
b = int(line[v-1][2])
c = int(line[v-1][4])
r = search(b,1)
b = int(r[0])
d = int(r[2])
g = int(r[4])
r = search(d,1)
d = int(r[0])
e = int(r[2])
f = int(r[4])
r = search(e,1)
e = int(r[0])
i = int(r[2])
h = int(r[4])
j = 19 - (c + i)
k = ( (a+b+c) == 19 )
l = ( (b+d+g) == 19 )
m = ( (d+e+f) == 19 )
n = ( (e+i+h) == 19 )
o = ( (i+c+j) == 19 )
p = ( j <= 9 )
if ( k and l and m and n and o and p ):
t = str(e) + ':' + str(d) + ':' + str(b) + ':' + str(c) + ':' + str(i) + ':' + str(f) + ':' + str(g) + ':' + str(a) + ':' + str(j) + ':' + str(h)
if not(t in sol):
sol.append(t)
z += 1
print(sol)
print("")
print("quantidade = ",len(sol))
return sol
def contagem():
carga()
max = 1000
tipo = []
cont = [0,0,0,0,0,0,0,0,0]
sum = 0
for j in range(1,10):
print("... Análise "+str(j)+" ...")
tipo.clear()
k = 0
s = 0
while (k < max):
t = search(j,2)
if (int(t[2]) == j):
if (not(t in tipo)):
tipo.append(t)
print(t)
s += 1
k += 1
m = s
print("Total = ",m)
print("")
tipo.clear()
k = 0
s = 0
while (k < max):
t = search(j,1)
if (int(t[0]) == j):
if (not(t in tipo)):
tipo.append(t)
print(".....",t)
s += 1
#
# Conta meio
#
cont[int(t[2])-1] += 1
k += 1
n = s
print("Total = ",n)
print("")
sum += m*n
print("Total Geral = ",sum)
print(cont)
def control():
s = ultra()
graf(s)
#contagem()
control()
To embed this project on your website, copy the following code and paste it into your website's HTML: