My stovetop has 10 different settings of heat (0 through 9) and a very odd way of cycling through them.
When I hit plus (
+
) it increments the number, unless the number is 9 in which case it becomes 0, or the number is 0 in which case it becomes 9.When I hit minus (
-
) it decrements the number, unless the number is zero in which case it becomes 4.
There are no other temperature control buttons.
So when I am cooking on one temperature and I want to change to another, it's always a bit of a puzzle to figure out what the easiest way to get to that temperature is.
In this challenge you will take a starting temperature and a desired temperature and give the shortest sequence of button presses to get from the starting temperature to the desired temperature.
You should take input as two integers on the range 0-9 and output a sequence of instructions. You may output the instructions either as the characters/strings +
and -
or as the numbers 1
and -1
. If there are two equally minimal sequences you may output either or both.
This is code-golf so the goal is to minimize the size of your source code as counted by the number of bytes.
Test cases
0 0 -> ""
0 1 -> "----"
0 2 -> "---"
0 3 -> "--"
0 4 -> "-"
0 5 -> "-+"
0 6 -> "-++"
0 7 -> "+--"
0 8 -> "+-"
0 9 -> "+"
1 0 -> "-"
1 1 -> ""
1 2 -> "+"
1 3 -> "++"
1 4 -> "--"
1 5 -> "--+"
1 6 -> "--++"
1 7 -> "-+--"
1 8 -> "-+-"
1 9 -> "-+"
2 0 -> "--"
2 1 -> "-"
2 2 -> ""
2 3 -> "+"
2 4 -> "++"
2 5 -> "+++"
2 6 -> "++++"
2 7 -> "+++++" or "--+--"
2 8 -> "--+-"
2 9 -> "--+"
8 0 -> "++"
8 1 -> "++----"
8 2 -> "++---"
8 3 -> "++--"
8 4 -> "++-"
8 5 -> "---"
8 6 -> "--"
8 7 -> "-"
8 8 -> ""
8 9 -> "+"
9 0 -> "+"
9 1 -> "+----"
9 2 -> "+---"
9 3 -> "+--"
9 4 -> "+-"
9 5 -> "+-+"
9 6 -> "---"
9 7 -> "--"
9 8 -> "-"
9 9 -> ""
0
for-
and1
for+
? \$\endgroup\$-1
and1
. \$\endgroup\$(2,7)
,(3,8)
,(4,9)
and(5,0)
. (And+++++
is one of the solutions for all of them.) \$\endgroup\$