16
Introduction
This is a follow-up of this challenge where you're taking the role of that person's evil twin. Being evil you don't want to maximize your share, but rather be as unfair as possible and you're not going to make it too obvious, that's why you came up with the following scheme:
You're going to tell the others that you want to be as fair as possible like your sibling and thus you're going to split the integer into pieces of equal length. So for each integer you will come up with the right amount of people such that the difference between the largest and the smallest piece is maximal.
For example if you're given the integer 6567
you could leave it as is, split it into two pieces 65,67
or four 6,5,6,7
. This gives you the following maximal differences:
6567 -> max() = 0
65,67 -> max(|65-67|) = 2
6,5,6,7 -> max(|6-5|,|6-5|,|6-6|,|6-7|,|5-6|,|5-7|,|6-7|) = 2
Since you only want to be evil you don't prefer 67
over 7
and thus you will output either 2
or 4
.
Another (less special case); given the integer 121131
you could split it like this:
121131 -> max() = 0
121,131 -> max(|121-131|) = 10
12,11,31 -> max(|12-11|,|12-31|,|11-31|) = 20
1,2,1,1,3,1 -> max(…) = 2
This time there's only one solution - namely 3
- since with three people the difference is maximal.
Challenge
Given an integer determine any possible way of being maximally evil and report the number of people needed to achieve this.
Rules
- Input will always be ≥ 1
- Input can be either an integer, list of digits or string
- You don't have to handle invalid inputs
Testcases
You only need to report the resulting number of people needed, the possible partitions are only for illustration:
In -> splits (difference) -> Out
1 -> [1] (0) -> 1
10 -> [1,0] (1) -> 2
11 -> [11] or [1,1] (0) -> 1 or 2
12 -> [1,2] (1) -> 2
42 -> [4,2] (2) -> 2
101 -> [1,0,1] (1) -> 3
2222 -> [2222] or [22,22] or [2,2,2,2] (0) -> 1 or 2 or 4
6567 -> [65,67] or [6,5,6,7] (2) -> 2 or 4
123000 -> [123,000] (123) -> 2
123001 -> [123,001] (122) -> 2
121131 -> [12,11,31] (20) -> 3
294884 -> [294,884] (590) -> 2
192884729 -> [192,884,729] (692) -> 3
123456189012 -> [123456,189012] (65556) -> 2
123457117346 -> [1234,5711,7346] (6112) -> 3
1I wonder if someone will submit a solution in the programming language evil? :D – SK19 – 2018-03-17T00:47:42.853