Introduction
In this challenge you should split an integer into two pieces. Since nobody likes getting the smaller piece of cake, your goal is to be as fair as possible. For example if you wanted to split the integer 7129
into two pieces, there are 3 possible ways of doing so.
7,129
, 71,29
and 712,9
are all possibilities, but 71,29
is the fairest way of splitting it into two pieces because it minimizes the difference between the two:
7 129 -> |7-129| = 122
71 29 -> |71-29| = 42
712 9 -> |712-9| = 703
Challenge
Given an integer determine the best possible way of partitioning it as described above and report the resulting difference.
Rules
- Splitting only makes sense for integers of length at least two, the input will always be ≥ 10
- Input can be either an integer, list of digits or a string
- You don't have to handle invalid input
Testcases
You only need to report the resulting difference, the partitioning is only here for illustration:
10 -> 1,0 -> 1
11 -> 1,1 -> 0
12 -> 1,2 -> 1
13 -> 1,3 -> 2
101 -> 1,01 -> 0
128 -> 12,8 -> 4
313 -> 3,13 -> 10
1003 -> 1,003 -> 2
7129 -> 71,29 -> 42
81128 -> 81,128 -> 47
999999 -> 999,999 -> 0
9999999 -> 999,9999 or 9999,999 -> 9000