Skip to main content
deleted 153 characters in body
Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281

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.

Charcoal, 38 bytes

≔⎇№θx…θ⌕θxθθ≔⁰ηFθ≡ιn≦⊕ηd≦⊖ηm≦⊗ηh≦⊘ηrIη

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θ≡ι

Loop over and switch on each character of 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.

Charcoal, 37 35 bytes

≔⁰ηF⎇№θx…θ⌕θxθ≡ιn≦⊕ηd≦⊖ηm≦⊗ηh≦⊘ηrIη

Try it online! Link is to verbose version of code. Inspired by @RickHitchcock's answer. Explanation:

≔⁰η

Clear the variable.

F⎇№θx…θ⌕θxθ≡ι

Truncate the input at the x if there is one, then loop over and switch on each character of (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.

added 94 characters in body
Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281

Charcoal, 3738 bytes

W№θx≔…θ⌕θxθ≔⁰ηFθ≡ιn≦⊕ηd≦⊖ηm≦⊗ηh≦⊘ηrIη≔⎇№θx…θ⌕θxθθ≔⁰ηFθ≡ιn≦⊕ηd≦⊖ηm≦⊗ηh≦⊘ηrIη

Try it online! Link is to verbose version of code. Inspired by @RickHitchcock's answer. Explanation:

W№θx≔…θ⌕θxθ≔⎇№θx…θ⌕θxθθ

Truncate the input at the x if there is one. (I tried using a Whilewhile is golfier thanloop but for some reason the variable got reset after the end of the loop, and an if as it doesn't needrequires an else so isn't very golfy.)

≔⁰η

Clear the variable.

Fθ≡ι

Loop over and switch on each character of 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.

Charcoal, 37 bytes

W№θx≔…θ⌕θxθ≔⁰ηFθ≡ιn≦⊕ηd≦⊖ηm≦⊗ηh≦⊘ηrIη

Try it online! Link is to verbose version of code. Inspired by @RickHitchcock's answer. Explanation:

W№θx≔…θ⌕θxθ

Truncate the input at the x if there is one. (While is golfier than if as it doesn't need an else.)

≔⁰η

Clear the variable.

Fθ≡ι

Loop over and switch on each character of 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.

Charcoal, 38 bytes

≔⎇№θx…θ⌕θxθθ≔⁰ηFθ≡ιn≦⊕ηd≦⊖ηm≦⊗ηh≦⊘ηrIη

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θ≡ι

Loop over and switch on each character of 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.

Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281

Charcoal, 37 bytes

W№θx≔…θ⌕θxθ≔⁰ηFθ≡ιn≦⊕ηd≦⊖ηm≦⊗ηh≦⊘ηrIη

Try it online! Link is to verbose version of code. Inspired by @RickHitchcock's answer. Explanation:

W№θx≔…θ⌕θxθ

Truncate the input at the x if there is one. (While is golfier than if as it doesn't need an else.)

≔⁰η

Clear the variable.

Fθ≡ι

Loop over and switch on each character of 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.