Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Revisions

5 of 5
added 8 characters in body; added 2 characters in body

Bash + GNU utilities, 17 bytes

tr '(|)D:-' 0-3\ 

Try it online!

Note: There's a space character after the backslash.

Input on stdin, output on stdout.

The challenge doesn't specify the format of the output. Depending on the input, this program may print the output in either %2d or %3d format (that is, with one or two spaces before the 0, 1, 2, or 3).

If that's not acceptable, then

tr -s '(|)D:-' 0-3\

(20 bytes) always prints the digit in %2d format. (There's a space after the backslash here too.)

Or

tr '(|)D:-' 0-4|tr -d 4

(23 bytes) prints just the digit (with no spaces).

AltStyle によって変換されたページ (->オリジナル) /