thanks, I am thinking a lot about this.
Since nobody answer yet for the recursive version I did some test on my own, Here is my new code:
It’s pretty AMAZING to solve all the (pocketcube,minicube,2x2x2 rubik’s cube) in LESS THAN 40 LINES OF JULIA CODE!!!
thanks julia
using Combinatorics
global const T =Int8[7 ,8 ,9 ,1 ,2 ,3 ,10,11,12,4 ,5 ,6 ,13,14,15,16,17,18,19,20,21]
global const Ti=Int8[4 ,5 ,6 ,10,11,12,1 ,2 ,3 ,7 ,8 ,9 ,13,14,15,16,17,18,19,20,21]
global const F =Int8[1 ,2 ,3 ,4 ,5 ,6 ,15,13,14,9 ,7 ,8 ,16,17,18,12,10,11,19,20,21]
global const Fi=Int8[1 ,2 ,3 ,4 ,5 ,6 ,11,12,10,17,18,16,8 ,9 ,7 ,13,14,15,19,20,21]
global const R =Int8[1 ,2 ,3 ,12,10,11,7 ,8 ,9 ,16,17,18,13,14,15,21,19,20,6 ,4 ,5 ]
global const Ri=Int8[1 ,2 ,3 ,20,21,19,7 ,8 ,9 ,5 ,6 ,4 ,13,14,15,10,11,12,17,18,16]
global stateslist=Int32[]
global rotlist=String[]
cube=Int8[1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10,11,12,13,14,15,16,17,18,19,20,21]
rot=""
function browsecube(cube,rot)
if length(rot)>6
return
end
state=Int32((cube[1]-1)*21^5+(cube[4]-1)*21^4+(cube[7]-1)*21^3+(cube[10]-1)*21^2+(cube[13]-1)*21+cube[16]-1)
index=findin(stateslist,state)
if index!=[]
if length(rot) < length(split(rotlist[index[1]],'/')[1])
rotlist[index[1]]=rot
elseif length(rot) == length(split(rotlist[index[1]],'/')[1])
rotlist[index[1]]*="/"*rot
else
return
end
else
push!(rotlist,rot)
push!(stateslist,state)
end
browsecube(cube[T],rot*"T")
browsecube(cube[F],rot*"F")
browsecube(cube[R],rot*"R")
browsecube(cube[Ti],rot*"t")
browsecube(cube[Fi],rot*"f")
browsecube(cube[Ri],rot*"r")
end
@time browsecube(cube,rot)
for o in rotlist
print(o*"-|-")
end
Since I have a lot to learn about Julia I will be glad if someone point out the part slowing it down because it is very long to evaluate.
I know I am making some strange stuff so please ask me some questions if needed.
Tips needed to speed it up.
thx!