Project Euler Lab - Problem 162

#162 - Hexadecimal Numbers

● AdvancedOfficial difficulty: 33%PolynomialsTier C - reduced scale in browser; full scale in notebookNot viewed
↖ Euler Lab

In the hexadecimal number system numbers are represented using \(16\) different digits: \[0,1,2,3,4,5,6,7,8,9,\mathrm A,\mathrm B,\mathrm C,\mathrm D,\mathrm E,\mathrm F.\]

The hexadecimal number \(\mathrm{AF}\) when written in the decimal number system equals \(10 \times 16 + 15 = 175\).

In the \(3\)-digit hexadecimal numbers \(10\mathrm A\), \(1\mathrm A0\), \(\mathrm A10\), and \(\mathrm A01\) the digits \(0\), \(1\) and \(\mathrm A\) are all present.
Like numbers written in base ten we write hexadecimal numbers without leading zeroes.

How many hexadecimal numbers containing at most sixteen hexadecimal digits exist with all of the digits \(0\), \(1\), and \(\mathrm A\) present at least once?
Give your answer as a hexadecimal number.

(A, B, C, D, E and F in upper case, without any leading or trailing code that marks the number as hexadecimal and without leading zeroes, e.g. 1A3F and not: 1a3f and not 0x1a3f and not $1A3F and not #1A3F and not 0000001A3F)

This problem is taken from Project Euler, Problem 162.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=162. Published Friday, 5th October 2007, 10:00 pm. Solved by 6,137 members at time of mirroring.

Why this is useful

General Problem Solving. Builds computational thinking, decomposition, and debugging discipline - transferable, without a specific financial application.

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

Prerequisites

Lessons that prepare you:
1.1 Sets, Functions, and Relations · 2.1 Functions, Limits, and Continuity · 4.2 Linear Maps, Matrices, Rank, and the Null Space

Recommended stepping-stone problems: #135 · #144 · #136

Concepts: algebra

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.