38
1
A number is balanced if the sum of the digits on each half of the number is equal, so: 1423
is balanced because 1+4 = 2+3
, so is: 42615
because 4+2=1+5
. Note that the middle digit is not included on either side (or it's included on both sides) if there's an odd number of digits.
Challenge:
Take a positive integer as input, and output a truthy value if it's balanced and a falsy value if it's unbalanced.
Test cases (true)
1
6
11
141
1221
23281453796004414
523428121656666655655556655656502809745249552466339089702361716477983610754966885128041975406005088
Test cases (false)
10
12
110
15421
5234095123508321
6240911314399072459493765661191058613491863144152352262897351988250431140546660035648795316740212454
There will not be numbers starting with zero, for instance 00032
instead of 32
. You must support numbers up to at least 100 digits (so larger than 2^64-1
). As always, optional input format, so you may surround the number with apostrophes if desired.
Can't you use
Ë
instead of\
Q`? – Erik the Outgolfer – 2017-07-11T19:33:48.437@EriktheOutgolfer:
Ë
was a different command back when this challenge was made, so unfortunately not. – Emigna – 2017-07-11T19:57:45.100