Charcoal, 3837 35 bytes
≔⎇№θx…θ⌕θxθθ≔⁰ηFθ≡ιn≦⊕ηd≦⊖ηm≦⊗ηh≦⊘ηrIη≔⁰ηF⎇№θx…θ⌕θxθ≡ιn≦⊕ηd≦⊖ηm≦⊗ηh≦⊘ηrIη
Try it online!Try it online! Link is to verbose version of code. Inspired by @RickHitchcock's answer. Explanation:
≔⎇№θx…θ⌕θxθθ
Truncate the input at the x
if there is one. (I tried using a while
loop but for some reason the variable got reset after the end of the loop, and an if
requires an else
so isn't very golfy.)
≔⁰η
Clear the variable.
Fθ≡ιF⎇№θx…θ⌕θxθ≡ι
LoopTruncate the input at the x
if there is one, then loop over and switch on each character of the(the remainder of) the input.
n≦⊕η
n
increments the variable.
d≦⊖η
d
decrements the variable.
m≦⊗η
m
multiplies the variable by two (i.e. doubles).
h≦⊘η
h
halves the variable.
rIη
r
prints the variable cast to string.