So, today I saw this in my Twitter feed:
«Phil Harvey wants us to partition {1,…,16} into two sets of equal size so each subset has the same sum, sum of squares and sum of cubes.» — posted by @MathsJam and retweeted @haggismaths.
Sounds implausible was my first though. My second thought was that there aren’t actually ALL that many of those: we can actually test this.
So, here’s a short collection of python lines to _do_ that testing.
import itertools
allIdx = range(1,17)
sets = itertools.combinations(allIdx,8)
setpairs = [(list(s), [i for i in allIdx if i not in s]) for s in sets]
def f((s1,s2)): return (sum(s1)-sum(s2), sum(map(lambda n: n**2, s1))-sum(map(lambda n: n**2, s2)), sum(map(lambda n: n**3, s1))-sum(map(lambda n: n**3, s2)))
goodsets = [ss for ss in setpairs if f(ss) == (0,0,0)]
And back comes one single response (actually, two, because the comparison is symmetric).
[([1, 4, 6, 7, 10, 11, 13, 16], [2, 3, 5, 8, 9, 12, 14, 15]),
([2, 3, 5, 8, 9, 12, 14, 15], [1, 4, 6, 7, 10, 11, 13, 16])]
Here’s a similar haskell version:
module Main where
rev [] ys = ys
rev (x:xs) ys = rev xs (x:ys)
subset_splits :: Int -> [a] -> [([a], [a])]
subset_splits n l = ss n l [] []
where ss n l rl rr | n Bool
test (l1, l2) = (sum l1 == sum l2 &&
sum [x*x | x <- l1] == sum [x*x | x <- l2] &&
sum [x*x*x | x <- l1] == sum [x*x*x | x <- l2])
main = do
putStrLn $ show $ filter test $ subset_splits 8 [1 .. 16]