Project Euler Lab - Problem 103

#103 - Special Subset Sums: Optimum

● AppliedOfficial difficulty: 14%Maximize/minimize an objectiveTier C - reduced scale in browser; full scale in notebookNot viewed
↖ Euler Lab

Let \(S(A)\) represent the sum of elements in set \(A\) of size \(n\). We shall call it a special sum set if for any two non-empty disjoint subsets, \(B\) and \(C\), the following properties are true:

  1. \(S(B) \ne S(C)\); that is, sums of subsets cannot be equal.
  2. If \(B\) contains more elements than \(C\) then \(S(B) \gt S(C)\).

If \(S(A)\) is minimised for a given \(n\), we shall call it an optimum special sum set. The first five optimum special sum sets are given below.

  • \(n = 1\): \(\{1\}\)
  • \(n = 2\): \(\{1, 2\}\)
  • \(n = 3\): \(\{2, 3, 4\}\)
  • \(n = 4\): \(\{3, 5, 6, 7\}\)
  • \(n = 5\): \(\{6, 9, 11, 12, 13\}\)

It seems that for a given optimum set, \(A = \{a_1, a_2, \dots, a_n\}\), the next optimum set is of the form \(B = \{b, a_1 + b, a_2 + b, \dots, a_n + b\}\), where \(b\) is the "middle" element on the previous row.

By applying this "rule" we would expect the optimum set for \(n = 6\) to be \(A = \{11, 17, 20, 22, 23, 24\}\), with \(S(A) = 117\). However, this is not the optimum set, as we have merely applied an algorithm to provide a near optimum set. The optimum set for \(n = 6\) is \(A = \{11, 18, 19, 20, 22, 25\}\), with \(S(A) = 115\) and corresponding set string: 111819202225.

Given that \(A\) is an optimum special sum set for \(n = 7\), find its set string.

NOTE: This problem is related to Problem 105 and Problem 106.

This problem is taken from Project Euler, Problem 103.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=103. Published Friday, 26th August 2005, 06:00 pm. Solved by 9,543 members at time of mirroring.

Why this is useful

Algorithmic Development. Optimal substructure and state-space reasoning are exactly how American-option pricing and optimal execution are solved (Phases 13, 16).

We classify relevance honestly - not every Euler problem is a trading application.

Learning mode

Pick how much scaffolding you want. Your choice is remembered per problem.

Scratchpad

Mathematical notes, formulas, pseudocode, hypotheses, complexity notes. Saved automatically with your progress.

Python workbench

Tier C - reduced scale in browser; full scale in notebook
Browser runs a reduced, clearly-labelled educational scale; the original scale is provided in a local notebook.

Real Python (Pyodide) in a sandboxed Web Worker - no network, no filesystem, no DOM access. Ctrl/Cmd+Enter runs. Escape leaves the editor. Stop terminates the worker.

Python runtime not loaded (it boots on first run - a one-time local load).

Check your answer

Answers are checked against a salted hash held in a separate file - not printed in this page. This prevents accidental spoilers; it is not cryptographic protection (see the build notes).

Progressive hints

Confidence

Low confidence schedules this problem for spaced review, even if you solved it.

Reference solution

Spoiler
The complete original explanation (interpretation, naive approach, insight, proof, complexity, Python implementation, tests, common mistakes, alternatives) is hidden and lazy-loaded. Reveal it only after a meaningful attempt - the struggle is where the learning happens.