There are precisely eight buttons in a row. Each button shows an arrow pointing left (L) or right (R).
When you press a button, all buttons in the direction of its arrow (not including itself) rotate 180 degrees.
Determine the least number of button presses required to get from RRRRLLLL to LRLRLRLR.
The smallest number of button presses required is 6. There are 240 possible sequences of 6 that will accomplish this, shown below with position numbers in between the changed states of the row. The variable shortest was originally higher before determining it could actually be reduced to 7 (the number of states including initial and final).
I'm assuming "all buttons in the direction of its arrow" means that each such button individually switches between left and right, not the whole set of buttons together. More on that after the results of this interpretation.
clearvars,clc
global h s shortest fid stepNo steps
s='rrrrllll';
h={s}; shortest=8; stepNo=0; steps=zeros(1,9);
fid=fopen('c:VB5 Projects\flooble\eight buttons.txt','w')
takeStep();
fclose(fid)
function takeStep()
global h s shortest fid stepNo steps
stepNo=stepNo+1;
for i=1:8
steps(stepNo)=i;
saveh=h;
saves=s;
dir=s(i);
if dir=='r'
for j=i+1:8
if s(j)=='r'
s(j)='l';
else
s(j)='r';
end
end
else
for j=i-1:-1:1
if s(j)=='r'
s(j)='l';
else
s(j)='r';
end
end
end
if isequal(s,'lrlrlrlr')
h{end+1}=s;
disp(h)
if length(h)<=shortest
shortest=length(h);
disp(h)
disp(steps)
disp(' ')
for i=1:length(h)
fprintf(fid,'%10s',h{i} );
fprintf(fid,'%3d',steps(i));
end
fprintf(fid,'
');
end
elseif ismember(s,h)
elseif length(h)<shortest
h{end+1}=s;
stepset{length(h)}=steps;
takeStep
end
h=saveh;
s=saves;;
end
stepNo=stepNo-1;
end
There are 240 sequences of button presses that will do the job. The number of the button is shown below between the sequence it worked on and the new sequence it produced.
rrrrllll 1 rlllrrrr 3 lrllrrrr 4 rlrlrrrr 5 rlrlrlll 8 lrlrlrrl 6 lrlrlrlr
rrrrllll 1 rlllrrrr 3 lrllrrrr 4 rlrlrrrr 7 rlrlrrrl 5 rlrlrllr 7 lrlrlrlr
rrrrllll 1 rlllrrrr 3 lrllrrrr 5 lrllrlll 4 rlrlrlll 8 lrlrlrrl 6 lrlrlrlr
rrrrllll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rl 2 lrlrlrlr
rrrrllll 1 rlllrrrr 5 rlllrlll 3 lrllrlll 4 rlrlrlll 8 lrlrlrrl 6 lrlrlrlr
rrrrllll 1 rlllrrrr 5 rlllrlll 3 lrllrlll 8 rlrrlrrl 3 rlrlrllr 7 lrlrlrlr
rrrrllll 1 rlllrrrr 5 rlllrlll 4 lrrlrlll 2 lrlrlrrr 7 lrlrlrrl 6 lrlrlrlr
rrrrllll 1 rlllrrrr 5 rlllrlll 4 lrrlrlll 7 rllrlrll 8 lrrlrlrl 2 lrlrlrlr
rrrrllll 1 rlllrrrr 5 rlllrlll 4 lrrlrlll 8 rllrlrrl 3 lrlrlrrl 6 lrlrlrlr
rrrrllll 1 rlllrrrr 5 rlllrlll 4 lrrlrlll 8 rllrlrrl 6 rllrlrlr 3 lrlrlrlr
rrrrllll 1 rlllrrrr 5 rlllrlll 7 lrrrlrll 3 lrrlrlrr 7 lrrlrlrl 2 lrlrlrlr
rrrrllll 1 rlllrrrr 5 rlllrlll 7 lrrrlrll 8 rlllrlrl 4 lrrlrlrl 2 lrlrlrlr
rrrrllll 1 rlllrrrr 5 rlllrlll 8 lrrrlrrl 2 lrllrllr 4 rlrlrllr 7 lrlrlrlr
rrrrllll 1 rlllrrrr 5 rlllrlll 8 lrrrlrrl 3 lrrlrllr 2 lrlrlrrl 6 lrlrlrlr
rrrrllll 1 rlllrrrr 5 rlllrlll 8 lrrrlrrl 3 lrrlrllr 7 rllrlrlr 3 lrlrlrlr
rrrrllll 1 rlllrrrr 5 rlllrlll 8 lrrrlrrl 6 lrrrlrlr 3 lrrlrlrl 2 lrlrlrlr
rrrrllll 1 rlllrrrr 6 rlllrrll 4 lrrlrrll 5 lrrlrlrr 7 lrrlrlrl 2 lrlrlrlr
rrrrllll 1 rlllrrrr 6 rlllrrll 4 lrrlrrll 8 rllrllrl 6 lrrlrlrl 2 lrlrlrlr
rrrrllll 1 rlllrrrr 6 rlllrrll 5 rlllrlrr 4 lrrlrlrr 7 lrrlrlrl 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rrl 6 lrlrlrlr
rrrrllll 2 rrllrrrr 5 rrllrlll 4 llrlrlll 8 rrlrlrrl 1 rlrlrllr 7 lrlrlrlr
rrrrllll 2 rrllrrrr 5 rrllrlll 8 llrrlrrl 2 rlrrlrrl 3 rlrlrllr 7 lrlrlrlr
rrrrllll 2 rrllrrrr 5 rrllrlll 8 llrrlrrl 3 llrlrllr 2 rlrlrllr 7 lrlrlrlr
rrrrllll 2 rrllrrrr 7 rrllrrrl 1 rlrrlllr 3 rlrlrrrl 5 rlrlrllr 7 lrlrlrlr
rrrrllll 2 rrllrrrr 7 rrllrrrl 1 rlrrlllr 6 lrllrllr 4 rlrlrllr 7 lrlrlrlr
rrrrllll 2 rrllrrrr 7 rrllrrrl 4 llrlrrrl 2 rlrlrrrl 5 rlrlrllr 7 lrlrlrlr
rrrrllll 2 rrllrrrr 7 rrllrrrl 4 llrlrrrl 5 llrlrllr 2 rlrlrllr 7 lrlrlrlr
rrrrllll 2 rrllrrrr 7 rrllrrrl 5 rrllrllr 1 rlrrlrrl 3 rlrlrllr 7 lrlrlrlr
rrrrllll 2 rrllrrrr 7 rrllrrrl 5 rrllrllr 4 llrlrllr 2 rlrlrllr 7 lrlrlrlr
rrrrllll 3 rrrlrrrr 1 rllrllll 3 lrlrllll 6 rlrlrlll 8 lrlrlrrl 6 lrlrlrlr
rrrrllll 3 rrrlrrrr 1 rllrllll 3 lrlrllll 8 rlrlrrrl 5 rlrlrllr 7 lrlrlrlr
rrrrllll 3 rrrlrrrr 1 rllrllll 6 lrrlrlll 2 lrlrlrrr 7 lrlrlrrl 6 lrlrlrlr
rrrrllll 3 rrrlrrrr 1 rllrllll 6 lrrlrlll 7 rllrlrll 8 lrrlrlrl 2 lrlrlrlr
rrrrllll 3 rrrlrrrr 1 rllrllll 6 lrrlrlll 8 rllrlrrl 3 lrlrlrrl 6 lrlrlrlr
rrrrllll 3 rrrlrrrr 1 rllrllll 6 lrrlrlll 8 rllrlrrl 6 rllrlrlr 3 lrlrlr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rlll 4 lrrlrlll 2 lrlrlrrr 7 lrlrlrrl 6 lrlrlrlr
rrrrllll 6 llllrlll 2 rlllrlll 4 lrrlrlll 7 rllrlrll 8 lrrlrlrl 2 lrlrlrlr
rrrrllll 6 llllrlll 2 rlllrlll 4 lrrlrlll 8 rllrlrrl 3 lrlrlrrl 6 lrlrlrlr
rrrrllll 6 llllrlll 2 rlllrlll 4 lrrlrlll 8 rllrlrrl 6 rllrlrlr 3 lrlrlrlr
rrrrllll 6 llllrlll 2 rlllrlll 7 lrrrlrll 3 lrrlrlrr 7 lrrlrlrl 2 lrlrlrlr
rrrrllll 6 llllrlll 2 rlllrlll 7 lrrrlrll 8 rlllrlrl 4 lrrlrlrl 2 lrlrlrlr
rrrrllll 6 llllrlll 2 rlllrlll 8 lrrrlrrl 2 lrllrllr 4 rlrlrllr 7 lrlrlrlr
rrrrllll 6 llllrlll 2 rlllrlll 8 lrrrlrrl 3 lrrlrllr 2 lrlrlrrl 6 lrlrlrlr
rrrrllll 6 llllrlll 2 rlllrlll 8 lrrrlrrl 3 lrrlrllr 7 rllrlrlr 3 lrlrlrlr
rrrrllll 6 llllrlll 2 rlllrlll 8 lrrrlrrl 6 lrrrlrlr 3 lrrlrlrl 2 lrlrlrlr
rrrrllll 6 llllrlll 3 rrllrlll 1 rlrrlrrr 3 rlrlrlll 8 lrlrlrrl 6 lrlrlrlr
rrrrllll 6 llllrlll 3 rrllrlll 1 rlrrlrrr 7 rlrrlrrl 3 rlrlrllr 7 lrlrlrlr
rrrrllll 6 llllrlll 3 rrllrlll 4 llrlrlll 2 rlrlrlll 8 lrlrlrrl 6 lrlrlrlr
rrrrllll 6 llllrlll 3 rrllrlll 4 llrlrlll 8 rrlrlrrl 1 rlrlrllr 7 lrlrlrlr
rrrrllll 6 llllrlll 3 rrllrlll 8 llrrlrrl 2 rlrrlrrl 3 rlrlrllr 7 lrlrlrlr
rrrrllll 6 llllrlll 3 rrllrlll 8 llrrlrrl 3 llrlrllr 2 rlrlrllr 7 lrlrlrlr
rrrrllll 6 llllrlll 4 rrrlrlll 1 rllrlrrr 3 lrlrlrrr 7 lrlrlrrl 6 lrlrlrlr
rrrrllll 6 llllrlll 4 rrrlrlll 1 rllrlrrr 6 rllrlrll 8 lrrlrlrl 2 lrlrlrlr
rrrrllll 6 llllrlll 4 rrrlrlll 1 rllrlrrr 7 rllrlrrl 3 lrlrlrrl 6 lrlrlrlr
rrrrllll 6 llllrlll 4 rrrlrlll 1 rllrlrrr 7 rllrlrrl 6 rllrlrlr 3 lrlrlrlr
rrrrllll 6 llllrlll 4 rrrlrlll 2 rrlrlrrr 1 rlrlrlll 8 lrlrlrrl 6 lrlrlrlr
rrrrllll 6 llllrlll 4 rrrlrlll 2 rrlrlrrr 7 rrlrlrrl 1 rlrlrllr 7 lrlrlrlr
rrrrllll 6 llllrlll 4 rrrlrlll 7 lllrlrll 2 rllrlrll 8 lrrlrlrl 2 lrlrlrlr
rrrrllll 6 llllrlll 4 rrrlrlll 7 lllrlrll 8 rrrlrlrl 1 rllrlrlr 3 lrlrlrlr
rrrrllll 6 llllrlll 4 rrrlrlll 8 lllrlrrl 2 rllrlrrl 3 lrlrlrrl 6 lrlrlrlr
rrrrllll 6 llllrlll 4 rrrlrlll 8 lllrlrrl 2 rllrlrrl 6 rllrlrlr 3 lrlrlrlr
rrrrllll 6 llllrlll 4 rrrlrlll 8 lllrlrrl 3 rrlrlrrl 1 rlrlrllr 7 lrlrlrlr
rrrrllll 6 llllrlll 4 rrrlrlll 8 lllrlrrl 6 lllrlrlr 2 rllrlrlr 3 lrlrlrlr
rrrrllll 6 llllrlll 7 rrrrlrll 1 rlllrlrr 4 lrrlrlrr 7 lrrlrlrl 2 lrlrlrlr
rrrrllll 6 llllrlll 7 rrrrlrll 1 rlllrlrr 7 rlllrlrl 4 lrrlrlrl 2 lrlrlrlr
rrrrllll 6 llllrlll 7 rrrrlrll 3 rrrlrlrr 1 rllrlrll 8 lrrlrlrl 2 lrlrlrlr
rrrrllll 6 llllrlll 7 rrrrlrll 3 rrrlrlrr 7 rrrlrlrl 1 rllrlrlr 3 lrlrlrlr
rrrrllll 6 llllrlll 7 rrrrlrll 8 llllrlrl 2 rlllrlrl 4 lrrlrlrl 2 lrlrlrlr
rrrrllll 6 llllrlll 7 rrrrlrll 8 llllrlrl 4 rrrlrlrl 1 rllrlrlr 3 lrlrlrlr
rrrrllll 6 llllrlll 8 rrrrlrrl 1 rlllrllr 3 lrllrllr 4 rlrlrllr 7 lrlrlrlr
rrrrllll 6 llllrlll 8 rrrrlrrl 1 rlllrllr 4 lrrlrllr 2 lrlrlrrl 6 lrlrlrlr
rrrrllll 6 llllrlll 8 rrrrlrrl 1 rlllrllr 4 lrrlrllr 7 rllrlrlr 3 lrlrlrlr
rrrrllll 6 llllrlll 8 rrrrlrrl 1 rlllrllr 7 lrrrlrlr 3 lrrlrlrl 2 lrlrlrlr
rrrrllll 6 llllrlll 8 rrrrlrrl 2 rrllrllr 1 rlrrlrrl 3 rlrlrllr 7 lrlrlrlr
rrrrllll 6 llllrlll 8 rrrrlrrl 2 rrllrllr 4 llrlrllr 2 rlrlrllr 7 lrlrlrlr
rrrrllll 6 llllrlll 8 rrrrlrrl 3 rrrlrllr 1 rllrlrrl 3 lrlrlrrl 6 lrlrlrlr
rrrrllll 6 llllrlll 8 rrrrlrrl 3 rrrlrllr 1 rllrlrrl 6 rllrlrlr 3 lrlrlrlr
rrrrllll 6 llllrlll 8 rrrrlrrl 3 rrrlrllr 2 rrlrlrrl 1 rlrlrllr 7 lrlrlrlr
rrrrllll 6 llllrlll 8 rrrrlrrl 3 rrrlrllr 7 lllrlrlr 2 rllrlrlr 3 lrlrlrlr
rrrrllll 6 llllrlll 8 rrrrlrrl 6 rrrrlrlr 1 rlllrlrl 4 lrrlrlrl 2 lrlrlrlr
rrrrllll 6 llllrlll 8 rrrrlrrl 6 rrrrlrlr 3 rrrlrlrl 1 rllrlrlr 3 lrlrlrlr
rrrrllll 7 llllrrll 2 rlllrrll 4 lrrlrrll 5 lrrlrlrr 7 lrrlrlrl 2 lrlrlrlr
rrrrllll 7 llllrrll 2 rlllrrll 4 lrrlrrll 8 rllrllrl 6 lrrlrlrl 2 lrlrlrlr
rrrrllll 7 llllrrll 2 rlllrrll 5 rlllrlrr 4 lrrlrlrr 7 lrrlrlrl 2 lrlrlrlr
rrrrllll 7 llllrrll 2 rlllrrll 5 rlllrlrr 7 rlllrlrl 4 lrrlrlrl 2 lrlrlrlr
rrrrllll 7 llllrrll 2 rlllrrll 8 lrrrllrl 3 lrrlrrlr 5 lrrlrlrl 2 lrlrlrlr
rrrrllll 7 llllrrll 2 rlllrrll 8 lrrrllrl 6 rlllrlrl 4 lrrlrlrl 2 lrlrlrlr
rrrrllll 7 llllrrll 4 rrrlrrll 1 rllrllrr 6 lrrlrlrr 7 lrrlrlrl 2 lrlrlrlr
rrrrllll 7 llllrrll 4 rrrlrrll 1 rllrllrr 7 rllrllrl 6 lrrlrlrl 2 lrlrlrlr
rrrrllll 7 llllrrll 4 rrrlrrll 5 rrrlrlrr 1 rllrlrll 8 lrrlrlrl 2 lrlrlrlr
rrrrllll 7 llllrrll 4 rrrlrrll 5 rrrlrlrr 7 rrrlrlrl 1 rllrlrlr 3 lrlrlrlr
rrrrllll 7 llllrrll 4 rrrlrrll 8 lllrllrl 2 rllrllrl 6 lrrlrlrl 2 lrlrlrlr
rrrrllll 7 llllrrll 4 rrrlrrll 8 lllrllrl 6 rrrlrlrl 1 rllrlrlr 3 lrlrlrlr
rrrrllll 7 llllrrll 5 llllrlrr 2 rlllrlrr 4 lrrlrlrr 7 lrrlrlrl 2 lrlrlrlr
rrrrllll 7 llllrrll 5 llllrlrr 2 rlllrlrr 7 rlllrlrl 4 lrrlrlrl 2 lrlrlrlr
rrrrllll 7 llllrrll 5 llllrlrr 4 rrrlrlrr 1 rllrlrll 8 lrrlrlrl 2 lrlrlrlr
rrrrllll 7 llllrrll 5 llllrlrr 4 rrrlrlrr 7 rrrlrlrl 1 rllrlrlr 3 lrlrlrlr
rrrrllll 7 llllrrll 5 llllrlrr 7 llllrlrl 2 rlllrlrl 4 lrrlrlrl 2 lrlrlrlr
rrrrllll 7 llllrrll 5 llllrlrr 7 llllrlrl 4 rrrlrlrl 1 rllrlrlr 3 lrlrlrlr
rrrrllll 7 llllrrll 8 rrrrllrl 1 rlllrrlr 4 lrrlrrlr 5 lrrlrlrl 2 lrlrlrlr
rrrrllll 7 llllrrll 8 rrrrllrl 1 rlllrrlr 5 rlllrlrl 4 lrrlrlrl 2 lrlrlrlr
rrrrllll 7 llllrrll 8 rrrrllrl 3 rrrlrrlr 1 rllrllrl 6 lrrlrlrl 2 lrlrlrlr
rrrrllll 7 llllrrll 8 rrrrllrl 3 rrrlrrlr 5 rrrlrlrl 1 rllrlrlr 3 lrlrlrlr
rrrrllll 7 llllrrll 8 rrrrllrl 6 llllrlrl 2 rlllrlrl 4 lrrlrlrl 2 lrlrlrlr
rrrrllll 7 llllrrll 8 rrrrllrl 6 llllrlrl 4 rrrlrlrl 1 rllrlrlr 3 lrlrlrlr
rrrrllll 8 llllrrrl 2 rlllrrrl 3 lrllrrrl 4 rlrlrrrl 5 rlrlrllr 7 lrlrlrlr
rrrrllll 8 llllrrrl 2 rlllrrrl 3 lrllrrrl 5 lrllrllr 4 rlrlrllr 7 lrlrlrlr
rrrrllll 8 llllrrrl 2 rlllrrrl 4 lrrlrrrl 2 lrlrlllr 6 rlrlrllr 7 lrlrlrlr
rrrrllll 8 llllrrrl 2 rlllrrrl 4 lrrlrrrl 5 lrrlrllr 2 lrlrlrrl 6 lrlrlrlr
rrrrllll 8 llllrrrl 2 rlllrrrl 4 lrrlrrrl 5 lrrlrllr 7 rllrlrlr 3 lrlrlrlr
rrrrllll 8 llllrrrl 2 rlllrrrl 4 lrrlrrrl 6 lrrlrrlr 5 lrrlrlrl 2 lrlrlrlr
rrrrllll 8 llllrrrl 2 rlllrrrl 5 rlllrllr 3 lrllrllr 4 rlrlrllr 7 lrlrlrlr
rrrrllll 8 llllrrrl 2 rlllrrrl 5 rlllrllr 4 lrrlrllr 2 lrlrlrrl 6 lrlrlrlr
rrrrllll 8 llllrrrl 2 rlllrrrl 5 rlllrllr 4 lrrlrllr 7 rllrlrlr 3 lrlrlrlr
rrrrllll 8 llllrrrl 2 rlllrrrl 5 rlllrllr 7 lrrrlrlr 3 lrrlrlrl 2 lrlrlrlr
rrrrllll 8 llllrrrl 2 rlllrrrl 6 rlllrrlr 4 lrrlrrlr 5 lrrlrlrl 2 lrlrlrlr
rrrrllll 8 llllrrrl 2 rlllrrrl 6 rlllrrlr 5 rlllrlrl 4 lrrlrlrl 2 lrlrlrlr
rrrrllll 8 llllrrrl 3 rrllrrrl 1 rlrrlllr 3 rlrlrrrl 5 rlrlrllr 7 lrlrlrlr
rrrrllll 8 llllrrrl 3 rrllrrrl 1 rlrrlllr 6 lrllrllr 4 rlrlrllr 7 lrlrlrlr
rrrrllll 8 llllrrrl 3 rrllrrrl 4 llrlrrrl 2 rlrlrrrl 5 rlrlrllr 7 lrlrlrlr
rrrrllll 8 llllrrrl 3 rrllrrrl 4 llrlrrrl 5 llrlrllr 2 rlrlrllr 7 lrlrlrlr
rrrrllll 8 llllrrrl 3 rrllrrrl 5 rrllrllr 1 rlrrlrrl 3 rlrlrllr 7 lrlrlrlr
rrrrllll 8 llllrrrl 3 rrllrrrl 5 rrllrllr 4 llrlrllr 2 rlrlrllr 7 lrlrlrlr
rrrrllll 8 llllrrrl 4 rrrlrrrl 1 rllrlllr 3 lrlrlllr 6 rlrlrllr 7 lrlrlrlr
rrrrllll 8 llllrrrl 4 rrrlrrrl 1 rllrlllr 6 lrrlrllr 2 lrlrlrrl 6 lrlrlrlr
rrrrllll 8 llllrrrl 4 rrrlrrrl 1 rllrlllr 6 lrrlrllr 7 rllrlrlr 3 lrlrlrlr
rrrrllll 8 llllrrrl 4 rrrlrrrl 1 rllrlllr 7 lrrlrrlr 5 lrrlrlrl 2 lrlrlrlr
rrrrllll 8 llllrrrl 4 rrrlrrrl 2 rrlrlllr 1 rlrlrrrl 5 rlrlrllr 7 lrlrlrlr
rrrrllll 8 llllrrrl 4 rrrlrrrl 2 rrlrlllr 6 llrlrllr 2 rlrlrllr 7 lrlrlrlr
rrrrllll 8 llllrrrl 4 rrrlrrrl 5 rrrlrllr 1 rllrlrrl 3 lrlrlrrl 6 lrlrlrlr
rrrrllll 8 llllrrrl 4 rrrlrrrl 5 rrrlrllr 1 rllrlrrl 6 rllrlrlr 3 lrlrlrlr
rrrrllll 8 llllrrrl 4 rrrlrrrl 5 rrrlrllr 2 rrlrlrrl 1 rlrlrllr 7 lrlrlrlr
rrrrllll 8 llllrrrl 4 rrrlrrrl 5 rrrlrllr 7 lllrlrlr 2 rllrlrlr 3 lrlrlrlr
rrrrllll 8 llllrrrl 4 rrrlrrrl 6 rrrlrrlr 1 rllrllrl 6 lrrlrlrl 2 lrlrlrlr
rrrrllll 8 llllrrrl 4 rrrlrrrl 6 rrrlrrlr 5 rrrlrlrl 1 rllrlrlr 3 lrlrlrlr
rrrrllll 8 llllrrrl 5 llllrllr 2 rlllrllr 3 lrllrllr 4 rlrlrllr 7 lrlrlrlr
rrrrllll 8 llllrrrl 5 llllrllr 2 rlllrllr 4 lrrlrllr 2 lrlrlrrl 6 lrlrlrlr
rrrrllll 8 llllrrrl 5 llllrllr 2 rlllrllr 4 lrrlrllr 7 rllrlrlr 3 lrlrlrlr
rrrrllll 8 llllrrrl 5 llllrllr 2 rlllrllr 7 lrrrlrlr 3 lrrlrlrl 2 lrlrlrlr
rrrrllll 8 llllrrrl 5 llllrllr 3 rrllrllr 1 rlrrlrrl 3 rlrlrllr 7 lrlrlrlr
rrrrllll 8 llllrrrl 5 llllrllr 3 rrllrllr 4 llrlrllr 2 rlrlrllr 7 lrlrlrlr
rrrrllll 8 llllrrrl 5 llllrllr 4 rrrlrllr 1 rllrlrrl 3 lrlrlrrl 6 lrlrlrlr
rrrrllll 8 llllrrrl 5 llllrllr 4 rrrlrllr 1 rllrlrrl 6 rllrlrlr 3 lrlrlrlr
rrrrllll 8 llllrrrl 5 llllrllr 4 rrrlrllr 2 rrlrlrrl 1 rlrlrllr 7 lrlrlrlr
rrrrllll 8 llllrrrl 5 llllrllr 4 rrrlrllr 7 lllrlrlr 2 rllrlrlr 3 lrlrlrlr
rrrrllll 8 llllrrrl 5 llllrllr 7 rrrrlrlr 1 rlllrlrl 4 lrrlrlrl 2 lrlrlrlr
rrrrllll 8 llllrrrl 5 llllrllr 7 rrrrlrlr 3 rrrlrlrl 1 rllrlrlr 3 lrlrlrlr
rrrrllll 8 llllrrrl 6 llllrrlr 2 rlllrrlr 4 lrrlrrlr 5 lrrlrlrl 2 lrlrlrlr
rrrrllll 8 llllrrrl 6 llllrrlr 2 rlllrrlr 5 rlllrlrl 4 lrrlrlrl 2 lrlrlrlr
rrrrllll 8 llllrrrl 6 llllrrlr 4 rrrlrrlr 1 rllrllrl 6 lrrlrlrl 2 lrlrlrlr
rrrrllll 8 llllrrrl 6 llllrrlr 4 rrrlrrlr 5 rrrlrlrl 1 rllrlrlr 3 lrlrlrlr
rrrrllll 8 llllrrrl 6 llllrrlr 5 llllrlrl 2 rlllrlrl 4 lrrlrlrl 2 lrlrlrlr
rrrrllll 8 llllrrrl 6 llllrrlr 5 llllrlrl 4 rrrlrlrl 1 rllrlrlr 3 lrlrlrlr
I later considered a different interpretation: that the whole of the set of buttons to the right or left be flipped 180° as a whole rather than each button individually changing between left and right pointing. The below program does that, with
if dir=='r'
s(i+1:8)=flip(s(i+1:8));
else
s(1:i-1)=flip(s(1:i-1));
end
This version finds no answers, even allowing sequences up to 21 button presses:
clearvars,clc
global h s shortest fid stepNo steps
s='rrrrllll';
h={s}; shortest=22; stepNo=0; steps=zeros(1,9);
fid=fopen('c:VB5 Projects\flooble\eight buttons 2.txt','w')
takeStep();
fclose(fid)
function takeStep()
global h s shortest fid stepNo steps
stepNo=stepNo+1;
for i=1:8
steps(stepNo)=i;
saveh=h;
saves=s;
dir=s(i);
if dir=='r'
s(i+1:8)=flip(s(i+1:8));
else
s(1:i-1)=flip(s(1:i-1));
end
if isequal(s,'lrlrlrlr')
h{end+1}=s;
disp(h)
if length(h)<=shortest
shortest=length(h);
disp(h)
disp(steps)
disp(' ')
for i=1:length(h)
fprintf(fid,'%10s',h{i} );
fprintf(fid,'%3d',steps(i));
end
fprintf(fid,'
');
end
elseif ismember(s,h)
elseif length(h)<shortest
h{end+1}=s;
stepset{length(h)}=steps;
takeStep
end
h=saveh;
s=saves;
end
stepNo=stepNo-1;
end
Edited on March 21, 2023, 2:58 pm
|
Posted by Charlie
on 2023-03-21 14:51:52 |