13
1
Description
We consider an integer with at least 3 digits triple-balanced if, when split into three parts, the digits in every part sum up to the same number. We split numbers as follows:
abcdefghi - Standard case: the number of digits is divisable through 3:
abc def ghi
abcdefgh - Number % 3 == 2: The outer groups are both assigned another digit
abc de fgh (the inner group will have one digit less than both outer groups)
abcdefghij - Number % 3 == 1: The inner group is assigned the extra digit
abc defg hij (the inner group will have one digit more than the outer groups)
Challenge
Your task is to write a program, that, given an integer with at least 3 digits, determines whether the given number is triple-balanced and outputs a truthy or falsy value based on it's result.
Test cases
333 -> True
343 -> False
3123 -> True
34725 -> True
456456 -> False
123222321 -> True
This is code-golf, so standard loopholes apply and may the shortest answer in bytes win!
1As I understand it, if you can split it evenly, you should. – totallyhuman – 2017-07-17T16:46:25.813
@Mr.Xcoder you split it into three parts (it still doesn't work as per @MagicOctopusUnr's comment:
when split in three parts,
– Stephen – 2017-07-17T16:46:49.047@geokavel But then you're violating
when split in three parts,
– Stephen – 2017-07-17T16:47:40.0534
Consider using the Sandbox, to avoid such a situation in the future.
– Mr. Xcoder – 2017-07-17T16:51:47.8202Whoops! I'm sorry for the confusion about the test cases, apparently I had some sort of twist in my head. Now that they are corrected, I hope you vote to reopen my challenge. – racer290 – 2017-07-17T17:08:41.097
5By default, input is allowed to be taken as a string. Can it be taken as an array of digits? – Luis Mendo – 2017-07-17T22:16:43.350