The Hexadecimal Digit Canon Challenge


In the Hexadecimal Canon, every number is first stripped of all insignificant zeros and reordered into its most “pure” form. The value of a number is not what it looks like at first glance, but what remains after this canonical purification.

All numbers in this problem are written in base 16 (hexadecimal). The available digits are

\[0,1,2,3,4,5,6,7,8,9,\text{A},\text{B},\text{C},\text{D},\text{E},\text{F},\]

with \(\text{A}=10,\dots,\text{F}=15.\)


The Digit–Canonical Function

For any positive hexadecimal integer \(d > 0\), define the function \(f(d)\) as follows:

  1. Write \(d\) in hexadecimal.
  2. Sort its hexadecimal digits in ascending order.
  3. Remove all zero digits.
  4. Interpret the remaining digits again as a hexadecimal number.

Since $d > 0$, removing zero digits always leaves at least one hexadecimal digit.


Examples

  • Example 1: \(d = \texttt{0x3A04}\). Digits: \(3, A, 0, 4.\) Sorted: \(0, 3, 4, A.\) Remove zeros → \(3, 4, A\). Result: \(f(\texttt{0x3A04}) = \texttt{0x34A}\)

  • Example 2 \(d = \texttt{0xF102}\). Digits: \(F, 1, 0, 2\). Sorted: \(0, 1, 2, F\). Remove zeros → \(1, 2, F\). Result: \(f(\texttt{0xF102}) = \texttt{0x12F}\)

  • Example 3 \(d = \texttt{0x800}\). Digits: \(8, 0, 0\). Sorted: \(0, 0, 8\). Remove zeros → \(8\). Result: \(f(\texttt{0x800}) = \texttt{0x8}\)

  • Example 4: $d = \texttt{0xA11B0}$. Digits: $A,1,1,B,0$. Sorted: $0,1,1,A,B$. Remove zeros → $1,1,A,B$. Result: $f(\texttt{0xA11B0}) = \texttt{0x11AB}$.


The Cumulative Sum

Let \(S(n)\) denote the sum of \(f(d)\) over all positive hexadecimal integers with at most \(n\) hexadecimal digits.

For example:

  • For \(n = \texttt{0x1}\), the result is \(S(\texttt{0x1}) = \texttt{0x78}\)
  • For \(n = \texttt{0x3}\), the result is \(S(\texttt{0x3}) = \texttt{0x4077C0}\)

Important: All values of \(S(n)\) are to be reported in hexadecimal notation.


Challenge Levels 🏅

Compute \(S(n)\) for the following four difficulty tiers:

Tier Value of \(n\) (hexadecimal) Your Result (hexadecimal)
🎗 Warm-up \(n = \; \texttt{0x5}\) \(S(n) = \;\_\_\_\_\_\_\_\_\_\_\_\_\)
🥉 Bronze \(n = \; \texttt{0xA}\) \(S(n) = \;\_\_\_\_\_\_\_\_\_\_\_\_\)
🥈 Silver \(n = \; \texttt{0xAA}\) \(S(n) = \;\_\_\_\_\_\_\_\_\_\_\_\_\, \,\) (first & last 10 hex digits)
🥇 Gold \(n = \; \texttt{0xAAA}\) \(S(n) \equiv \;\_\_\_\_\_\_\_\_\_\_\_\_ \pmod{\texttt{0x1FFFFFFFFFFFFFFF}}\)


For the silver medal, report only the first 10 and last 10 hexadecimal digits of \(S(n)\).
Here, “first 10” means the first 10 digits of the standard hexadecimal representation of \(S(n)\), and “last 10” means the last 10 digits (equivalently \(S(n) \bmod 16^{10}\)). The problem is designed so that neither part has leading zeros, and both substrings consist of exactly 10 hexadecimal digits.

For the gold medal, report your hexadecimal answer modulo \(\texttt{0x1FFFFFFFFFFFFFFF}.\)

Check your solution (enter hex, e.g. 34A or 34a):








💡 Solution coming soon: A full, step-by-step solution—including the underlying combinatorics and an efficient implementation—will be published on this blog shortly. Stay tuned!




Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • Google Gemini updates: Flash 1.5, Gemma 2 and Project Astra
  • Displaying External Posts on Your al-folio Blog
  • Solving a Mini Sudoku in 6502 Assembly
  • Short Notes: Equal Partitions, Products, and Decimal Structure
  • Short Notes: On a Curious Prefix-Sum Problem