Working out permutations
Moderator: DosItHelp
Working out permutations
Hey guys, I was working on a program to generate all possibilities you can have from a rubik tangle, It worked out well for a while, but when I got to the permutation part, 25*24*23*22*21*20*19*18*17*16*15*14*13*12*11*10*9*8*7*6*5*4*3*2*1, I got stuck, Since the program has to generate all these possibilities, which are over a billion. Could anyone help me making a batch script which generates all these possibilities? Thanks for your support!
Example: Permutation of 3 :
abc
acb
bca
bac
cba
cab
Example: Permutation of 3 :
abc
acb
bca
bac
cba
cab
Re: support needed!
You'll want to use a high level language - speed being one reason.
Re: Working out permutations
Impossible for nowadays PC to store (or even to generate) all permutation of 25 elements which is "slightly" more than 1 billion:Pascaen wrote:but when I got to the permutation part, 25*24*23*22*21*20*19*18*17*16*15*14*13*12*11*10*9*8*7*6*5*4*3*2*1, I got stuck, Since the program has to generate all these possibilities, which are over a billion.
25! == 15511210043330985.984 billion
If you want to store it to disk (intuitively using 25 ANSI characters per permutation), you would need:
25!*25/(1024^4) > 352684083812414 TByte > actual global storage capacity
Assumed your pc is "really extraordinary super fast", so it computes 1,000,000,000,000 million permutations per second (MUCH faster than all nowadays pc's on earth together) then it would take ~0.5 years to compute all.
So you should think of simplifying your solution (find a simpler equivalent mathematical description).
penpen
Edit 1: Corrected "terabyte" to "TByte" (=="TB" == "TiB"); normally i don't use the correct phrase because nearly nobody (i jave talked to) 'sees' the difference.
Last edited by penpen on 25 Apr 2015 07:40, edited 1 time in total.
Re: Working out permutations
It is possible to generate permutations with a batch file.
The first file will be created directly. Each additional file is created on the basis of the previous file.
Please consider the following information:
25! = 15 511 210 043 330 985 984 000 000 = 15.511 * 10^24
25! * 51 char = 791 071 712 209 880 285 184 000 000 byte
= 791.072 * 10^24 byte
= 791 071 712 209 880.28 terabyte (TB)
= 719 475 530 977 324.78 tebibyte (TiB) (most in software used: TB)
= 791.07 yotabyte (YB)
= 654.36 yobibyte (YiB)
51 char = 25 letter + 24 space character + CR + LF
See also: http://en.wikipedia.org/wiki/Terabyte
###
Create a square of 4 parts (2 x 2). The number will be sure manageable.
Then combine two squares to a rectangle of 6 parts (3 x 2). Next step then a rectangle with 8 and then with 10 parts.
In the next step, the rectangles with 10 parts now be extended to larger rectangles (15, 20, and 25 parts).
Here I have used four parts. Each part has a corresponding letter of the orientation of the part.
Here again the parts.
In the following the quarter circle is highlighted.
01b: RG BY YR BG
02c: RG YG RB BY
03a: YR GY BR BG
04c: RB YB RG GY
A part in various orientations.
01a: GB RG YB YR
01b: RG BY YR BG
01c: BY RY BG GR
01d: RY GB GR YB
The first file will be created directly. Each additional file is created on the basis of the previous file.
Code: Select all
@echo off
setlocal ENABLEEXTENSIONS enableDelayedExpansion
if exist permutation_*.txt del permutation_*.txt
echo 1 >permutation_1.txt
for /F "tokens=1" %%a in (permutation_1.txt) do (
echo %%a 2
echo 2 %%a
) >>permutation_2.txt
for /F "tokens=1-2" %%a in (permutation_2.txt) do (
echo %%a %%b 3
echo %%a 3 %%b
echo 3 %%a %%b
) >>permutation_3.txt
for /F "tokens=1-3" %%a in (permutation_3.txt) do (
echo %%a %%b %%c 4
echo %%a %%b 4 %%c
echo %%a 4 %%b %%c
echo 4 %%a %%b %%c
) >>permutation_4.txt
for /F "tokens=1-4" %%a in (permutation_4.txt) do (
echo %%a %%b %%c %%d 5
echo %%a %%b %%c 5 %%d
echo %%a %%b 5 %%c %%d
echo %%a 5 %%b %%c %%d
echo 5 %%a %%b %%c %%d
) >>permutation_5.txt
for /F "tokens=1-5" %%a in (permutation_5.txt) do (
echo %%a %%b %%c %%d %%e 6
echo %%a %%b %%c %%d 6 %%e
echo %%a %%b %%c 6 %%d %%e
echo %%a %%b 6 %%c %%d %%e
echo %%a 6 %%b %%c %%d %%e
echo 6 %%a %%b %%c %%d %%e
) >>permutation_6.txt
Please consider the following information:
25! = 15 511 210 043 330 985 984 000 000 = 15.511 * 10^24
25! * 51 char = 791 071 712 209 880 285 184 000 000 byte
= 791.072 * 10^24 byte
= 791 071 712 209 880.28 terabyte (TB)
= 719 475 530 977 324.78 tebibyte (TiB) (most in software used: TB)
= 791.07 yotabyte (YB)
= 654.36 yobibyte (YiB)
51 char = 25 letter + 24 space character + CR + LF
See also: http://en.wikipedia.org/wiki/Terabyte
###
Create a square of 4 parts (2 x 2). The number will be sure manageable.
Then combine two squares to a rectangle of 6 parts (3 x 2). Next step then a rectangle with 8 and then with 10 parts.
In the next step, the rectangles with 10 parts now be extended to larger rectangles (15, 20, and 25 parts).
Code: Select all
RG RG
B B B Y
G Y Y G 01b + 02c
YR RB
YR RB
B G G Y
G Y Y B 03a + 04c
BR RG
01b: RG BY YR BG
02c: RG YG RB BY
03a: YR GY BR BG
04c: RB YB RG GY
Here I have used four parts. Each part has a corresponding letter of the orientation of the part.
Here again the parts.
In the following the quarter circle is highlighted.
01b: RG BY YR BG
02c: RG YG RB BY
03a: YR GY BR BG
04c: RB YB RG GY
A part in various orientations.
01a: GB RG YB YR
01b: RG BY YR BG
01c: BY RY BG GR
01d: RY GB GR YB
Last edited by trebor68 on 05 May 2015 05:01, edited 1 time in total.
Re: Working out permutations
I write a batch file, with which it is possible to find all combinations of four Tangle pieces (2x2 pieces).
There are four different Tangle: Tangle 1, Tangle 2, Tangle 3 and Tangle 4
The versions differ only by the duplicate Tangle piece. In the batch file one of the duplicate Tangle piece is p25.
To find out the existing version give a command:
With the parameter /ALL all combinations are determined. The output here is to redirect to a file.
Note: There are 4948 combinations of four Tangle pieces (2x2 pieces).
Here the code of Test54a.bat
(update: /ALL and /TEST with problem. Error in /SEARCH found - corrected)
(update: some new parameter)
An error can occur if it is not enabled DelayedExpansion on your system - corrected:
How can you expand from 2x2 pieces to 3x2 pieces?
Result is:
p01a p13a p05b
p17c p02b p10a
How can you expand from 2x2 pieces to 4x2 pieces?
Result is:
p01a p13a p05b p23a
p17c p02b p10a p15d
In the FOR loop, the same values were used for both variables here, because both have Tangle pieces on the left side the color combination RG (Red, Green).
The examples show only one of the combinations.
With the expansion of 2x2 to 4x2 there are 56 combinations. I think the extension to 2x4 will come to a similar number of combinations.
There are many combinations to consider.
There are four different Tangle: Tangle 1, Tangle 2, Tangle 3 and Tangle 4
The versions differ only by the duplicate Tangle piece. In the batch file one of the duplicate Tangle piece is p25.
To find out the existing version give a command:
Code: Select all
for %a in (p12a p14a p15a p24a p25a) do @test54a /piece %a
With the parameter /ALL all combinations are determined. The output here is to redirect to a file.
Code: Select all
test54a /all >Tangle_4p.txt
Here the code of Test54a.bat
(update: /ALL and /TEST with problem. Error in /SEARCH found - corrected)
(update: some new parameter)
An error can occur if it is not enabled DelayedExpansion on your system - corrected:
Code: Select all
@echo off
setlocal ENABLEEXTENSIONS enableDelayedExpansion
set viewmode=#
if /i "%1"=="/piece" set viewmode=#1
if /i "%1"=="/piece4" set viewmode=#4
if /i "%1"=="/piece9" set viewmode=#9
if /i "%1"=="/piece16" set viewmode=#16
if /i "%1"=="/piece25" set viewmode=#25
set letrun=no
for %%a in (/piece /piece4 /piece9 /piece16 /piece25 /TEST /ALL /SEARCH /RECOLOR /ROTATE /FINDCOLOR) do if /i "%1"=="%%a" set letrun=yes
if %letrun%==yes goto :anfang
:help
echo.
echo %0 - Overview of Tangle and solution for 2x2 pieces
echo.
echo %0 [ /TEST ^| /ALL ]
echo %0 /PIECE piece
echo %0 /PIECE4 piece piece piece piece
echo %0 /PIECE9 piece piece piece piece piece piece piece piece piece
echo %0 /PIECE16 piece ... piece
echo %0 /PIECE25 piece ... piece
echo %0 /SEARCH LEFT^|RIGHT^|BOTTOM^|UPPER cords^|piece
echo %0 /FINDCOLOR piece1 piece2
echo %0 /RECOLOR code piece [piece ... piece]
echo %0 /ROTATE area 1^|2^|3 piece [piece ... piece]
echo.
echo /TEST tested only one piece in all four orientations
echo /ALL all pieces in all orientations; not used p25a, p25b, p25c, p25d
echo /PIECE view a Tangle piece in one orientation
echo /PIECE4 view four Tangle pieces ^(2x2 pieces^)
echo /PIECE9 view nine Tangle pieces ^(3x3 pieces^)
echo /PIECE16 view 16 Tangle pieces ^(4x4 pieces^)
echo /PIECE25 view 25 Tangle pieces ^(5x5 pieces^)
echo piece letter p, two digits, one letter ^(a, b, c, d^)
echo p01a, p01b, p01c, p01d, p02a, p02b ... p25a, p25b, p25c, p25d
echo /SEARCH searches color coding or piece on one side of the Tangle piece
echo cords one of these values: YG YR YB GY GR GB RY RG RB BY BR BG
echo /FINDCOLOR find the color code that change piece1 to piece2
echo /RECOLOR change the color code of pieces;
echo in the result are not present: p25a, p25b, p25c or p25d
echo code color code ^(example: BRYG^); result of /FINDCOLOR
echo /ROTATE rotate area not clockwise 90 degrees, 180 degrees or 270 degrees
echo area one of this following value: 2x2, 3x3, 4x4, 5x5
echo.
echo Also possible are the pieces: p00a, p00b, p00c and p00d
goto :eof
:anfang
rem 34 # 13 # 42 # 12 # Tangle piece and each orientations.
rem 2 1 # 4 4 # 3 1 # 2 3 # The orientation of the first Tangle piece is shown that the cord that passes straight from top to bottom on the right side.
rem 1 3 # 3 2 # 1 2 # 4 4 #
rem 24 # 21 # 43 # 31 #
rem Arrangement of the cords on Tangle piece for each orientations.
set basic=34 13 24 21 # 13 42 21 43 # 42 12 43 31 # 12 34 31 24
for /l %%n in (1 1 25) do (
if %%n lss 10 (set p0%%n=%basic%) else set p%%n=%basic%
)
rem piece 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
rem 1234 1243 1324 1342 1423 1432 2134 2143 2314 2341 2413 2431 3124 3142 3214 3241 3412 3421 4123 4132 4213 4231 4312 4321
rem color YGRB YGBR YRGB YRBG YBGR YBRG GYRB GYBR GRYB GRBY GBYR GBRY RYGB RYBG RGYB RGBY RBYG RBGY BYGR BYRG BGYR BGRY BRYG BRGY
rem Tangle_1 M C E F V I T Q H L O D+S J G W A R B P U X Y N L
rem Tangle_2 U V R S B O T K G M J N P H+I L F E Q X W A D C Y
rem Tangle_3 Q N R E A Y G H D X O L V B C+T J S I W K F M P U
rem Tangle_4 W B R U X I J E A V C P Y Q M L G N H S T K O D+F
rem Sets for each position one letter; Yellow, Green, Red, Blue
for %%a in (01 02 03 04 05 06) do set p%%a=!p%%a:1=Y!
for %%a in (07 08 09 10 11 12) do set p%%a=!p%%a:1=G!
for %%a in (13 14 15 16 17 18) do set p%%a=!p%%a:1=R!
for %%a in (19 20 21 22 23 24) do set p%%a=!p%%a:1=B!
for %%a in (07 08 13 14 19 20) do set p%%a=!p%%a:2=Y!
for %%a in (01 02 15 16 21 22) do set p%%a=!p%%a:2=G!
for %%a in (03 04 09 10 23 24) do set p%%a=!p%%a:2=R!
for %%a in (05 06 11 12 17 18) do set p%%a=!p%%a:2=B!
for %%a in (09 11 15 17 21 23) do set p%%a=!p%%a:3=Y!
for %%a in (03 05 13 18 19 24) do set p%%a=!p%%a:3=G!
for %%a in (01 06 07 12 20 22) do set p%%a=!p%%a:3=R!
for %%a in (02 04 08 10 14 16) do set p%%a=!p%%a:3=B!
for %%a in (10 12 16 18 22 24) do set p%%a=!p%%a:4=Y!
for %%a in (04 06 14 17 20 23) do set p%%a=!p%%a:4=G!
for %%a in (02 05 08 11 19 21) do set p%%a=!p%%a:4=R!
for %%a in (01 03 07 09 13 15) do set p%%a=!p%%a:4=B!
rem double Tangle piece: Tangle_1 = 12 (D+S); Tangle_2 = 14 (H+I); Tangle_3 = 15 (C+T); Tangle_4 = 24 (D+F)
rem Here double Tangle piece Tangle_1.
set p25=%p12%
rem Any Tangle piece with each orientations.
for %%n in (01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25) do (
(set p%%na=!p%%n:~0,11!) & (set p%%nb=!p%%n:~14,11!) & (set p%%nc=!p%%n:~28,11!) & (set p%%nd=!p%%n:~42,11!)
)
rem Dummy Tangle piece; can use in view mode
(set p00a=xx xx xx xx) & (set p00b=xx xx xx xx) & (set p00c=xx xx xx xx) & (set p00d=xx xx xx xx)
rem View Tangle piece
if %viewmode%==#1 (
rem Test if 1 pieces available
if "%2"=="" goto :help3
if not "%3"=="" goto :help3
(set pset=%2) & (set test=%2###) & (set test=!test:~0,4!)
if "!test!" neq "!pset!" goto :help3
call :TestPieces "!pset!" TestOK
if /i !TestOK!==notOK goto :help3
set view=%2
for %%t in (!view!) do set test=!%%t!
echo.
echo +---!test:~0,1!--!test:~1,1!---+
echo ^| ^|
echo !test:~9,1! !test:~3,1!
echo ^| !view! ^|
echo !test:~10,1! !test:~4,1!
echo ^| ^|
echo +---!test:~6,1!--!test:~7,1!---+
echo.
goto :eof
)
rem View four Tangle pieces
if %viewmode%==#4 (
rem Test if 4 pieces available
for /f "tokens=1*" %%a in ("%*") do set "pset=%%b"
rem Reduces max four spaces to one space and test pieces
(set pset=!pset: = !) & (set pset=!pset: = !) & (set test=!pset!###) & (set test=!test:~0,19!)
if "!test!" neq "!pset!" goto :help3
call :TestPieces "!pset!" TestOK
if /i !TestOK!==notOK goto :help3
(set view1=%2) & (set view2=%3) & (set view3=%4) & (set view4=%5)
(for %%t in (!view1!) do set test1=!%%t!) & (for %%t in (!view2!) do set test2=!%%t!) & (for %%t in (!view3!) do set test3=!%%t!) & (for %%t in (!view4!) do set test4=!%%t!)
echo.
echo +---!test1:~0,1!--!test1:~1,1!---+ +---!test2:~0,1!--!test2:~1,1!---+
echo ^| ^| ^| ^|
echo !test1:~9,1! !test1:~3,1! !test2:~9,1! !test2:~3,1!
echo ^| !view1! ^| ^| !view2! ^|
echo !test1:~10,1! !test1:~4,1! !test2:~10,1! !test2:~4,1!
echo ^| ^| ^| ^|
echo +---!test1:~6,1!--!test1:~7,1!---+ +---!test2:~6,1!--!test2:~7,1!---+
echo.
echo +---!test3:~0,1!--!test3:~1,1!---+ +---!test4:~0,1!--!test4:~1,1!---+
echo ^| ^| ^| ^|
echo !test3:~9,1! !test3:~3,1! !test4:~9,1! !test4:~3,1!
echo ^| !view3! ^| ^| !view4! ^|
echo !test3:~10,1! !test3:~4,1! !test4:~10,1! !test4:~4,1!
echo ^| ^| ^| ^|
echo +---!test3:~6,1!--!test3:~7,1!---+ +---!test4:~6,1!--!test4:~7,1!---+
echo.
goto :eof
)
rem View nine Tangle pieces
if %viewmode%==#9 (
rem Test if 9 pieces available
for /f "tokens=1*" %%a in ("%*") do set "pset=%%b"
rem Reduces max four spaces to one space and test pieces
(set pset=!pset: = !) & (set pset=!pset: = !) & (set test=!pset!###) & (set test=!test:~0,44!)
if "!test!" neq "!pset!" goto :help3
call :TestPieces "!pset!" TestOK
if /i !TestOK!==notOK goto :help3
for /f "tokens=2-10" %%A in ("%*") do (set view1=%%A) & (set view2=%%B) & (set view3=%%C) & (set view4=%%D) & (set view5=%%E) & (set view6=%%F) & (set view7=%%G) & (set view8=%%H) & (set view9=%%I)
(for %%t in (!view1!) do set test1=!%%t!) & (for %%t in (!view2!) do set test2=!%%t!) & (for %%t in (!view3!) do set test3=!%%t!)
(for %%t in (!view4!) do set test4=!%%t!) & (for %%t in (!view5!) do set test5=!%%t!) & (for %%t in (!view6!) do set test6=!%%t!)
(for %%t in (!view7!) do set test7=!%%t!) & (for %%t in (!view8!) do set test8=!%%t!) & (for %%t in (!view9!) do set test9=!%%t!)
echo.
echo +---!test1:~0,1!--!test1:~1,1!---+ +---!test2:~0,1!--!test2:~1,1!---+ +---!test3:~0,1!--!test3:~1,1!---+
echo ^| ^| ^| ^| ^| ^|
echo !test1:~9,1! !test1:~3,1! !test2:~9,1! !test2:~3,1! !test3:~9,1! !test3:~3,1!
echo ^| !view1! ^| ^| !view2! ^| ^| !view3! ^|
echo !test1:~10,1! !test1:~4,1! !test2:~10,1! !test2:~4,1! !test3:~10,1! !test3:~4,1!
echo ^| ^| ^| ^| ^| ^|
echo +---!test1:~6,1!--!test1:~7,1!---+ +---!test2:~6,1!--!test2:~7,1!---+ +---!test3:~6,1!--!test3:~7,1!---+
echo.
echo +---!test4:~0,1!--!test4:~1,1!---+ +---!test5:~0,1!--!test5:~1,1!---+ +---!test6:~0,1!--!test6:~1,1!---+
echo ^| ^| ^| ^| ^| ^|
echo !test4:~9,1! !test4:~3,1! !test5:~9,1! !test5:~3,1! !test6:~9,1! !test6:~3,1!
echo ^| !view4! ^| ^| !view5! ^| ^| !view6! ^|
echo !test4:~10,1! !test4:~4,1! !test5:~10,1! !test5:~4,1! !test6:~10,1! !test6:~4,1!
echo ^| ^| ^| ^| ^| ^|
echo +---!test4:~6,1!--!test4:~7,1!---+ +---!test5:~6,1!--!test5:~7,1!---+ +---!test6:~6,1!--!test6:~7,1!---+
echo.
echo +---!test7:~0,1!--!test7:~1,1!---+ +---!test8:~0,1!--!test8:~1,1!---+ +---!test9:~0,1!--!test9:~1,1!---+
echo ^| ^| ^| ^| ^| ^|
echo !test7:~9,1! !test7:~3,1! !test8:~9,1! !test8:~3,1! !test9:~9,1! !test9:~3,1!
echo ^| !view7! ^| ^| !view8! ^| ^| !view9! ^|
echo !test7:~10,1! !test7:~4,1! !test8:~10,1! !test8:~4,1! !test9:~10,1! !test9:~4,1!
echo ^| ^| ^| ^| ^| ^|
echo +---!test7:~6,1!--!test7:~7,1!---+ +---!test8:~6,1!--!test8:~7,1!---+ +---!test9:~6,1!--!test9:~7,1!---+
echo.
goto :eof
)
rem View 16 Tangle pieces
if %viewmode%==#16 (
rem Test if 16 pieces available
for /f "tokens=1*" %%a in ("%*") do set "pset=%%b"
rem Reduces max four spaces to one space and test pieces
(set pset=!pset: = !) & (set pset=!pset: = !) & (set test=!pset!###) & (set test=!test:~0,79!)
if "!test!" neq "!pset!" goto :help3
call :TestPieces "!pset!" TestOK
if /i !TestOK!==notOK goto :help3
for /f "tokens=2-17" %%A in ("%*") do (
(set view1=%%A) & (set view2=%%B) & (set view3=%%C) & (set view4=%%D) & (set view5=%%E) & (set view6=%%F) & (set view7=%%G) & (set view8=%%H)
(set view9=%%I) & (set view10=%%J) & (set view11=%%K) & (set view12=%%L) & (set view13=%%M) & (set view14=%%N) & (set view15=%%O) & (set view16=%%P)
)
(for %%t in (!view1!) do set test1=!%%t!) & (for %%t in (!view2!) do set test2=!%%t!) & (for %%t in (!view3!) do set test3=!%%t!) & (for %%t in (!view4!) do set test4=!%%t!)
(for %%t in (!view5!) do set test5=!%%t!) & (for %%t in (!view6!) do set test6=!%%t!) & (for %%t in (!view7!) do set test7=!%%t!) & (for %%t in (!view8!) do set test8=!%%t!)
(for %%t in (!view9!) do set test9=!%%t!) & (for %%t in (!view10!) do set test10=!%%t!) & (for %%t in (!view11!) do set test11=!%%t!) & (for %%t in (!view12!) do set test12=!%%t!)
(for %%t in (!view13!) do set test13=!%%t!) & (for %%t in (!view14!) do set test14=!%%t!) & (for %%t in (!view15!) do set test15=!%%t!) & (for %%t in (!view16!) do set test16=!%%t!)
echo.
echo +---!test1:~0,1!--!test1:~1,1!---+ +---!test2:~0,1!--!test2:~1,1!---+ +---!test3:~0,1!--!test3:~1,1!---+ +---!test4:~0,1!--!test4:~1,1!---+
echo ^| ^| ^| ^| ^| ^| ^| ^|
echo !test1:~9,1! !test1:~3,1! !test2:~9,1! !test2:~3,1! !test3:~9,1! !test3:~3,1! !test4:~9,1! !test4:~3,1!
echo ^| !view1! ^| ^| !view2! ^| ^| !view3! ^| ^| !view4! ^|
echo !test1:~10,1! !test1:~4,1! !test2:~10,1! !test2:~4,1! !test3:~10,1! !test3:~4,1! !test4:~10,1! !test4:~4,1!
echo ^| ^| ^| ^| ^| ^| ^| ^|
echo +---!test1:~6,1!--!test1:~7,1!---+ +---!test2:~6,1!--!test2:~7,1!---+ +---!test3:~6,1!--!test3:~7,1!---+ +---!test4:~6,1!--!test4:~7,1!---+
echo.
echo +---!test5:~0,1!--!test5:~1,1!---+ +---!test6:~0,1!--!test6:~1,1!---+ +---!test7:~0,1!--!test7:~1,1!---+ +---!test8:~0,1!--!test8:~1,1!---+
echo ^| ^| ^| ^| ^| ^| ^| ^|
echo !test5:~9,1! !test5:~3,1! !test6:~9,1! !test6:~3,1! !test7:~9,1! !test7:~3,1! !test8:~9,1! !test8:~3,1!
echo ^| !view5! ^| ^| !view6! ^| ^| !view7! ^| ^| !view8! ^|
echo !test5:~10,1! !test5:~4,1! !test6:~10,1! !test6:~4,1! !test7:~10,1! !test7:~4,1! !test8:~10,1! !test8:~4,1!
echo ^| ^| ^| ^| ^| ^| ^| ^|
echo +---!test5:~6,1!--!test5:~7,1!---+ +---!test6:~6,1!--!test6:~7,1!---+ +---!test7:~6,1!--!test7:~7,1!---+ +---!test8:~6,1!--!test8:~7,1!---+
echo.
echo +---!test9:~0,1!--!test9:~1,1!---+ +---!test10:~0,1!--!test10:~1,1!---+ +---!test11:~0,1!--!test11:~1,1!---+ +---!test12:~0,1!--!test12:~1,1!---+
echo ^| ^| ^| ^| ^| ^| ^| ^|
echo !test9:~9,1! !test9:~3,1! !test10:~9,1! !test10:~3,1! !test11:~9,1! !test11:~3,1! !test12:~9,1! !test12:~3,1!
echo ^| !view9! ^| ^| !view10! ^| ^| !view11! ^| ^| !view12! ^|
echo !test9:~10,1! !test9:~4,1! !test10:~10,1! !test10:~4,1! !test11:~10,1! !test11:~4,1! !test12:~10,1! !test12:~4,1!
echo ^| ^| ^| ^| ^| ^| ^| ^|
echo +---!test9:~6,1!--!test9:~7,1!---+ +---!test10:~6,1!--!test10:~7,1!---+ +---!test11:~6,1!--!test11:~7,1!---+ +---!test12:~6,1!--!test12:~7,1!---+
echo.
echo +---!test13:~0,1!--!test13:~1,1!---+ +---!test14:~0,1!--!test14:~1,1!---+ +---!test15:~0,1!--!test15:~1,1!---+ +---!test16:~0,1!--!test16:~1,1!---+
echo ^| ^| ^| ^| ^| ^| ^| ^|
echo !test13:~9,1! !test13:~3,1! !test14:~9,1! !test14:~3,1! !test15:~9,1! !test15:~3,1! !test16:~9,1! !test16:~3,1!
echo ^| !view13! ^| ^| !view14! ^| ^| !view15! ^| ^| !view16! ^|
echo !test13:~10,1! !test13:~4,1! !test14:~10,1! !test14:~4,1! !test15:~10,1! !test15:~4,1! !test16:~10,1! !test16:~4,1!
echo ^| ^| ^| ^| ^| ^| ^| ^|
echo +---!test13:~6,1!--!test13:~7,1!---+ +---!test14:~6,1!--!test14:~7,1!---+ +---!test15:~6,1!--!test15:~7,1!---+ +---!test16:~6,1!--!test16:~7,1!---+
echo.
goto :eof
)
rem View 25 Tangle pieces
if %viewmode%==#25 (
rem Test if 25 pieces available
for /f "tokens=1*" %%a in ("%*") do set "pset=%%b"
rem Reduces max four spaces to one space and test pieces
(set pset=!pset: = !) & (set pset=!pset: = !) & (set test=!pset!###) & (set test=!test:~0,124!)
if "!test!" neq "!pset!" goto :help3
call :TestPieces "!pset!" TestOK
if /i !TestOK!==notOK goto :help3
for /f "tokens=2-26" %%A in ("%*") do (
(set view1=%%A) & (set view2=%%B) & (set view3=%%C) & (set view4=%%D) & (set view5=%%E) & (set view6=%%F) & (set view7=%%G) & (set view8=%%H)
(set view9=%%I) & (set view10=%%J) & (set view11=%%K) & (set view12=%%L) & (set view13=%%M) & (set view14=%%N) & (set view15=%%O) & (set view16=%%P)
(set view17=%%Q) & (set view18=%%R) & (set view19=%%S) & (set view20=%%T) & (set view21=%%U) & (set view22=%%V) & (set view23=%%W) & (set view24=%%X)
(set view25=%%Y)
)
(for %%t in (!view1!) do set test1=!%%t!) & (for %%t in (!view2!) do set test2=!%%t!) & (for %%t in (!view3!) do set test3=!%%t!) & (for %%t in (!view4!) do set test4=!%%t!)
(for %%t in (!view5!) do set test5=!%%t!) & (for %%t in (!view6!) do set test6=!%%t!) & (for %%t in (!view7!) do set test7=!%%t!) & (for %%t in (!view8!) do set test8=!%%t!)
(for %%t in (!view9!) do set test9=!%%t!) & (for %%t in (!view10!) do set test10=!%%t!) & (for %%t in (!view11!) do set test11=!%%t!) & (for %%t in (!view12!) do set test12=!%%t!)
(for %%t in (!view13!) do set test13=!%%t!) & (for %%t in (!view14!) do set test14=!%%t!) & (for %%t in (!view15!) do set test15=!%%t!) & (for %%t in (!view16!) do set test16=!%%t!)
(for %%t in (!view17!) do set test17=!%%t!) & (for %%t in (!view18!) do set test18=!%%t!) & (for %%t in (!view19!) do set test19=!%%t!) & (for %%t in (!view20!) do set test20=!%%t!)
(for %%t in (!view21!) do set test21=!%%t!) & (for %%t in (!view22!) do set test22=!%%t!) & (for %%t in (!view23!) do set test23=!%%t!) & (for %%t in (!view24!) do set test24=!%%t!)
(for %%t in (!view25!) do set test25=!%%t!)
echo.
echo +---!test1:~0,1!--!test1:~1,1!---+ +---!test2:~0,1!--!test2:~1,1!---+ +---!test3:~0,1!--!test3:~1,1!---+ +---!test4:~0,1!--!test4:~1,1!---+ +---!test5:~0,1!--!test5:~1,1!---+
echo ^| ^| ^| ^| ^| ^| ^| ^| ^| ^|
echo !test1:~9,1! !test1:~3,1! !test2:~9,1! !test2:~3,1! !test3:~9,1! !test3:~3,1! !test4:~9,1! !test4:~3,1! !test5:~9,1! !test5:~3,1!
echo ^| !view1! ^| ^| !view2! ^| ^| !view3! ^| ^| !view4! ^| ^| !view5! ^|
echo !test1:~10,1! !test1:~4,1! !test2:~10,1! !test2:~4,1! !test3:~10,1! !test3:~4,1! !test4:~10,1! !test4:~4,1! !test5:~10,1! !test5:~4,1!
echo ^| ^| ^| ^| ^| ^| ^| ^| ^| ^|
echo +---!test1:~6,1!--!test1:~7,1!---+ +---!test2:~6,1!--!test2:~7,1!---+ +---!test3:~6,1!--!test3:~7,1!---+ +---!test4:~6,1!--!test4:~7,1!---+ +---!test5:~6,1!--!test5:~7,1!---+
echo.
echo +---!test6:~0,1!--!test6:~1,1!---+ +---!test7:~0,1!--!test7:~1,1!---+ +---!test8:~0,1!--!test8:~1,1!---+ +---!test9:~0,1!--!test9:~1,1!---+ +---!test10:~0,1!--!test10:~1,1!---+
echo ^| ^| ^| ^| ^| ^| ^| ^| ^| ^|
echo !test6:~9,1! !test6:~3,1! !test7:~9,1! !test7:~3,1! !test8:~9,1! !test8:~3,1! !test9:~9,1! !test9:~3,1! !test10:~9,1! !test10:~3,1!
echo ^| !view6! ^| ^| !view7! ^| ^| !view8! ^| ^| !view9! ^| ^| !view10! ^|
echo !test6:~10,1! !test6:~4,1! !test7:~10,1! !test7:~4,1! !test8:~10,1! !test8:~4,1! !test9:~10,1! !test9:~4,1! !test10:~10,1! !test10:~4,1!
echo ^| ^| ^| ^| ^| ^| ^| ^| ^| ^|
echo +---!test6:~6,1!--!test6:~7,1!---+ +---!test7:~6,1!--!test7:~7,1!---+ +---!test8:~6,1!--!test8:~7,1!---+ +---!test9:~6,1!--!test9:~7,1!---+ +---!test10:~6,1!--!test10:~7,1!---+
echo.
echo +---!test11:~0,1!--!test11:~1,1!---+ +---!test12:~0,1!--!test12:~1,1!---+ +---!test13:~0,1!--!test13:~1,1!---+ +---!test14:~0,1!--!test14:~1,1!---+ +---!test15:~0,1!--!test15:~1,1!---+
echo ^| ^| ^| ^| ^| ^| ^| ^| ^| ^|
echo !test11:~9,1! !test11:~3,1! !test12:~9,1! !test12:~3,1! !test13:~9,1! !test13:~3,1! !test14:~9,1! !test14:~3,1! !test15:~9,1! !test15:~3,1!
echo ^| !view11! ^| ^| !view12! ^| ^| !view13! ^| ^| !view14! ^| ^| !view15! ^|
echo !test11:~10,1! !test11:~4,1! !test12:~10,1! !test12:~4,1! !test13:~10,1! !test13:~4,1! !test14:~10,1! !test14:~4,1! !test15:~10,1! !test15:~4,1!
echo ^| ^| ^| ^| ^| ^| ^| ^| ^| ^|
echo +---!test11:~6,1!--!test11:~7,1!---+ +---!test12:~6,1!--!test12:~7,1!---+ +---!test13:~6,1!--!test13:~7,1!---+ +---!test14:~6,1!--!test14:~7,1!---+ +---!test15:~6,1!--!test15:~7,1!---+
echo.
echo +---!test16:~0,1!--!test16:~1,1!---+ +---!test17:~0,1!--!test17:~1,1!---+ +---!test18:~0,1!--!test18:~1,1!---+ +---!test19:~0,1!--!test19:~1,1!---+ +---!test20:~0,1!--!test20:~1,1!---+
echo ^| ^| ^| ^| ^| ^| ^| ^| ^| ^|
echo !test16:~9,1! !test16:~3,1! !test17:~9,1! !test17:~3,1! !test18:~9,1! !test18:~3,1! !test19:~9,1! !test19:~3,1! !test20:~9,1! !test20:~3,1!
echo ^| !view16! ^| ^| !view17! ^| ^| !view18! ^| ^| !view19! ^| ^| !view20! ^|
echo !test16:~10,1! !test16:~4,1! !test17:~10,1! !test17:~4,1! !test18:~10,1! !test18:~4,1! !test19:~10,1! !test19:~4,1! !test20:~10,1! !test20:~4,1!
echo ^| ^| ^| ^| ^| ^| ^| ^| ^| ^|
echo +---!test16:~6,1!--!test16:~7,1!---+ +---!test17:~6,1!--!test17:~7,1!---+ +---!test18:~6,1!--!test18:~7,1!---+ +---!test19:~6,1!--!test19:~7,1!---+ +---!test20:~6,1!--!test20:~7,1!---+
echo.
echo +---!test21:~0,1!--!test21:~1,1!---+ +---!test22:~0,1!--!test22:~1,1!---+ +---!test23:~0,1!--!test23:~1,1!---+ +---!test24:~0,1!--!test24:~1,1!---+ +---!test25:~0,1!--!test25:~1,1!---+
echo ^| ^| ^| ^| ^| ^| ^| ^| ^| ^|
echo !test21:~9,1! !test21:~3,1! !test22:~9,1! !test22:~3,1! !test23:~9,1! !test23:~3,1! !test24:~9,1! !test24:~3,1! !test25:~9,1! !test25:~3,1!
echo ^| !view21! ^| ^| !view22! ^| ^| !view23! ^| ^| !view24! ^| ^| !view25! ^|
echo !test21:~10,1! !test21:~4,1! !test22:~10,1! !test22:~4,1! !test23:~10,1! !test23:~4,1! !test24:~10,1! !test24:~4,1! !test25:~10,1! !test25:~4,1!
echo ^| ^| ^| ^| ^| ^| ^| ^| ^| ^|
echo +---!test21:~6,1!--!test21:~7,1!---+ +---!test22:~6,1!--!test22:~7,1!---+ +---!test23:~6,1!--!test23:~7,1!---+ +---!test24:~6,1!--!test24:~7,1!---+ +---!test25:~6,1!--!test25:~7,1!---+
echo.
goto :eof
)
set tangleset=p01a p02a p03a p04a p05a p06a p07a p08a p09a p10a p11a p12a p13a p14a p15a p16a p17a p18a p19a p20a p21a p22a p23a p24a p25a
set tangleset=%tangleset% p01b p02b p03b p04b p05b p06b p07b p08b p09b p10b p11b p12b p13b p14b p15b p16b p17b p18b p19b p20b p21b p22b p23b p24b p25b
set tangleset=%tangleset% p01c p02c p03c p04c p05c p06c p07c p08c p09c p10c p11c p12c p13c p14c p15c p16c p17c p18c p19c p20c p21c p22c p23c p24c p25c
set tangleset=%tangleset% p01d p02d p03d p04d p05d p06d p07d p08d p09d p10d p11d p12d p13d p14d p15d p16d p17d p18d p19d p20d p21d p22d p23d p24d p25d
rem num01_r: right side - num01_l: left side - num01_b: bottom side (lower side) - num01_u: upper side
rem _r=%num01:~3,2% _l=%num01:~9,2% _b=%num01:~6,2% _u=%num01:~0,2%
if /i %1==/SEARCH (
if "%2"=="" goto :help1
if "%3"=="" goto :help1
set test=#
for %%t in (left right bottom upper) do if /i %%t==%2 set test=##
if !test!==# goto :help1
set test=#
rem Test if parameter %3 is color code or piece
for %%t in (YG YR YB GY GR GB RY RG RB BY BR BG) do if /i %%t==%3 set test=1##
if !test!==1## set hvar=%3
for %%t in (%tangleset%) do if /i %%t==%3 set test=2##
if !test!==# goto :help1
rem Find color code in piece
if !test!==2## (
set hvar2=!%3!
if /i "%2"=="left" set hvar=!hvar2:~3,2!
if /i "%2"=="right" set hvar=!hvar2:~9,2!
if /i "%2"=="bottom" set hvar=!hvar2:~0,2!
if /i "%2"=="upper" set hvar=!hvar2:~6,2!
)
set hvar2=#
if /i "%2"=="left" (
for %%A in (%tangleset%) do (
set help=!%%A:~9,2!
if /i "!hvar!"=="!help!" set hvar2=!hvar2! %%A
)
)
if /i "%2"=="right" (
for %%A in (%tangleset%) do (
set help=!%%A:~3,2!
if /i "!hvar!"=="!help!" set hvar2=!hvar2! %%A
)
)
if /i "%2"=="bottom" (
for %%A in (%tangleset%) do (
set help=!%%A:~6,2!
if /i "!hvar!"=="!help!" set hvar2=!hvar2! %%A
)
)
if /i "%2"=="upper" (
for %%A in (%tangleset%) do (
set help=!%%A:~0,2!
if /i "!hvar!"=="!help!" set hvar2=!hvar2! %%A
)
)
echo !hvar2:~2!
goto :eof
)
if /i %1==/RECOLOR (
if "%2"=="" goto :help2
if "%3"=="" goto :help2
rem Delete piece p25 from the variable TANGLESET, but not from the pieces
(set tangleset=!tangleset: p25a=!) & (set tangleset=!tangleset: p25b=!) & (set tangleset=!tangleset: p25c=!) & (set tangleset=!tangleset: p25d=!)
for /f "tokens=2*" %%a in ("%*") do (
set color=%%a
set pieceset=%%b
)
set test=OK
for %%a in (!color!) do echo #YGRB#YGBR#YRGB#YRBG#YBGR#YBRG#GYRB#GYBR#GRYB#GRBY#GBYR#GBRY#RYGB#RYBG#RGYB#RGBY#RBYG#RBGY#BYGR#BYRG#BGYR#BGRY#BRYG#BRGY# | find /i "#%%a#">nul || set test=notOK
if /i !test!==notOK goto :help2
call :TestPieces "!pieceset!" TestOK
if /i !TestOK!==notOK goto :help3
set num=#
for %%A in (!pieceset!) do (
set test=!%%A!
(set test=!test:Y=1!) & (set test=!test:G=2!) & (set test=!test:R=3!) & (set test=!test:B=4!)
for /f "tokens=1-4" %%E in ("!color:~0,1! !color:~1,1! !color:~2,1! !color:~3,1!") do (
(set test=!test:1=%%E!) & (set test=!test:2=%%F!) & (set test=!test:3=%%G!) & (set test=!test:4=%%H!)
)
set hvar=FALSE
for %%z in (!tangleset!) do (
set nump=!%%z!
if /i "!nump!"=="!test!" (set num=!num! %%z) & (set hvar=TRUE)
)
if !hvar!==FALSE set num=!num! %%A
)
echo !num:~2!
goto :eof
)
if /i %1==/FINDCOLOR (
if "%2"=="" goto :help3
if "%3"=="" goto :help3
call :TestPieces "%2 %3" TestOK
if /i !TestOK!==notOK goto :help3
rem Rotate the pieces in orientation pxxa
(set test=%2) & (set test=!test:~0,-1!a) & for %%A in (!test!) do set test1=!%%A!
(set test=%3) & (set test=!test:~0,-1!a) & for %%B in (!test!) do set test2=!%%B!
rem Changes the color code from piece 1 in a numerical code
(set test1=!test1:Y=1!) & (set test1=!test1:G=2!) & (set test1=!test1:R=3!) & (set test1=!test1:B=4!)
rem Addiction cords with the numbers 1 to 4 and takes over the color code of piece 2
rem The tokens correspond to the cord types: %%a = wave, %%b = rippon, %%c = bow, %%d = straight line
for /f "tokens=1-4" %%a in ("!test1:~10,1! !test1:~9,1! !test1:~0,1! !test1:~1,1!") do (
(if %%a==1 set color=!test2:~10,1!) & (if %%b==1 set color=!test2:~9,1!) & (if %%c==1 set color=!test2:~0,1!) & (if %%d==1 set color=!test2:~1,1!)
(if %%a==2 set color=!color!!test2:~10,1!) & (if %%b==2 set color=!color!!test2:~9,1!) & (if %%c==2 set color=!color!!test2:~0,1!) & (if %%d==2 set color=!color!!test2:~1,1!)
(if %%a==3 set color=!color!!test2:~10,1!) & (if %%b==3 set color=!color!!test2:~9,1!) & (if %%c==3 set color=!color!!test2:~0,1!) & (if %%d==3 set color=!color!!test2:~1,1!)
(if %%a==4 set color=!color!!test2:~10,1!) & (if %%b==4 set color=!color!!test2:~9,1!) & (if %%c==4 set color=!color!!test2:~0,1!) & (if %%d==4 set color=!color!!test2:~1,1!)
)
echo Color code: !color!
goto :eof
)
if /i %1==/ROTATE (
for /f "tokens=2,3*" %%a in ("%*") do (
set area=%%a
set rotcount=%%b
set "pset=%%c"
)
rem Reduces max four spaces to one space and test pieces
(set pset=!pset: = !) & (set pset=!pset: = !)
call :TestPieces "!pset!" TestOK
if /i !TestOK!==notOK goto :help3
set test=#
for %%a in (2x2 3x3 4x4 5x5) do if "%%a"=="!area!" set test=##
if !test!==# goto :help
set test=#
for %%a in (1 2 3) do if "%%a"=="!rotcount!" set test=##
if !test!==# goto :help
rem Changes the position of the pieces
if !area!==2x2 (
set test=!pset!###
set test=!test:~0,19!
if "!test!" neq "!pset!" goto :help3
if !rotcount!==1 set pset2=!pset:~5,4! !pset:~15,4! !pset:~0,4! !pset:~10,4!
if !rotcount!==2 set pset2=!pset:~15,4! !pset:~10,4! !pset:~5,4! !pset:~0,4!
if !rotcount!==3 set pset2=!pset:~10,4! !pset:~0,4! !pset:~15,4! !pset:~5,4!
)
if !area!==3x3 (
set test=!pset!###
set test=!test:~0,44!
if "!test!" neq "!pset!" goto :help3
if !rotcount!==1 set pset2=!pset:~10,4! !pset:~25,4! !pset:~40,4! !pset:~5,4! !pset:~20,4! !pset:~35,4! !pset:~0,4! !pset:~15,4! !pset:~30,4!
if !rotcount!==2 set pset2=!pset:~40,4! !pset:~35,4! !pset:~30,4! !pset:~25,4! !pset:~20,4! !pset:~15,4! !pset:~10,4! !pset:~5,4! !pset:~0,4!
if !rotcount!==3 set pset2=!pset:~30,4! !pset:~15,4! !pset:~0,4! !pset:~35,4! !pset:~20,4! !pset:~5,4! !pset:~40,4! !pset:~25,4! !pset:~10,4!
)
if !area!==4x4 (
set test=!pset!###
set test=!test:~0,79!
if "!test!" neq "!pset!" goto :help3
if !rotcount!==1 (
set pset2=!pset:~15,4! !pset:~35,4! !pset:~55,4! !pset:~75,4! !pset:~10,4! !pset:~30,4! !pset:~50,4! !pset:~70,4!
set pset2=!pset2! !pset:~5,4! !pset:~25,4! !pset:~45,4! !pset:~65,4! !pset:~0,4! !pset:~20,4! !pset:~40,4! !pset:~60,4!
)
if !rotcount!==2 (
set pset2=!pset:~75,4! !pset:~70,4! !pset:~65,4! !pset:~60,4! !pset:~55,4! !pset:~50,4! !pset:~45,4! !pset:~40,4!
set pset2=!pset2! !pset:~35,4! !pset:~30,4! !pset:~25,4! !pset:~20,4! !pset:~15,4! !pset:~10,4! !pset:~5,4! !pset:~0,4!
)
if !rotcount!==3 (
set pset2=!pset:~60,4! !pset:~40,4! !pset:~20,4! !pset:~0,4! !pset:~65,4! !pset:~45,4! !pset:~25,4! !pset:~5,4!
set pset2=!pset2! !pset:~70,4! !pset:~50,4! !pset:~30,4! !pset:~10,4! !pset:~75,4! !pset:~55,4! !pset:~35,4! !pset:~15,4!
)
)
if !area!==5x5 (
set test=!pset!###
set test=!test:~0,124!
if "!test!" neq "!pset!" goto :help3
if !rotcount!==1 (
set pset2=!pset:~20,4! !pset:~45,4! !pset:~70,4! !pset:~95,4! !pset:~120,4! !pset:~15,4! !pset:~40,4! !pset:~65,4!
set pset2=!pset2! !pset:~90,4! !pset:~115,4! !pset:~10,4! !pset:~35,4! !pset:~60,4! !pset:~85,4! !pset:~110,4! !pset:~5,4!
set pset2=!pset2! !pset:~30,4! !pset:~55,4! !pset:~80,4! !pset:~105,4! !pset:~0,4! !pset:~25,4! !pset:~50,4! !pset:~75,4! !pset:~100,4!
)
if !rotcount!==2 (
set pset2=!pset:~120,4! !pset:~115,4! !pset:~110,4! !pset:~105,4! !pset:~100,4! !pset:~95,4! !pset:~90,4! !pset:~85,4!
set pset2=!pset2! !pset:~80,4! !pset:~75,4! !pset:~70,4! !pset:~65,4! !pset:~60,4! !pset:~55,4! !pset:~50,4! !pset:~45,4!
set pset2=!pset2! !pset:~40,4! !pset:~35,4! !pset:~30,4! !pset:~25,4! !pset:~20,4! !pset:~15,4! !pset:~10,4! !pset:~5,4! !pset:~0,4!
)
if !rotcount!==3 (
set pset2=!pset:~100,4! !pset:~75,4! !pset:~50,4! !pset:~25,4! !pset:~0,4! !pset:~105,4! !pset:~80,4! !pset:~55,4!
set pset2=!pset2! !pset:~30,4! !pset:~5,4! !pset:~110,4! !pset:~85,4! !pset:~60,4! !pset:~35,4! !pset:~10,4! !pset:~115,4!
set pset2=!pset2! !pset:~90,4! !pset:~65,4! !pset:~40,4! !pset:~15,4! !pset:~120,4! !pset:~95,4! !pset:~70,4! !pset:~45,4! !pset:~20,4!
)
)
rem Changes the orientation of the pieces
(set pset2=!pset2:a=e!) & (set pset2=!pset2:b=f!) & (set pset2=!pset2:c=g!) & (set pset2=!pset2:d=h!)
if !rotcount!==1 ((set pset2=!pset2:e=b!) & (set pset2=!pset2:f=c!) & (set pset2=!pset2:g=d!) & (set pset2=!pset2:h=a!))
if !rotcount!==2 ((set pset2=!pset2:e=c!) & (set pset2=!pset2:f=d!) & (set pset2=!pset2:g=a!) & (set pset2=!pset2:h=b!))
if !rotcount!==3 ((set pset2=!pset2:e=d!) & (set pset2=!pset2:f=a!) & (set pset2=!pset2:g=b!) & (set pset2=!pset2:h=c!))
echo !pset2!
goto :eof
)
if /i %1==/TEST for %%z in (p01a p01b p01c p01d) do call :pierce_ %%z
(set tangleset=!tangleset: p25a=!) & (set tangleset=!tangleset: p25b=!) & (set tangleset=!tangleset: p25c=!) & (set tangleset=!tangleset: p25d=!)
if /i %1==/ALL for %%z in (%tangleset%) do call :pierce_ %%z
goto :eof
rem Find all combinations of a Tangle piece.
rem The arrangement of the parts: num01 num02
rem num03 num04
rem Output to the file or screen: num01 num02 num03 num04
:pierce_
rem Color code from piece 1 - right: %num01_r% - bottom: %num01_b%
(set num01_=%1) & (set num01=!%1!)
set num01_r=%num01:~3,2%
set num01_b=%num01:~6,2%
(set test1=%num01_%) & (set test1=!test1:~0,3!)
rem Search piece 2 - left: %num01_r%
set num02=#
for %%A in (%tangleset%) do (
set help=!%%A:~9,2!
(set test2=%%A) & (set test2=!test2:~0,3!)
if %num01_r% equ !help! set num02=!num02! %%A
)
set num02=%num02:~1%
rem Search piece 3 - up: %num01_b%
set num03=#
for %%A in (%tangleset%) do (
set help=!%%A:~0,2!
(set test3=%%A) & (set test3=!test3:~0,3!)
if %num01_b% equ !help! set num03=!num03! %%A
)
set num03=%num03:~1%
rem Piece 4 is a combination of 'piece 2 - buttom' and 'piece 3 - right'
for %%B in (%num02%) do for %%R in (%num03%) do (
set num02_b=!%%B:~6,2!
set num03_r=!%%R:~3,2!
(set num04=#) & (set test2=%%B) & (set test2=!test2:~0,3!) & (set test3=%%R) & (set test3=!test3:~0,3!)
for %%s in (%tangleset%) do (
set help1=!%%s:~0,2!
set help2=!%%s:~9,2!
(set test4=%%s) & (set test4=!test4:~0,3!)
if !num02_b! equ !help1! if !num03_r! equ !help2! (
rem Output to the file or screen
echo %num01_% %%B %%R %%s
)
)
)
goto :eof
:TestPieces
setlocal
set "hvar= %~1 "
(set hvar=!hvar:a = !) & (set hvar=!hvar:b = !) & (set hvar=!hvar:c = !) & (set hvar=!hvar:d = !) & (set hvar=!hvar: p= !)
set test=OK
for %%a in (%hvar%) do echo #00#01#02#03#04#05#06#07#08#09#10#11#12#13#14#15#16#17#18#19#20#21#22#23#24#25# | find "#%%a#">nul || set test=notOK
endlocal & set %2=%test%
exit /B
:: goto :eof
:help1
echo.
echo %0 - ERROR
echo.
echo %0 /SEARCH LEFT^|RIGHT^|BOTTOM^|UPPER cords^|piece
echo.
echo In the following example, a Tangle piece is wanted that color combination YR
echo should have on the left side.
echo The color combinations are two letters ^(Yellow, Green, Red, Blue^).
echo.
echo +---R--B---+ +---x--x---+
echo ^| ^| ^| ^| %0 /SEARCH LEFT YR
echo G Y Y x %0 /SEARCH LEFT p01a
echo ^| p01a ^| ^| p??? ^|
echo Y R R x
echo ^| ^| ^| ^| Easy to remember: LEFT is YR
echo +---G--B---+ +---x--x---+ LEFT is P01A
echo.
goto :eof
:help2
echo.
echo %0 - ERROR
echo.
echo %0 /RECOLOR code piece [piece ... piece]
echo.
echo The color code is one of this value:
echo YGRB YGBR YRGB YRBG YBGR YBRG GYRB GYBR GRYB GRBY GBYR GBRY
echo RYGB RYBG RGYB RGBY RBYG RBGY BYGR BYRG BGYR BGRY BRYG BRGY
echo.
goto :eof
:help3
echo.
echo %0 - ERROR
echo.
echo Any pieces are definated as: letter p, two digits, one letter ^(a, b, c, d^)
echo p01a, p01b, p01c, p01d, p02a, p02b ... p25a, p25b, p25c, p25d
echo Also possible are: p00a, p00b, p00c and p00d
echo.
echo For some parameters, a specific number of pieces needed.
echo 1 piece /PIECE
echo 2 pieces /FINDCOLOR
echo 4 pieces /PIECE4 and /ROTATE 2x2
echo 9 pieces /PIECE9 and /ROTATE 3x3
echo 16 pieces /PIECE16 and /ROTATE 4x4
echo 25 pieces /PIECE25 and /ROTATE 5x5
echo 1 or more pieces /RECOLOR
echo.
echo Use no more than four spaces between the pieces.
echo.
goto :eof
How can you expand from 2x2 pieces to 3x2 pieces?
Code: Select all
D:\CMDVerz>test54a /piece4 p01a p13a p17c p02b
p01a - RB YR GB GY
p13a - GB RG YB YR
p17c - GB RB GY YR
p02b - YB RG GY RB
+---R--B---+ +---G--B---+
| | | |
G Y Y R
| p01a | | p13a |
Y R R G
| | | |
+---G--B---+ +---Y--B---+
+---G--B---+ +---Y--B---+
| | | |
Y R R R
| p17c | | p02b |
R B B G
| | | |
+---G--Y---+ +---G--Y---+
D:\CMDVerz>findstr /i /r "p13a......p02b....." tangle_4p.txt
p13a p05b p02b p10a
p13a p05b p02b p07c
p13a p19b p02b p09a
p13a p19b p02b p12c
p13a p19b p02b p25c
p13a p07c p02b p23d
p13a p12c p02b p04d
p13a p25c p02b p04d
p13a p04d p02b p10a
p13a p04d p02b p07c
p13a p23d p02b p09a
p13a p23d p02b p12c
p13a p23d p02b p25c
D:\CMDVerz>test54a /piece4 p13a p05b p02b p10a
p13a - GB RG YB YR
p05b - YG RB BY RG
p02b - YB RG GY RB
p10a - BY GB RY RG
+---G--B---+ +---Y--G---+
| | | |
Y R R R
| p13a | | p05b |
R G G B
| | | |
+---Y--B---+ +---B--Y---+
+---Y--B---+ +---B--Y---+
| | | |
R R R G
| p02b | | p10a |
B G G B
| | | |
+---G--Y---+ +---R--Y---+
D:\CMDVerz>
Result is:
p01a p13a p05b
p17c p02b p10a
How can you expand from 2x2 pieces to 4x2 pieces?
Code: Select all
D:\CMDVerz>test54a /piece4 p01a p13a p17c p02b
p01a - RB YR GB GY
p13a - GB RG YB YR
p17c - GB RB GY YR
p02b - YB RG GY RB
+---R--B---+ +---G--B---+
| | | |
G Y Y R
| p01a | | p13a |
Y R R G
| | | |
+---G--B---+ +---Y--B---+
+---G--B---+ +---Y--B---+
| | | |
Y R R R
| p17c | | p02b |
R B B G
| | | |
+---G--Y---+ +---G--Y---+
D:\CMDVerz>test54a /search left RG
p09a
p10a
p05b
p19b
p07c
p12c
p25c
p04d
p23d
D:\CMDVerz>for %a in (p09a p10a p05b p19b p07c p12c p25c p04d p23d) do @for %b in (p09a p10a p05b p19b p07c p12c p25c p04d p23d) do @findstr /i /r "%a......%b....." tangle_4p.txt | findstr /v "p01 p13 p17 p02"
p05b p23a p10a p15d
p05b p24a p10a p22a
p05b p24a p10a p19c
p05b p22c p10a p21a
p05b p22c p10a p24c
p05b p23a p07c p16d
p19b p03a p09a p05c
p19b p04a p09a p16d
p19b p11b p09a p22d
p19b p10d p09a p22d
p19b p03a p12c p14b
p19b p04a p12c p15d
p19b p03a p25c p14b
p19b p04a p25c p15d
p07c p03c p23d p24b
p07c p05c p23d p18b
p07c p16d p23d p08a
p07c p16d p23d p09c
p07c p22d p23d p11c
p12c p14b p04d p11a
p12c p14b p04d p10c
p12c p24c p04d p03b
p12c p15d p04d p11a
p12c p15d p04d p10c
p25c p14b p04d p11a
p25c p14b p04d p10c
p25c p24c p04d p03b
p25c p15d p04d p11a
p25c p15d p04d p10c
p04d p03b p10a p22a
p04d p03b p10a p19c
p04d p08c p10a p14b
p04d p06d p10a p22a
p04d p06d p10a p19c
p04d p11a p07c p03c
p04d p12a p07c p23b
p04d p25a p07c p23b
p04d p08c p07c p05c
p23d p18b p09a p03c
p23d p24b p09a p05c
p23d p14d p09a p03c
p23d p20d p09a p05c
p23d p07a p12c p04b
p23d p08a p12c p21a
p23d p08a p12c p24c
p23d p24b p12c p14b
p23d p11c p12c p22a
p23d p11c p12c p19c
p23d p20d p12c p14b
p23d p07a p25c p04b
p23d p08a p25c p21a
p23d p08a p25c p24c
p23d p24b p25c p14b
p23d p11c p25c p22a
p23d p11c p25c p19c
p23d p20d p25c p14b
D:\CMDVerz>test54a /piece4 p05b p23a p10a p15d
p05b - YG RB BY RG
p23a - YG BY RG RB
p10a - BY GB RY RG
p15d - RG YB YR GB
+---Y--G---+ +---Y--G---+
| | | |
R R R B
| p05b | | p23a |
G B B Y
| | | |
+---B--Y---+ +---R--G---+
+---B--Y---+ +---R--G---+
| | | |
R G G Y
| p10a | | p15d |
G B B B
| | | |
+---R--Y---+ +---Y--R---+
D:\CMDVerz>
Result is:
p01a p13a p05b p23a
p17c p02b p10a p15d
In the FOR loop, the same values were used for both variables here, because both have Tangle pieces on the left side the color combination RG (Red, Green).
Code: Select all
In the search string is not a space character.
(1) findstr /i /r "p13a.p05b.p02b.p10a" tangle_4p.txt
(2) findstr /i /r "p13a......p02b....." tangle_4p.txt
(3) findstr /i /r "%a......%b....." tangle_4p.txt
(4) findstr /i /r "p13a.p05b.........." tangle_4p.txt
(1) Find only one result.
(2) Find any Tangle piece combinations with p13a and p02b at the left side.
(3) Same as (2). But with the variable %a and %b.
(4) Find any Tangle piece combinations with p13a and p05b at the upper side.
The examples show only one of the combinations.
With the expansion of 2x2 to 4x2 there are 56 combinations. I think the extension to 2x4 will come to a similar number of combinations.
There are many combinations to consider.
Last edited by trebor68 on 05 May 2015 05:06, edited 3 times in total.
Re: Working out permutations
I found a mistake of causing a problem on the issue with parameter /ALL and /TEST. This error has occurred in the area /SEARCH.
Now the problem is solved.
Now the problem is solved.
Re: Working out permutations
I've read your source, and i have some notes, because as i'd said above, that one should use math to find a simpler equivalent mathematical description.
Maybe it is not immediately obvious, what i wanted to say with that:
Your batch is a nice work and it solves the OP task, but the problem stays that the computation of a 5x5 tangle costs a lot of time (you are using nearly the same bruteforce method, that the OP has asked for, so it is not much faster).
Although i haven't tested it, i assume that even if you are using c++ instead of batch for your algorithm, it would take (at minimum) hours or days to solve the complete task that way (using batch it would take days or weeks).
1) I don't see the system behind the naming of the pieces (A to Y; although this seems to be more "optical"):
I think, you don't you use normed pieces.
If that uis true, then you may use a notation like the following (similar to yours) to simplify applying math on these pieces:
So all pieces (with real and virtual colors; rotated to all directions) are:
2) if i see it right, you are searching brute force for fitting pieces.
That is suboptimal because there are always only 8 pieces (with one special orientation) fitting to a given side of another piece.
In virtual colors (in my above notation) all pieces fitting to the top of piece 1234 (in all directions) are:
- 12345 ==> 21347 21437 23415 24315 32148 34216 42138 43216
- 12346 ==> 13248 14326 31425 32147 32417 34125 41326 43218
- 12347 ==> 23416 24138 32416 34128 41237 41327 42315 43215
- 12348 ==> 12436 14328 21436 24318 41235 42135 43127 43217
Because you are able to assign any color combination to the virtual colors you could create an algorithm to compute all pieces (with orientation) that are fitting to a given side of a given piece (with orientation; i hope ther is no flaw):
This only speeds up your algorithm by factor ~12.
3) If you don't use an initial color mapping (so you are only working with virtual colors) you again could speed up your algorithm by reducing the search space by the factor ~24.
Just assume your first piece (no matter where you are starting) is 1234, so you only need to search for pieces fitting to 12345, 12346, 12347, or 12348 (and not all "real colored" 96 pieces).
The real colors could be mapped as a last step.
Although i haven't searched for more i'm sure that you could simplify the problem a lot (i doubt that Ernő Rubik didn't use a mathematical model for: select the doubled card, select the tangle card, ...).
penpen
Maybe it is not immediately obvious, what i wanted to say with that:
Your batch is a nice work and it solves the OP task, but the problem stays that the computation of a 5x5 tangle costs a lot of time (you are using nearly the same bruteforce method, that the OP has asked for, so it is not much faster).
Although i haven't tested it, i assume that even if you are using c++ instead of batch for your algorithm, it would take (at minimum) hours or days to solve the complete task that way (using batch it would take days or weeks).
1) I don't see the system behind the naming of the pieces (A to Y; although this seems to be more "optical"):
Why not using A (for piece 01) to X (for piece 24) and use Y for the doubled piece.trebor68 wrote:Code: Select all
rem piece 01 02 03...
rem 1234 1243 1324...
rem color YGRB YGBR YRGB ...
rem Tangle_1 M C E...
rem Tangle_2 U V R...
rem Tangle_3 Q N R...
rem Tangle_4 W B R...
I think, you don't you use normed pieces.
If that uis true, then you may use a notation like the following (similar to yours) to simplify applying math on these pieces:
Code: Select all
possible colors: blue, green, red, yellow
abstract colors: 1, 2, 3, 4
piece default orientation: (cmd shell window rasterfont 8x12 or similar; top heads north)
north
┌───────────────────────────────────────┐
│ ░░░ top ▒▒▒ │
│ ░░░ ▒▒▒ │
│ ░░░███████████████ │
│ ░░░███████████████ │
│ ██████░░░ ▒▒▒ ███ │
│ ██████░░░ ▒▒▒ ███ │
│ ███ ░░░ ▒▒▒ ███ │
│ ███ ░░░ ▒▒▒ ███ │
│▓▓▓▓▓▓███▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓│
│▓▓▓▓▓▓███▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓│
│ ███ ░░░ ▒▒▒ ███ │
west│left ███ ░░░ ▒▒▒ ███ right│east
│ ███ ░░░▒▒▒ ███ │
│ ███ ░░░▒▒▒ ███ │
│ ███ ▒▒▒▒▒▒░░░ ███ │
│ ███ ▒▒▒▒▒▒░░░ ███ │
│▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ░░░ ██████│
│▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ░░░ ██████│
│ ███ ░░░ │
│ ███ ░░░ │
│ ███ ░░░ │
│ ███ ░░░ │
│ ███ ░░░ │
│ ███ ░░░ │
│ ███ ░░░ │
│ ███ bottom ░░░ │
└───────────────────────────────────────┘
south
' ' background
'▒' color 1
'#' color 2
'▓' color 3
'█' color 4
rotation id (avoid abstract color names):
5 : rotated clockwise by 0 degree (top heads north)
6 : rotated clockwise by 90 degree (top heads east)
7 : rotated clockwise by 180 degree (top heads south)
8 : rotated clockwise by 270 degree (top heads west)
So all pieces (with real and virtual colors; rotated to all directions) are:
Code: Select all
pieces (real colors):
bgry bgyr brgy bryg bygr byrg
gbry gbyr grby gryb gybr gyrb
rbgy rbyg rgby rgyb rybg rygb
ybgr ybrg ygbr ygrb yrbg yrgb
doubled pieces:
- bgyr within pack type A
- gryb within pack type B
- rbgy within pack type C
- rybg within pack type D
pieces (virtual colors: used to abstract from one piece):
1234 1243 1324 1342 1423 1432
2134 2143 2314 2341 2413 2431
3124 3142 3214 3241 3412 3421
4123 4132 4213 4231 4312 4321
pieces with orientations (virtual colors):
12345 12435 13245 13425 14235 14325
21345 21435 23145 23415 24135 24315
31245 31425 32145 32415 34125 34215
41235 41325 42135 42315 43125 43215
12346 12436 13246 13426 14236 14326
21346 21436 23146 23416 24136 24316
31246 31426 32146 32416 34126 34216
41236 41326 42136 42316 43126 43216
12347 12437 13247 13427 14237 14327
21347 21437 23147 23417 24137 24317
31247 31427 32147 32417 34127 34217
41237 41327 42137 42317 43127 43217
12348 12438 13248 13428 14238 14328
21348 21438 23148 23418 24138 24318
31248 31428 32148 32418 34128 34218
41238 41328 42138 42318 43128 43218
2) if i see it right, you are searching brute force for fitting pieces.
That is suboptimal because there are always only 8 pieces (with one special orientation) fitting to a given side of another piece.
In virtual colors (in my above notation) all pieces fitting to the top of piece 1234 (in all directions) are:
- 12345 ==> 21347 21437 23415 24315 32148 34216 42138 43216
- 12346 ==> 13248 14326 31425 32147 32417 34125 41326 43218
- 12347 ==> 23416 24138 32416 34128 41237 41327 42315 43215
- 12348 ==> 12436 14328 21436 24318 41235 42135 43127 43217
Because you are able to assign any color combination to the virtual colors you could create an algorithm to compute all pieces (with orientation) that are fitting to a given side of a given piece (with orientation; i hope ther is no flaw):
Code: Select all
@echo off
:: initialize
setlocal enabledelayedExpansion
set /A "north=top=5", "east=right=6", "bottom=south=7", "west=left=8"
set "fit[12345]=21347 21437 23415 24315 32148 34216 42138 43216"
set "fit[12346]=13248 14326 31425 32147 32417 34125 41326 43218"
set "fit[12347]=23416 24138 32416 34128 41237 41327 42315 43215"
set "fit[12348]=12436 14328 21436 24318 41235 42135 43127 43217"
:: example piece colored with rgby, top heading south; appending to west
set "piece=rgby%south%"
set "appendTo=%west%"
:: algorithm (for any piece and direction)
set "orientations=8567856785678"
:: step 1: rotate enviroment by alpha (appendTo heads north)
set /A "o=%piece:~4,1%-appendTo+5"
set "o=!orientations:~%o%,1!"
:: step 2: rotate enviroment by -alpha (restore original orientation)
set "fit= "
for %%a in (!fit[1234%o%]!) do (
set "append=%%~a"
set /A "o=!append:~4,1!+appendTo-5"
for %%o in ("!o!") do set "o=!orientations:~%%~o,1!"
set "fit=!fit!!append:~0,4!!o! "
)
echo(fit_1234%piece:~4,1%_%appendTo% := {%fit%}
set "fit=!fit:1=%piece:~0,1%!"
set "fit=!fit:2=%piece:~1,1%!"
set "fit=!fit:3=%piece:~2,1%!"
set "fit=!fit:4=%piece:~3,1%!"
:: end of algorithm
echo(fit_%piece%_%appendTo% := {%fit%}
endlocal
goto :eof
3) If you don't use an initial color mapping (so you are only working with virtual colors) you again could speed up your algorithm by reducing the search space by the factor ~24.
Just assume your first piece (no matter where you are starting) is 1234, so you only need to search for pieces fitting to 12345, 12346, 12347, or 12348 (and not all "real colored" 96 pieces).
The real colors could be mapped as a last step.
Although i haven't searched for more i'm sure that you could simplify the problem a lot (i doubt that Ernő Rubik didn't use a mathematical model for: select the doubled card, select the tangle card, ...).
penpen
Re: Working out permutations
I have extended the Code (see above).
The coding of the pieces 01 to 24 corresponds to my logical system. The piece 25 is the double piece that is present in the respective version of Tangle.
The orientation of the pieces is characterized by the following letter. The piece 00 is used only as a dummy.
p01a: piece 01 with orientation a
The internal format from piece p01a is: "RB YR GB GY"
Here piece 01 in all orientations (Yellow = wave, Green = rippon, Red = bow, Blue = straight line).
The letter code (A through Y) have been printed on the back of the Tangle pieces. Each Tangle 1 to 4 had its own coding.
Here are the steps to solve the Tangle.
Step 1 - Create all combinations with 2x2 pieces
Only the pieces 01 to 24 uses. The pieces can also be present more than once.
Step 2 - Create all combinations with 3x3 pieces
Only the pieces 01 to 24 uses. The pieces can also be present more than once.
The code is in only one line (no line breaks).
Step 3 - Creating nine different files (with 3x3 pieces)
The files differing only in the position of the piece p01a (part 01 in orientation a).
The piece p01a is selected for the center from 5x5 Tangle.
The color coding of the pieces will be changed later. The orientation can be changed later.
Here to understand:
Here are the commands:
Step 4 - Creating four different files (with 4x4 pieces)
The files differing only in the position of the piece p01a (part 01 in orientation a).
The piece p01a is selected for the center from 5x5 Tangle.
The color coding of the pieces will be changed later. The orientation can be changed later.
Here to understand:
Here are the commands:
Step 5 - Reduction of combinations (4x4 pieces)
Create a temporary file with the combinations of two duplicate pieces and triple or more existing pieces. Thereafter, the combinations are determined, which are not present in the temporary file.
Now only combinations are available which consist of 16 different pieces or consist of 15 different pieces, one of the pieces is double.
Step 6 - Creating one file (with 5x5 pieces)
The files differing only in the position of the piece p01a (part 01 in orientation a).
The piece p01a is selected for the center from 5x5 Tangle.
The color coding of the pieces will be changed later. The orientation can be changed later.
Step 7 - Reduction of combinations (5x5 pieces)
Create a temporary file with the combinations of two duplicate pieces and triple or more existing pieces. Thereafter, the combinations are determined, which are not present in the temporary file.
Now only combinations are available which consist all 24 pieces, one of the pieces is double.
Step 8 - Calculate color code and change pieces
In each line is a duplicated piece (the orientation does not matter).
Here a example with duplicated piece p03.
Search color code will change from p03d to p25d.
With the color code change all pieces. Here are the results of Tangle 1 appears (p25 corresponds p12). Now one of the pieces of P12 can be renamed in p25, but not change the following letter (orientation: a, b, c, d)
Here one result:
With the duplicated piece p08 can find the color code BGYR.
The coding of the pieces 01 to 24 corresponds to my logical system. The piece 25 is the double piece that is present in the respective version of Tangle.
The orientation of the pieces is characterized by the following letter. The piece 00 is used only as a dummy.
p01a: piece 01 with orientation a
The internal format from piece p01a is: "RB YR GB GY"
Here piece 01 in all orientations (Yellow = wave, Green = rippon, Red = bow, Blue = straight line).
Code: Select all
D:\CMDVerz\Tangle2>tangle2 /piece4 p01a p01b p01c p01d
+---R--B---+ +---Y--R---+
| | | |
G Y B B
| p01a | | p01b |
Y R R G
| | | |
+---G--B---+ +---G--Y---+
+---B--G---+ +---Y--G---+
| | | |
R Y G R
| p01c | | p01d |
Y G B B
| | | |
+---B--R---+ +---R--Y---+
The letter code (A through Y) have been printed on the back of the Tangle pieces. Each Tangle 1 to 4 had its own coding.
Here are the steps to solve the Tangle.
Step 1 - Create all combinations with 2x2 pieces
Only the pieces 01 to 24 uses. The pieces can also be present more than once.
Code: Select all
Tangle2 /all>Tangle_4p.txt
Step 2 - Create all combinations with 3x3 pieces
Only the pieces 01 to 24 uses. The pieces can also be present more than once.
The code is in only one line (no line breaks).
Code: Select all
for /f "tokens=1-4" %a in (tangle_4p.txt) do @for /f "tokens=1-4" %e in ('findstr /i /r "%b......%d....." tangle_4p.txt') do @for /f "tokens=1-4" %i in ('findstr /i /r "%c.%d.........." tangle_4p.txt') do @for /f "tokens=1-4" %m in ('findstr /i /r "%d.%h.%l....." tangle_4p.txt') do @echo %a %b %f %c %d %h %k %l %p>>Tangle_9p.txt
Step 3 - Creating nine different files (with 3x3 pieces)
The files differing only in the position of the piece p01a (part 01 in orientation a).
The piece p01a is selected for the center from 5x5 Tangle.
The color coding of the pieces will be changed later. The orientation can be changed later.
Here to understand:
Code: Select all
A1 B1 C1 D1 E1
A2 B2 C2 D2 E2
A3 B3 C3 D3 E3 C3 = p01a
A4 B4 C4 D4 E4
A5 B5 C5 D5 E5
9pOL = A1:C3 9pOM = B1:D3 9pOR = C1:E3 These nine values are used as identification of files.
9pML = A2:C4 9pMM = B2:D4 9pMR = C2:E4
9pUL = A3:C5 9pUM = B3:D5 9pUR = C3:E5
Here are the commands:
Code: Select all
findstr /i /r "........................................p01a" Tangle_9p.txt>>Tangle_9pOL.txt
findstr /i /r "...................................p01a....." Tangle_9p.txt>>Tangle_9pOM.txt
findstr /i /r "..............................p01a.........." Tangle_9p.txt>>Tangle_9pOR.txt
findstr /i /r ".........................p01a..............." Tangle_9p.txt>>Tangle_9pML.txt
findstr /i /r "....................p01a...................." Tangle_9p.txt>>Tangle_9pMI.txt
findstr /i /r "...............p01a........................." Tangle_9p.txt>>Tangle_9pMR.txt
findstr /i /r "..........p01a.............................." Tangle_9p.txt>>Tangle_9pUL.txt
findstr /i /r ".....p01a..................................." Tangle_9p.txt>>Tangle_9pUM.txt
findstr /i /r "p01a........................................" Tangle_9p.txt>>Tangle_9pUR.txt
Step 4 - Creating four different files (with 4x4 pieces)
The files differing only in the position of the piece p01a (part 01 in orientation a).
The piece p01a is selected for the center from 5x5 Tangle.
The color coding of the pieces will be changed later. The orientation can be changed later.
Here to understand:
Code: Select all
A1 B1 C1 D1 E1
A2 B2 C2 D2 E2
A3 B3 C3 D3 E3 C3 = p01a
A4 B4 C4 D4 E4
A5 B5 C5 D5 E5
16pOL = A1:D4 16pOR = B1:E4 These four values are used as identification of files.
16pUL = A2:D5 16pUR = B2:E5
Here are the commands:
Code: Select all
for /f "tokens=1-9" %a in (Tangle_9pOL.txt) do @for /f "tokens=1-9" %j in ('findstr /i /r "%b.%c......%e.%f......%h.%i....." Tangle_9pOM.txt') do @for /f "tokens=1-9" %A in ('findstr /i /r "%d.%e.%f.%g.%h.%i..............." tangle_9pML.txt') do @for /f "tokens=1-9" %J in ('findstr /i /r "%e.%f.%o.%h.%i.%r.%H.%I....." tangle_9pMM.txt') do @echo %a %b %c %l %d %e %f %o %g %h %i %r %G %H %I %R>>Tangle_16pOL.txt
for /f "tokens=1-9" %a in (Tangle_9pOM.txt) do @for /f "tokens=1-9" %j in ('findstr /i /r "%b.%c......%e.%f......%h.%i....." Tangle_9pOR.txt') do @for /f "tokens=1-9" %A in ('findstr /i /r "%d.%e.%f.%g.%h.%i..............." tangle_9pMM.txt') do @for /f "tokens=1-9" %J in ('findstr /i /r "%e.%f.%o.%h.%i.%r.%H.%I....." tangle_9pMR.txt') do @echo %a %b %c %l %d %e %f %o %g %h %i %r %G %H %I %R>>Tangle_16pOR.txt
for /f "tokens=1-9" %a in (Tangle_9pML.txt) do @for /f "tokens=1-9" %j in ('findstr /i /r "%b.%c......%e.%f......%h.%i....." Tangle_9pMM.txt') do @for /f "tokens=1-9" %A in ('findstr /i /r "%d.%e.%f.%g.%h.%i..............." tangle_9pUL.txt') do @for /f "tokens=1-9" %J in ('findstr /i /r "%e.%f.%o.%h.%i.%r.%H.%I....." tangle_9pUM.txt') do @echo %a %b %c %l %d %e %f %o %g %h %i %r %G %H %I %R>>Tangle_16pUL.txt
for /f "tokens=1-9" %a in (Tangle_9pMM.txt) do @for /f "tokens=1-9" %j in ('findstr /i /r "%b.%c......%e.%f......%h.%i....." Tangle_9pMR.txt') do @for /f "tokens=1-9" %A in ('findstr /i /r "%d.%e.%f.%g.%h.%i..............." tangle_9pUM.txt') do @for /f "tokens=1-9" %J in ('findstr /i /r "%e.%f.%o.%h.%i.%r.%H.%I....." tangle_9pUR.txt') do @echo %a %b %c %l %d %e %f %o %g %h %i %r %G %H %I %R>>Tangle_16pUR.txt
Step 5 - Reduction of combinations (4x4 pieces)
Create a temporary file with the combinations of two duplicate pieces and triple or more existing pieces. Thereafter, the combinations are determined, which are not present in the temporary file.
Now only combinations are available which consist of 16 different pieces or consist of 15 different pieces, one of the pieces is double.
Code: Select all
set tangle=01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
for %a in (%tangle%) do @for %b in (%tangle%) do @if "%a" neq "%b" findstr /i /r "%a.*%a.*%b.*%b %a.*%b.*%a.*%b %a.*%b.*%b.*%a %a.*%a.*%a" Tangle_16pOL.txt >>T_OL.tmp
findstr /v /g:T_OL.tmp Tangle_16pOL.txt >Tangle_16pOL#.txt
for %a in (%tangle%) do @for %b in (%tangle%) do @if "%a" neq "%b" findstr /i /r "%a.*%a.*%b.*%b %a.*%b.*%a.*%b %a.*%b.*%b.*%a %a.*%a.*%a" Tangle_16pOR.txt >>T_OR.tmp
findstr /v /g:T_OR.tmp Tangle_16pOR.txt >Tangle_16pOR#.txt
for %a in (%tangle%) do @for %b in (%tangle%) do @if "%a" neq "%b" findstr /i /r "%a.*%a.*%b.*%b %a.*%b.*%a.*%b %a.*%b.*%b.*%a %a.*%a.*%a" Tangle_16pUL.txt >>T_UL.tmp
findstr /v /g:T_UL.tmp Tangle_16pUL.txt >Tangle_16pUL#.txt
for %a in (%tangle%) do @for %b in (%tangle%) do @if "%a" neq "%b" findstr /i /r "%a.*%a.*%b.*%b %a.*%b.*%a.*%b %a.*%b.*%b.*%a %a.*%a.*%a" Tangle_16pUR.txt >>T_UR.tmp
findstr /v /g:T_UR.tmp Tangle_16pUR.txt >Tangle_16pUR#.txt
Step 6 - Creating one file (with 5x5 pieces)
The files differing only in the position of the piece p01a (part 01 in orientation a).
The piece p01a is selected for the center from 5x5 Tangle.
The color coding of the pieces will be changed later. The orientation can be changed later.
Code: Select all
for /f "delims=" %a in (Tangle_16pOL#.txt) do @(set i=%a) & @for /f "delims=" %b in ('findstr /i /r "!i:~5,4!.!i:~10,4!.!i:~15,4!......!i:~25,4!.!i:~30,4!.!i:~35,4!......!i:~45,4!.!i:~50,4!.!i:~55,4!......!i:~65,4!.!i:~70,4!.!i:~75,4!....." Tangle_16pOR#.txt') do @(set k=%b) & @for /f "delims=" %c in ('findstr /i /r "!i:~20,4!.!i:~25,4!.!i:~30,4!.!i:~35,4!.!i:~40,4!.!i:~45,4!.!i:~50,4!.!i:~55,4!.!i:~60,4!.!i:~65,4!.!i:~70,4!.!i:~75,4!...................." Tangle_16pUL#.txt') do @(set l=%c) & @for /f "delims=" %d in ('findstr /i /r "!i:~25,4!.!i:~30,4!.!i:~35,4!.!k:~35,4!.!i:~45,4!.!i:~50,4!.!i:~55,4!.!k:~55,4!.!i:~65,4!.!i:~70,4!.!i:~75,4!.!k:~75,4!.!l:~65,4!.!l:~70,4!.!l:~75,4!....." Tangle_16pUR#.txt') do @(set m=%d) & @echo !i:~0,4! !i:~5,4! !i:~10,4! !i:~15,4! !k:~15,4! !i:~20,4! !i:~25,4! !i:~30,4! !i:~35,4! !k:~35,4! !i:~40,4! !i:~45,4! !i:~50,4! !i:~55,4! !k:~55,4! !i:~60,4! !i:~65,4! !i:~70,4! !i:~75,4! !k:~75,4! !l:~60,4! !l:~65,4! !l:~70,4! !l:~75,4! !m:~75,4!>>Tangle_25p.txt
Step 7 - Reduction of combinations (5x5 pieces)
Create a temporary file with the combinations of two duplicate pieces and triple or more existing pieces. Thereafter, the combinations are determined, which are not present in the temporary file.
Now only combinations are available which consist all 24 pieces, one of the pieces is double.
Code: Select all
set tangle=01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
for %a in (%tangle%) do @for %b in (%tangle%) do @if "%a" neq "%b" findstr /i /r "%a.*%a.*%b.*%b %a.*%b.*%a.*%b %a.*%b.*%b.*%a %a.*%a.*%a" Tangle_25p.txt >>T_25.tmp
findstr /v /g:T_25.tmp Tangle_25p.txt >Tangle_25p#.txt
Step 8 - Calculate color code and change pieces
In each line is a duplicated piece (the orientation does not matter).
Here a example with duplicated piece p03.
Search color code will change from p03d to p25d.
With the color code change all pieces. Here are the results of Tangle 1 appears (p25 corresponds p12). Now one of the pieces of P12 can be renamed in p25, but not change the following letter (orientation: a, b, c, d)
Code: Select all
tangle2 /findcolor p03d p25d
Color code: GRBY
tangle2 /recolor GRBY p09c p02d p18a p04d p17d p21b p07c p23b p16a p03d p12d p24d p01a p08d p14c p20a p11d p13a p19b p06c p22c p03b p05d p15a p10d
p18c p09d p20a p11d p19d p03b p16c p05b p23a p12d p14d p06d p10a p15d p21c p02a p13d p22a p01b p08c p04c p12b p07d p24a p17d
Here one result:
Code: Select all
tangle2 /piece25 p18c p09d p20a p11d p19d p03b p16c p05b p23a p12d p14d p06d p10a p15d p21c p02a p13d p22a p01b p08c p04c p25b p07d p24a p17d
With the duplicated piece p08 can find the color code BGYR.
Re: Working out permutations
I have optimized the steps.
The code above is required in the following batch file. Please save the file as Tangle2.bat.
The following code creates the necessary files and saves the solution to a file (Solution.txt).
Some ideas to improve (accelerate) the codes come from penpen.
Here the output with time code:
The code above is required in the following batch file. Please save the file as Tangle2.bat.
The following code creates the necessary files and saves the solution to a file (Solution.txt).
Some ideas to improve (accelerate) the codes come from penpen.
Code: Select all
@echo off
setlocal EnableExtensions EnableDelayedExpansion
set num=01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
if not exist Tangle2.bat (
echo ERROR - Tangle2.bat is not exist.
echo.
goto :eof
)
if not "%1"=="" goto %1
:step1
echo.
time /t
echo Step 1: Search all combinations for 2x2 Tangle
call tangle2 /all >Tangle_4p.txt
time /t
:step2
if /i "%1"=="step2" (echo.) & (time /t)
echo Step 2: Search all combinations for 3x2 Tangle
for /f "tokens=1-4" %%a in (Tangle_4p.txt) do (
for /f "tokens=1-4" %%e in ('findstr /i /r "%%b......%%d....." Tangle_4p.txt') do echo %%a %%b %%f %%c %%d %%h>>Tangle_6p.txt
)
time /t
:step3
if /i "%1"=="step3" (echo.) & (time /t)
echo Step 3: Search combinations for 3x3 Tangle
echo Sufficient for a 5x5 Tangle with p01a in the center.
echo.
echo Make 3x3 Tangle that is in top left corner in 5x5 Tangle.
for /f "tokens=1-6" %%a in ('findstr /i /r /e "p01a" Tangle_6p.txt') do (
for /f "tokens=1-6" %%g in ('findstr /i /r /e "%%a.%%b.%%c" Tangle_6p.txt') do echo %%g %%h %%i %%a %%b %%c %%d %%e %%f>>Tangle_9pTL.txt
)
echo Make 3x3 Tangle that is in top right corner in 5x5 Tangle.
for /f "tokens=1-6" %%a in ('findstr /i /r /e "p01a.........." Tangle_6p.txt') do (
for /f "tokens=1-6" %%g in ('findstr /i /r /e "%%a.%%b.%%c" Tangle_6p.txt') do echo %%g %%h %%i %%a %%b %%c %%d %%e %%f>>Tangle_9pTR.txt
)
echo Make 3x3 Tangle that is in bottom left corner in 5x5 Tangle.
for /f "tokens=1-6" %%a in ('findstr /i /r /b "..........p01a" Tangle_6p.txt') do (
for /f "tokens=1-6" %%g in ('findstr /i /r /b "%%d.%%e.%%f" Tangle_6p.txt') do echo %%a %%b %%c %%d %%e %%f %%j %%k %%l>>Tangle_9pBL.txt
)
echo Make 3x3 Tangle that is in bottom right corner in 5x5 Tangle.
for /f "tokens=1-6" %%a in ('findstr /i /r /b "p01a" Tangle_6p.txt') do (
for /f "tokens=1-6" %%g in ('findstr /i /r /b "%%d.%%e.%%f" Tangle_6p.txt') do echo %%a %%b %%c %%d %%e %%f %%j %%k %%l>>Tangle_9pBR.txt
)
time /t
:step4
if /i "%1"=="step4" (echo.) & (time /t)
echo Step 4: Optimized files for 3x3 Tangle
call :optimizefile Tangle_9pTL.txt Tangle_9pTL#.txt
call :optimizefile Tangle_9pTR.txt Tangle_9pTR#.txt
call :optimizefile Tangle_9pBL.txt Tangle_9pBL#.txt
call :optimizefile Tangle_9pBR.txt Tangle_9pBR#.txt
time /t
:step5
if /i "%1"=="step5" (echo.) & (time /t)
echo Step 5: Search combinations for 5x3 Tangle
for /f "tokens=1-9" %%a in (Tangle_9pTL#.txt) do (
for /f "tokens=1-9" %%j in ('findstr /i /r "%%c...........%%f...........%%i.........." Tangle_9pTR#.txt') do (
echo %%a %%b %%c %%k %%l %%d %%e %%f %%n %%o %%g %%h %%i %%q %%r>>Tangle_15pU.txt
)
)
for /f "tokens=1-9" %%a in (Tangle_9pBL#.txt) do (
for /f "tokens=1-9" %%j in ('findstr /i /r "%%c...........%%f...........%%i.........." Tangle_9pBR#.txt') do (
echo %%a %%b %%c %%k %%l %%d %%e %%f %%n %%o %%g %%h %%i %%q %%r>>Tangle_15pB.txt
)
)
time /t
:step6
if /i "%1"=="step6" (echo.) & (time /t)
echo Step 6: Optimized files for 5x3 Tangle
echo.
echo Optimized 5x3 Tangle is in top in 5x5 Tangle.
call :optimizefile Tangle_15pU.txt Tangle_15pU#.txt
echo Optimized 5x3 Tangle is in bottom in 5x5 Tangle.
call :optimizefile Tangle_15pB.txt Tangle_15pB#.txt
time /t
:step7
if /i "%1"=="step7" (echo.) & (time /t)
echo Step 7: Search combinations for 5x5 Tangle with p01a in the center
for /f "tokens=1-15" %%a in (Tangle_15pU#.txt) do (
for /f "tokens=1-15" %%A in ('findstr /i /r /b "%%k.%%l.%%m.%%n.%%o" Tangle_15pB#.txt') do (
echo %%a %%b %%c %%d %%e %%f %%g %%h %%i %%j %%k %%l %%m %%n %%o %%F %%G %%H %%I %%J %%K %%L %%M %%N %%O>>Tangle_25p.txt
)
)
time /t
:step8
if /i "%1"=="step8" (echo.) & (time /t)
echo Step 8: Optimized files for 5x5 Tangle
call :optimizefile Tangle_25p.txt Tangle_25p#.txt
time /t
:step9
if /i "%1"=="step9" (echo.) & (time /t)
echo Step 9: Change color
for /f "delims=" %%a in (Tangle_25p#.txt) do (
for %%b in (%num%) do (
set ich=%%a
set ich=!ich:%%b=#!
for /f "tokens=1-4 delims=#" %%A in ("!ich!") do if "%%C" neq "" set double=%%b
)
for /f "tokens=3" %%f in ('call Tangle2 /findcolor p!double!a p25a') do set color=%%f
for /f "delims=" %%r in ('call Tangle2 /recolor !color! %%a') do set var=%%r
rem Change one of the duplicate pieces to p25
for %%b in (%num%) do (
set ich=!var!
set ich=!ich:%%b=#!
for /f "tokens=1-4 delims=#" %%A in ("!ich!") do if "%%C" neq "" set hvar=%%A%%b%%B25%%C
)
rem echo "!hvar!"
call Tangle2 /piece25 !hvar!>>Solution.txt
echo.>>Solution.txt
echo #####>>Solution.txt
echo.>>Solution.txt
)
echo.
echo The solution is saved in Solution.txt.
time /t
goto :eof
rem Optimize the file by removing rows with two double pieces and rows with three or more equal pieces
:optimizefile
setlocal
rem set num=01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
for %%a in (%num%) do findstr /r "%%a.*%%a.*%%a" %1>>T_3.tmp
for %%a in (%num%) do findstr /r "%%a.*%%a" %1>>T_2.tmp
findstr /v /g:T_2.tmp %1 >T_1.tmp
for %%a in (T_1.tmp) do set hvar=%%~za
if %hvar%==0 (findstr /v /g:T_3.tmp %1 >T_2.tmp) else (findstr /v /g:T_1.tmp %1 | findstr /v /g:T_3.tmp >T_2.tmp)
for %%a in (%num%) do for %%b in (%num%) do (
if "%%a" neq "%%b" findstr /r "%%a.*%%a.*%%b.*%%b %%a.*%%b.*%%a.*%%b %%a.*%%b.*%%b.*%%a" T_2.tmp>>T_4.tmp
)
for %%a in (T_4.tmp) do set hvar=%%~za
if %hvar%==0 (findstr /v /g:T_3.tmp %1 >%2) else (findstr /v /g:T_4.tmp %1 | findstr /v /g:T_3.tmp >%2)
del T_?.tmp
endlocal
Here the output with time code:
Code: Select all
D:\CMDVerz\Tangle3>SolutionTangle
15:48
Step 1: Search all combinations for 2x2 Tangle
15:50
Step 2: Search all combinations for 3x2 Tangle
15:51
Step 3: Search combinations for 3x3 Tangle
Sufficient for a 5x5 Tangle with p01a in the center.
Make 3x3 Tangle that is in top left corner in 5x5 Tangle.
Make 3x3 Tangle that is in top right corner in 5x5 Tangle.
Make 3x3 Tangle that is in bottom left corner in 5x5 Tangle.
Make 3x3 Tangle that is in bottom right corner in 5x5 Tangle.
15:53
Step 4: Optimized files for 3x3 Tangle
15:53
Step 5: Search combinations for 5x3 Tangle
15:54
Step 6: Optimized files for 5x3 Tangle
Optimized 5x3 Tangle is in top in 5x5 Tangle.
Optimized 5x3 Tangle is in bottom in 5x5 Tangle.
16:02
Step 7: Search combinations for 5x5 Tangle with p01a in the center
16:05
Step 8: Optimized files for 5x5 Tangle
16:08
Step 9: Change color
The solution is saved in Solution.txt.
16:08
D:\CMDVerz\Tangle3>
Re: Working out permutations
I've created a new version (with my own internal format - translated as a last step to the above format) using lookup tables for appendable pieces (with 1 and 2 given neighbours):
So all needed 3x3 parts are created in ~20 seconds (on my pc and excluding the time needed to build the lookup tables - i haven't tested it, but maybe the 5x5 block could be computed that way...; "only" an idea how to handle multiple doubled entries is needed... else it computes for the next thousands of years).
The usage of environmental memory over a specific limit seems to slow down the processing speed massively, so i had to reduce it by mapping pieces sides to colors, colors to pieces, ... .
I also tried to reduce the computation length of the other steps... it works and is faster, but somehow i "feel" that it better could be done in another way... .
The whole process takes ~10 mins (on my pc).
This batch produces a bunch of files (and don't delete them at the end), so you should run it from an own folder:
The source of this batch is:
penpen
So all needed 3x3 parts are created in ~20 seconds (on my pc and excluding the time needed to build the lookup tables - i haven't tested it, but maybe the 5x5 block could be computed that way...; "only" an idea how to handle multiple doubled entries is needed... else it computes for the next thousands of years).
The usage of environmental memory over a specific limit seems to slow down the processing speed massively, so i had to reduce it by mapping pieces sides to colors, colors to pieces, ... .
I also tried to reduce the computation length of the other steps... it works and is faster, but somehow i "feel" that it better could be done in another way... .
The whole process takes ~10 mins (on my pc).
This batch produces a bunch of files (and don't delete them at the end), so you should run it from an own folder:
Code: Select all
Tangle_3x3_58.txt 3x3 blocks with standard piece 1234 with north (N) orientation (5) in the NW corner
Tangle_3x3_65.txt 3x3 blocks with standard piece 1234 with north (N) orientation (5) in the NE corner
Tangle_3x3_76.txt 3x3 blocks with standard piece 1234 with north (N) orientation (5) in the SE corner
Tangle_3x3_87.txt 3x3 blocks with standard piece 1234 with north (N) orientation (5) in the SW corner
Tangle_5x3_5.txt 5x3 blocks with standard piece 12345 in the lower middle row
Tangle_5x3_7.txt 5x3 blocks with standard piece 12345 in the upper middle row
Tangle_5x3_5min.txt Some special 5x3 blocks to reduce the amount of combinations of two 5x3 blocks to one 5x5 block
Tangle_5x3_7min.txt Some special 5x3 blocks to reduce the amount of combinations of two 5x3 blocks to one 5x5 block
Tangle_5x5d.txt All 5x5 blocks combined using the four 5x3 block files above (produces doubled 5x5 blocks)
Tangle_5x5ds.txt sorted
Tangle_5x5dsu.txt removed doubled 5x5 blocks
Tangle_5x5s.txt removed 5x5 blocks with more than 1 doubled entry
Tangle_5x5u.txt colorized the solution
Tangle_5x5.txt sorted
Tangle_5x5n.txt Transformed the piece format to { p01a, ..., p24d } and typed to screen (i hope there is no error at this point).
The source of this batch is:
Code: Select all
@echo off
cls
setlocal enableExtensions enableDelayedExpansion
echo([%time%] Start: Initialize lookup-maps.
:: initialize absolute and relative directions
set /A "north=top=5", "east=right=6", "south=bottom=7", "west=left=8"
setlocal enableExtensions enableDelayedExpansion
:: initialize borders
set "opponent=01234!bottom!!left!!top!!right!"
for %%p in (
"1 2 3 4" "1 2 4 3" "1 3 2 4" "1 3 4 2" "1 4 2 3" "1 4 3 2"
"2 1 3 4" "2 1 4 3" "2 3 1 4" "2 3 4 1" "2 4 1 3" "2 4 3 1"
"3 1 2 4" "3 1 4 2" "3 2 1 4" "3 2 4 1" "3 4 1 2" "3 4 2 1"
"4 1 2 3" "4 1 3 2" "4 2 1 3" "4 2 3 1" "4 3 1 2" "4 3 2 1"
) do for /F "tokens=1-4" %%1 in (
"%%~p"
) do for %%t in (
"%%~1 %%~2 !top! %%~1%%~2%%~3%%~4!north! !top! "
"%%~3 %%~4 !top! %%~1%%~2%%~3%%~4!west! !top! "
"%%~1 %%~4 !top! %%~1%%~2%%~3%%~4!south! !top! "
"%%~2 %%~3 !top! %%~1%%~2%%~3%%~4!east! !top! "
"%%~1 %%~2 !right! %%~1%%~2%%~3%%~4!east! !right! "
"%%~3 %%~4 !right! %%~1%%~2%%~3%%~4!north! !right! "
"%%~1 %%~4 !right! %%~1%%~2%%~3%%~4!west! !right! "
"%%~2 %%~3 !right! %%~1%%~2%%~3%%~4!south! !right! "
"%%~1 %%~2 !bottom! %%~1%%~2%%~3%%~4!south! !bottom!"
"%%~3 %%~4 !bottom! %%~1%%~2%%~3%%~4!east! !bottom!"
"%%~1 %%~4 !bottom! %%~1%%~2%%~3%%~4!north! !bottom!"
"%%~2 %%~3 !bottom! %%~1%%~2%%~3%%~4!west! !bottom!"
"%%~1 %%~2 !left! %%~1%%~2%%~3%%~4!west! !left! "
"%%~3 %%~4 !left! %%~1%%~2%%~3%%~4!south! !left! "
"%%~1 %%~4 !left! %%~1%%~2%%~3%%~4!east! !left! "
"%%~2 %%~3 !left! %%~1%%~2%%~3%%~4!north! !left! "
) do for /F "tokens=1-5" %%a in (
"%%~t"
) do for %%o in (
"!opponent:~%%~c,1!"
) do (
set "p_%%~a%%~b%%~c=!p_%%~a%%~b%%~c! %%~d"
set "f_%%~b%%~a%%~o=!f_%%~b%%~a%%~o! %%~d"
set "c_%%~d%%~e=%%~a%%~b%%~c"
set "o_%%~a%%~b%%~c=%%~b%%~a%%~o"
)
for %%Z in (
"1 2" "1 3" "1 4"
"2 1" "2 3" "2 4"
"3 1" "3 2" "3 4"
"4 1" "4 2" "4 3"
) do for /F "tokens=1-2" %%A in (
"%%~Z"
) do for %%C in (
!top! !right! !bottom! !left!
) do for %%O in (
"!opponent:~%%~C,1!"
) do for %%z in (
"1 2" "1 3" "1 4"
"2 1" "2 3" "2 4"
"3 1" "3 2" "3 4"
"4 1" "4 2" "4 3"
) do for /F "tokens=1-2" %%a in (
"%%~z"
) do for %%c in (
!top! !right! !bottom! !left!
) do for %%o in (
"!opponent:~%%~c,1!"
) do if NOT %%C == %%c (
set "A=!f_%%B%%A%%~O!"
set "B=!f_%%b%%a%%~o!"
set "I="
for %%a in (!A!) do for %%b in (!B!) do if %%a == %%b set "I=!I! %%a"
if defined I set "f2_%%B%%A%%~O_%%b%%a%%~o=!I!"
)
set "opponent="
:: initialize macro "$getFitting1"
:: %~1 container (environment variable name) to store the result(s) into
:: %~2 piece to fit to
:: %~3 direction to append to
set "$getFitting1=for %%N in (1 2) do if %%N==2 (for /F "tokens=1-3" %%1 in ("^^^!args^^^!") do for %%A in (^!c_%%2%%3^!) do for %%B in (^!o_%%A^!) do set "%%1=^^^!p_%%B^^^!") else set args= "
set "$getFitting1=for %%N in (1 2) do if %%N==2 (for /F "tokens=1-3" %%1 in ("^^^!args^^^!") do for %%A in (^!c_%%2%%3^!) do set "%%1=^^^!f_%%A^^^!") else set args= "
rem example: %$getFitting1% result 1234!south! !right!
rem result= 13245 14327 31426 32148 32418 34126 41327 43215
:: initialize macro "$getFitting2"
:: %~1 container (environment variable name) to store the result(s) into
:: %~2 piece1 to fit to
:: %~3 direction of piece1 to append to
:: %~4 piece2 to fit to
:: %~5 direction of piece2 to append to
set "$getFitting2=for %%N in (1 2) do if %%N==2 (for /F "tokens=1-5" %%1 in ("^^^!args^^^!") do for %%A in (^!c_%%2%%3^!) do for %%B in (^!c_%%4%%5^!) do set "%%1=^^^!f2_%%A_%%B^^^!") else set args= "
rem example: %$getFitting2% result 3214!west! !bottom! 4321!south! !right!
rem result= 12345
echo([%time%] Create all 3x3 standardized combinations.
:: create all 3x3 with north oriented piece 1234 in an edge
:: A B C G D A I H G C F I
:: D E F H E B F E D B E H
:: G H I I F C C B A A D G
for %%0 in (
"!bottom! !right! "
"!left! !bottom!"
"!top! !left! "
"!right! !top! "
) do for /F "tokens=1-2" %%7 in (
%%0
) do >"Tangle_3x3_%%7%%8.txt" (
set "A=12345"
for %%a in (!A!) do (
%$getFitting1% B %%a %%8
%$getFitting1% D %%a %%7
for %%b in (!B!) do for %%d in (!D!) do (
%$getFitting1% C %%b %%8
%$getFitting2% E %%b %%7 %%d %%8
for %%c in (!C!) do for %%e in (!E!) do (
%$getFitting2% F %%c %%7 %%e %%8
%$getFitting1% G %%d %%7
for %%f in (!F!) do for %%g in (!G!) do (
%$getFitting2% H %%e %%7 %%g %%8
for %%h in (!H!) do (
%$getFitting2% I %%f %%7 %%h %%8
for %%i in (!I!) do (
if "%%7%%8" == "!bottom!!right!" (
echo %%a %%b %%c %%d %%e %%f %%g %%h %%i
) else if "%%7%%8" == "!left!!bottom!" (
echo %%g %%d %%a %%h %%e %%b %%i %%f %%c
) else if "%%7%%8" == "!top!!left!" (
echo %%i %%h %%g %%f %%e %%d %%c %%b %%a
) else (
echo %%c %%f %%i %%b %%e %%h %%a %%d %%g
)
)
)
)
)
)
)
)
endlocal
rem create all 5x3 combinations with 12345 in the middle of south/north.
echo([%time%] Create all 5x3 standardized combinations.
::
:: a b c = j k l
:: d e f = m n o
:: g h i=12345=p q r
>"Tangle_5x3_5.txt" (
for /F "usebackq tokens=1-9" %%a in (
"Tangle_3x3_58.txt"
) do for /F "tokens=1-9" %%j in (
'findstr /R /C:"^%%~c ..... ..... %%~f ..... ..... %%~i" "Tangle_3x3_65.txt"'
) do (
echo(%%~a %%~b %%~c %%~k %%~l %%~d %%~e %%~f %%~n %%~o %%~g %%~h %%~i %%~q %%~r
)
)
::
:: a b c=12345=j k l
:: d e f = m n o
:: g h i = p q r
>"Tangle_5x3_7.txt" (
for /F "usebackq tokens=1-9" %%a in (
"Tangle_3x3_87.txt"
) do for /F "tokens=1-9" %%j in (
'findstr /R /C:"^%%~c ..... ..... %%~f ..... ..... %%~i" "Tangle_3x3_76.txt"'
) do (
echo(%%~a %%~b %%~c %%~k %%~l %%~d %%~e %%~f %%~n %%~o %%~g %%~h %%~i %%~q %%~r
)
)
rem Extract all 5x3 combinations with double pieces in the middle line ^(of the final 5x5 combination^).
echo([%time%] Extract all 5x3 parts with double pieces in the line middle line.
set "compare="
set "vars=a b c d e"
for %%a in (!vars!) do for %%b in (!vars^:*%%a^=!) do set "compare=!compare!) else if %%%%a == %%%%b ( set /A "d+=1""
set "compare=((set "d=0")&(!compare:*e =!))&(if ^!d^! == 1 echo ^!line^!))"
set "compare1=for /F "usebackq tokens=*" %%A in ("Tangle_5x3_5.txt") do ((set "line=%%A") & (for /F "tokens=11-15" %%a in ("%%A") do !compare!))"
set "compare2=for /F "usebackq tokens=*" %%A in ("Tangle_5x3_7.txt") do ((set "line=%%A") & (for /F "tokens=1-5" %%a in ("%%A") do !compare!))"
set "compare="
>"Tangle_5x3_5min.txt" (
%compare1%
)
>"Tangle_5x3_7min.txt" (
%compare2%
)
set "compare1="
set "compare2="
rem Extract all 5x3 combinations with no double pieces (append min text files).
echo([%time%] Extract all 5x3 parts with no double pieces.
set "filter=/V /R"
for %%a in (
"1234" "1243" "1324" "1342" "1423" "1432"
"2134" "2143" "2314" "2341" "2413" "2431"
"3124" "3142" "3214" "3241" "3412" "3421"
"4123" "4132" "4213" "4231" "4312" "4321"
) do (
set "filter=!filter! /C:"%%~a.*%%~a""
)
>>"Tangle_5x3_5min.txt" (
findstr !filter! "Tangle_5x3_5.txt"
)
>>"Tangle_5x3_7min.txt" (
findstr !filter! "Tangle_5x3_7.txt"
)
rem Combine all (maybe tripled - not checked) 5x5 combinations with any double pieces.
echo([%time%] Combine all standardized 5x5 combinations.
:: a b c d e
:: f g h i j
:: k l m n o
:: p q r s t
:: u v w x y
>"Tangle_5x5d.txt" (
for /F "usebackq tokens=* delims=" %%Z in ("Tangle_5x3_5min.txt") do (
set "line=%%Z"
for /F "tokens=11-15" %%a in ("!line!") do (
for /F "tokens=5*" %%A in ('findstr /R /C:"^%%~a %%~b %%~c %%~d %%~e" "Tangle_5x3_7.txt"') do (
echo(!line! %%B
)
)
)
for /F "usebackq tokens=* delims=" %%Z in ("Tangle_5x3_7min.txt") do (
set "line=%%Z"
for /F "tokens=1-5" %%a in ("!line!") do (
for /F "tokens=1-10" %%A in ('findstr /R /C:"^..... ..... ..... ..... ..... ..... ..... ..... ..... ..... %%~a %%~b %%~c %%~d %%~e" "Tangle_5x3_5.txt"') do (
echo(%%A %%B %%C %%D %%E %%F %%G %%H %%I %%J !line!
)
)
)
)
echo([%time%] Remove multiple solutions 5x5 combinations.
sort "Tangle_5x5d.txt" /O "Tangle_5x5ds.txt"
set "lastLine="
>"Tangle_5x5dsu.txt" (
for /F "usebackq tokens=* delims=" %%a in ("Tangle_5x5ds.txt") do (
if NOT "%%a" == "!lastLine!" (
echo %%a
set "lastLine=%%a"
)
)
)
echo([%time%] Minimize 5x5 combinations.
setlocal enableExtensions enableDelayedExpansion
for %%a in (
1234 1243 1324 1342 1423 1432
2134 2143 2314 2341 2413 2431
3124 3142 3214 3241 3412 3421
4123 4132 4213 4231 4312 4321
) do (
for %%b in (5 6 7 8) do set "d_%%a%%b=m_%%a"
if %%a == 1234 (
set "M_0=m_%%a"
set "M_1=^!m_%%a^!"
) else (
set "M_0=!M_0!=m_%%a"
set "M_1=!M_1!^!m_%%a^!"
)
)
>"Tangle_5x5s.txt" (
for /F "usebackq tokens=* delims=" %%a in ("Tangle_5x5dsu.txt") do (
set /A "!M_0!=0"
for %%b in (%%a) do set /A "!d_%%b!+=1"
set "M=%M_1%0"
set "M=!M:*0=!"
if not defined M echo(%%a
)
)
endlocal
rem Variations:
rem Type 1: doubled piece GBRY 1423 1234 GRYB
rem Type 2: doubled piece RYBG 1423 1234 RBGY
rem Type 3: doubled piece RGYB 1423 1234 RYBG
rem Type 4: doubled piece BRGY 1423 1234 BGYR
echo([%time%] Colorize basing on tangle variations.
>"Tangle_5x5u.txt" (
for /F "usebackq tokens=* delims=" %%a in ("Tangle_5x5s.txt") do (
set "line=%%a "
set "line=!line:5=!"
set "line=!line:6=!"
set "line=!line:7=!"
set "line=!line:8=!"
set "doubled="
for %%b in (!line!) do if not defined doubled (
set "line=!line:*%%b=!"
set "check=!line:*%%b=!"
if NOT "!line!" == "!check!" set "doubled=%%b"
)
set "doubled=!doubled:~0,1! !doubled:~1,1! !doubled:~2,1! !doubled:~3,1!"
set "type=0"
for /F "tokens=1-4" %%1 in (
"!doubled!"
) do for %%A in (
"G R Y B" "R B G Y" "R Y B G" "B G Y R"
) do for /F "tokens=1-4" %%A in (
%%A
) do (
set "line=%%a"
set /A "type+=1"
set "line=!line:%%1=%%A!"
set "line=!line:%%2=%%B!"
set "line=!line:%%3=%%C!"
set "line=!line:%%4=%%D!"
echo(Type !type!: !line!
)
)
)
sort "Tangle_5x5u.txt" /O "Tangle_5x5.txt"
echo([%time%] Translate the internal piece format to { p01a, ..., p24d }.
:: piece 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
:: code1 YGRB YGBR YRGB YRBG YBGR YBRG GYRB GYBR GRYB GRBY GBYR GBRY RYGB RYBG RGYB RGBY RBYG RBGY BYGR BYRG BGYR BGRY BRYG BRGY
:: code2 YRBG YBRG YGBR YBGR YGRB YRGB GRBY GBRY GYBR GBYR GYRB GRYB RGBY RBGY RYBG RBYG RYGB RGYB BGRY BRGY BYRG BRYG BYGR BGYR
:: code3* 4312 4132 4213 4123 4231 4321 2314 2134 2413 2143 2431 2341 3214 3124 3412 3142 3421 3241 1234 1324 1432 1342 1423 1243
::
:: code1: sides cd
:: code2: sides ab
:: code3: BGRY := 1234 (*: all permutations possible)
setlocal enableExtensions enableDelayedExpansion
set "oMap=01234badc"
for %%o in (5 6 7 8) do (
set "piece[YRBG%%~o]=p01!oMap:~%%~o,1!"
set "piece[YBRG%%~o]=p02!oMap:~%%~o,1!"
set "piece[YGBR%%~o]=p03!oMap:~%%~o,1!"
set "piece[YBGR%%~o]=p04!oMap:~%%~o,1!"
set "piece[YGRB%%~o]=p05!oMap:~%%~o,1!"
set "piece[YRGB%%~o]=p06!oMap:~%%~o,1!"
set "piece[GRBY%%~o]=p07!oMap:~%%~o,1!"
set "piece[GBRY%%~o]=p08!oMap:~%%~o,1!"
set "piece[GYBR%%~o]=p09!oMap:~%%~o,1!"
set "piece[GBYR%%~o]=p10!oMap:~%%~o,1!"
set "piece[GYRB%%~o]=p11!oMap:~%%~o,1!"
set "piece[GRYB%%~o]=p12!oMap:~%%~o,1!"
set "piece[RGBY%%~o]=p13!oMap:~%%~o,1!"
set "piece[RBGY%%~o]=p14!oMap:~%%~o,1!"
set "piece[RYBG%%~o]=p15!oMap:~%%~o,1!"
set "piece[RBYG%%~o]=p16!oMap:~%%~o,1!"
set "piece[RYGB%%~o]=p17!oMap:~%%~o,1!"
set "piece[RGYB%%~o]=p18!oMap:~%%~o,1!"
set "piece[BGRY%%~o]=p19!oMap:~%%~o,1!"
set "piece[BRGY%%~o]=p20!oMap:~%%~o,1!"
set "piece[BYRG%%~o]=p21!oMap:~%%~o,1!"
set "piece[BRYG%%~o]=p22!oMap:~%%~o,1!"
set "piece[BYGR%%~o]=p23!oMap:~%%~o,1!"
set "piece[BGYR%%~o]=p24!oMap:~%%~o,1!"
)
>"Tangle_5x5n.txt" (
for /F "usebackq tokens=1* delims=:" %%a in ("Tangle_5x5.txt") do (
set "line="
for %%c in (%%b) do set "line=!line! !piece[%%c]!"
echo(%%a:!line!
)
)
type "Tangle_5x5n.txt"
endlocal
echo([%time%] Finished.
endlocal
goto :eof
penpen
Re: Working out permutations
I have your batch file tested - just 5 minutes on my computer.
All solutions are correct.
The difference of the solutions are:
- That my two solutions are valid for a Tangle and penpen all eight solutions for all four Tangle versions contains
- That the solutions of penpen and mine in the orientation of the central piece differ
On the idea of the look-up table, I could have been. But to create the complete 3x3 block with the look-up table is really good. Create the macro I get not so good, but here it is a great way to make the program more quickly.
The solutions in Tangle_5x5n.txt can used with Tangle2 /piece25.
All solutions are correct.
The difference of the solutions are:
- That my two solutions are valid for a Tangle and penpen all eight solutions for all four Tangle versions contains
- That the solutions of penpen and mine in the orientation of the central piece differ
On the idea of the look-up table, I could have been. But to create the complete 3x3 block with the look-up table is really good. Create the macro I get not so good, but here it is a great way to make the program more quickly.
The solutions in Tangle_5x5n.txt can used with Tangle2 /piece25.