Post History
Perl, 45 bytes Takes numerical string on stdin. Prints 0 if balanced; non-zero otherwise. perl -ple'for$i(/./g){$n{()=/$i/g}++}$_=%n-1' Comments: -p - read line into $_, manipulate, then pr...
#1: Initial revision
# Perl, 45 bytes
Takes numerical string on stdin. Prints `0` if balanced; non-zero otherwise.
```
perl -ple'for$i(/./g){$n{()=/$i/g}++}$_=%n-1'
```
Comments:
* `-p` - read line into `$_`, manipulate, then print
* `-l` - strip newline from `$_`, add back when printing
* `for $i (/./g) {...}` - split `$_` into individual characters, process each as `$i`
* `()=/$i/g` - count `$i`s in `$_`
* `$n{...}++` - store count as key of hash
* `%n-1` - zero iff exactly one key in hash (ie. input is balanced)
[Try it online!][TIO-mmiaws7x]
[TIO-mmiaws7x]: https://tio.run/##ZY/dboQgEIXvfQqSYla7dYEB/Kmxr7LZC7UmBg3Qq82@ei02AtuUqzNfzjkzrL2e5faChkUj2xuLPm9a9cYkq56UHdApNaj4QKc3fG0TQ9A7urwSMrZJqrosbzeXw1NGLmTM71jds7wjeCLj43x@4GuXqoJtG3Mpq7/6BMCrpo4sQODCSy5kGfUT51J6LcoycAZ7oqqbp67fmQYHA@BcxMQOHOEBcODAgAUghZRCiLCv8c@Dqtp/Mdxm48ylDHrfFAZXGQffUP8h9VF6pI9D5b8UjR7KgAKnsfl7We20KLMV6/wD "Perl 5 – Try It Online"
