٥륯åĥ
/ɽꥢե٥åȤɵƤȡA35ˤʤޤ
421ڡ 0:06:08 51449

3̤΢Τ褦ʵޤ
θʤ̾ϤޤȿǤƤޤ
421ڡ 0:07:45 51450
Ȥ
ɽޤɽޤäƤΤ褯ƳڤäǤ
421ڡ 0:13:41 51451
Mr.ǥ
٥륯åĥΡ#51449Ʊͤˤޤ
421ڡ 0:14:17 51452
鯤ο
ߣɽäƲ򤭤ޤ
ƹԳˤϡŤĤʤΤǡ˲򤱤Ƥޤ

塡ȡ
塡ȡ
塡ȡ
塡ȡ
塡ȡ
ˤʤޤ

顢ϡ3,5
421ڡ 0:20:21 51453
ֿء׾ι
ԲǽʽäƤȹʤޤ
421ڡ 1:23:29 51454
Sunachu
5x5x5ΩΤǹͤñǤ
421ڡ 9:30:36 51456
DA
ͤ55ɽȤäƲ򤭤ޤ
A礬ǽ˵ޤޤ
421ڡ 20:43:11 51457
SECOND
!ץDz򤯤ˤϡɤФ褤ǡʤ
! P(5,5)=120 Σ衢14400̤ꡢƤΥ򸡺̤¾ˤ̵
!ͤůŪˡԤˤϡɤФ褤

!ok= 0 1
!ok= 0 2
!ok= 0 3
! (
!)
!ok= 0 6220
!ok= 1 6221

! - - E - -
! - B - - -
! - - - - A
! C - - - -
! - - - D -

!ok= 0 6222
! (
!)
!ok= 0 14399
!ok= 0 14400

DIM m(120,5), z(5), h$(5,5)
DATA 1,2,3,4,5
MAT READ z
CALL perm20(1) !z(5)=1,2,3,4,5 ν P(5,5) Ÿ m(120,5)˺
!
FOR y=1 TO 120
FOR x=1 TO 120
MAT h$="-"& NUL$ !h$(,) ޡ"-"
FOR i=1 TO 5
LET h$(m(y,i),m(x,i))=CHR$(i+64) !P(5,5)^2=14400̤ (,) h$(5,5) ˽缡
NEXT i
CALL check !ѵҥѵҥξ
LET n=n+1
PRINT "!ok=";ok;n
IF ok=1 THEN
PRINT
MAT PRINT USING "! # # # # #" :h$
PRINT
pause
END IF
NEXT x
NEXT y

!-------------------------------------------
! h$(1~5,1~5) ̣ ABCDE θ
!-------------------------------------------
SUB check
LET ok=0
!--------------------
!ѵҥäϣȤ
!--------------------
FOR i=1 TO 5
IF h$(4,i)="C" THEN EXIT FOR
NEXT i
IF 5< i THEN EXIT SUB
!--------------------
!ѵҥŤϡȤϤ夷衣
!--------------------
FOR i=1 TO 5
IF h$(5,i)<>"-" THEN EXIT FOR
NEXT i
FOR j=1 TO i-1
FOR w=1 TO 4
IF h$(w,j)="E" THEN EXIT FOR
NEXT w
IF w<=4 THEN EXIT FOR
NEXT j
IF i<=j THEN EXIT SUB
!--------------------
!ѵҥȤϡʲ͡
!--------------------
IF h$(1,1)<>"-" OR h$(1,2)<>"-" THEN EXIT SUB
!--------------------
!ѵҥ¤ϣ夫ˤʤ
!--------------------
FOR i=1 TO 5
IF h$(i,2)="B" THEN EXIT FOR
NEXT i
IF 5< i THEN EXIT SUB
!--------------------
!ѵҥȤϡä...
!--------------------
IF h$(3,5)="-" THEN EXIT SUB
!--------------------
!ѵҥȤϤϡˤϤʤʤä
!--------------------
IF h$(2,1)<>"-" THEN EXIT SUB
!--------------------
!ѵҥĤϡϤ곰¦ȡȤֹ椬礭Ȥȡˤäʡ
!--------------------
FOR i=1 TO 5
IF h$(i,1)<>"-" THEN EXIT FOR
NEXT i
FOR i=i+1 TO 5
FOR j=2 TO 5
IF h$(i,j)="D" THEN EXIT FOR
NEXT j
IF j<=5 THEN EXIT FOR
NEXT i
IF 5< i THEN EXIT SUB
!--------------------
LET ok=1
END SUB

!-----------------------------------------------------
! z(5)=1,2,3,4,5 P(5,5)m(120,5) ˳Ǽ
!-----------------------------------------------------
SUB perm20(k) !start CALL perm20(1)
local i
IF k<=5 THEN
FOR i=k TO 5
swap z(k),z(i)
CALL perm20(k+1)
swap z(k),z(i)
NEXT i
ELSE
LET p=p+1
FOR i=1 TO 5
LET m(p,i)=z(i)
NEXT i
END IF
END SUB

END
422ʶ 11:17:43 51458

pythonʼ꽬ˤץߥ󥰤Dz򤤤Ƥߤޤ
Google ColabǡʲΥɤ¹Ԥ

UMA Chaku Waku
A 5 3
B 2 2
C 1 4
D 4 5
E 3 1

Ȥ̤ޤ

------------------------

!pip install ortools

from ortools.sat.python import cp_model

class SolutionPrinter(cp_model.CpSolverSolutionCallback):
def __init__(self, u2c, u2w):
cp_model.CpSolverSolutionCallback.__init__(self)
self.__u2c = u2c
self.__u2w = u2w
self.__solution_count = 0

def solution_count(self):
return self.__solution_count

def on_solution_callback(self):
print('Solution %i,' % self.__solution_count)
self.__solution_count += 1

uma=['A','B','C','D','E']
print('UMA Chaku Waku')
for i in range(len(uma)):
print(f'{uma[i]} {self.Value(u2c[i])+1} {self.Value(u2w[i])+1}')
print()

m = cp_model.CpModel()
u2w=[m.NewIntVar(0,5-1,'u2w%i'% i) for i in range(5)]#Ϣ
w2c=[m.NewIntVar(0,5-1,'w2c%i'% i) for i in range(5)]#Ȣ
u2c=[m.NewIntVar(0,5-1,'u2c%i'% i) for i in range(5)]#Ϣ
m.AddAllDifferent(u2w)
m.AddAllDifferent(w2c)
m.AddAllDifferent(u2c)

for i in range(5):
m.AddElement(u2w[i],w2c,u2c[i])#ϢȢϢ夬

#äϣȤ
m.Add(u2w[2]==3)
#ŤϡȤϤ夷衣
m.Add(u2c[4]<w2c[4])
#Ȥϡʲ͡
m.Add(w2c[0]>=2)
#¤ϣ夫ˤʤ
m.Add(u2c[1]==1)
#Ȥϡä...
m.Add(w2c[2]==4)
#ȤϤϡˤϤʤʤä
m.Add(w2c[1]!=0)
#ĤϡϤ곰¦ȡȤֹ椬礭Ȥȡˤäʡ
c2w=[m.NewIntVar(0,5-1,'c2w%i'% i) for i in range(5)]#墪
m.AddInverse(w2c,c2w)
m.Add(u2w[3]>c2w[0])

# Solve the model.
solver = cp_model.CpSolver()
solution_printer = SolutionPrinter(u2c,u2w)
solver.parameters.enumerate_all_solutions = True
solver.Solve(m, solution_printer)
422ʶ 17:04:42 51459

ηǼĤϹƬΥڡȥवƤޤǤ͡pythonϥڡʸˡΰ̣Τʤȥ顼ˤʤޤ
Ԥ4,9,11,27ܤ1
5-8,10,12-16,18ܤ2
17ܤ3Ĥ
ƬΥڡʤޤϥ֡ˤդޤ
422ʶ 18:09:37 51460