My stovetop has 10 (0 through 9) different settings of heat and a very odd way of cycling through them.
It always starts at 0
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.
In this challenge you will take as input a string of commands and output which setting my stovetop ends up on after running that sequence.
Answers will be scored in bytes with fewer bytes being better.
Input
You may take input in any of the following formats:
- A list/array/vector/stream of booleans/1s or 0s/1s or -1s
- A string (or list/array/vector/stream) of two different characters (which should be consistent for your program)
And you may output
An integer on the range 0-9.
A character on the range '0'-'9'.
A string of size 1 consisting of the above.
Testcases
Input as a string -
for decrement and +
for increment.
: 0
- : 4
+ : 9
-- : 3
-+ : 5
+- : 8
++ : 0
--- : 2
--+ : 4
-+- : 4
-++ : 6
+-- : 7
+-+ : 9
++- : 4
+++ : 9
---- : 1
---+ : 3
f(f(f(0,M),M),P)
? (for the stringMMP
) What about(M)(M)(P)
? \$\endgroup\$+
=+++
because they both give 9), they certainly don't form a group. Something like 5+9 is not well defined (9 can be represented by any odd number of+
s so 5+9 could be 6, 8 or 0). Under the equivalence of the sequences themselves, they also don't form a group. They are isomorphic binary strings under concatenation and thus don't have an inverse. You can relax the latter into a category, and try some other stuff but nothing really interesting come out of it. I don't think this corresponds to any mathematical structure of any note. \$\endgroup\$