Parenthifiable Binary Numbers
Pyth, 10 bytes
!uscG`T.BQ
Try this test suite in the Pyth Compiler.
How it works
(implicit) Store the evaluated input in Q.
.BQ Return the binary string representation of Q.
u Reduce w/base case; set G to .BQ and begin a loop:
`T Return str(10) = "10".
cG Split G (looping variable) at occurrences of "10".
s Join the pieces without separators.
Set G to the returned string.
If the value of G changed, repeat the loop.
This will eventually result in either an empty string or a
non-empty string without occurrences of "10".
! Return (and print) the logical NOT of the resulting string.
TeaScript, 9 bytes 16 18 20 22 24
Saved 2 bytes thanks to @ETHproductions
!x÷W(n,¢)
Woah. That's short. Uses @xnor's approach. This will use the recursive replace function (W
) which will replace all 10
equal to ()
with nothing. If the string is blank it is balanced.
Using a version of TeaScript made after this challenge was posted this could become 7 bytes:
!x÷W(n)
Ungolfed
!xT(2)W(n,``)
Explanation
! // NOT, returns true if empty string, else false
xT(2) // To binary
W(n,``) // n is 10, reclusive replaces 10 or (), with nothing.
Python2, 87 bytes
try:exec"print 1,"+"".join(["],","["][int(c)]for c in bin(input())[2:])
except:print 0
A terrible implementation that abuses syntax errors.