Skip over navigation
Cambridge University Faculty of Mathematics NRich logo
menu search
  • Teachers expand_more
    • Early years
    • Primary
    • Secondary
    • Post-16
    • Events
    • Professional development
  • Students expand_more
    • Primary
    • Secondary
    • Post-16
  • Parents expand_more
    • Early Years
    • Primary
    • Secondary
    • Post-16
  • Problem-Solving Schools
  • About NRICH expand_more
    • About us
    • Impact stories
    • Support us
    • Our funders
    • Contact us
  • search

Or search by topic

Number and algebra

  • The Number System and Place Value
  • Calculations and Numerical Methods
  • Fractions, Decimals, Percentages, Ratio and Proportion
  • Properties of Numbers
  • Patterns, Sequences and Structure
  • Algebraic expressions, equations and formulae
  • Coordinates, Functions and Graphs

Geometry and measure

  • Angles, Polygons, and Geometrical Proof
  • 3D Geometry, Shape and Space
  • Measuring and calculating with units
  • Transformations and constructions
  • Pythagoras and Trigonometry
  • Vectors and Matrices

Probability and statistics

  • Handling, Processing and Representing Data
  • Probability

Working mathematically

  • Thinking mathematically
  • Developing positive attitudes
  • Cross-curricular contexts

Advanced mathematics

  • Decision Mathematics and Combinatorics
  • Advanced Probability and Statistics
  • Mechanics
  • Calculus

For younger learners

  • Early Years Foundation Stage

Knapsack

Age 14 to 16
Challenge Level Yellow starYellow star
  • Problem
  • Getting Started
  • Student Solutions
  • Teachers' Resources
knapsack

This problem is based on the idea of Knapsack codes.

You have worked out a secret code with a friend. Every letter in the alphabet can be represented by a binary value that is given in the lookup table below.

You go off on a camping trip with 5 sticks in your knapsack. They have lengths of 1,3,5,10 and 20 centimetres, these will help you decode any message your friend sends.

A coded message arrives. It is the number 31. To decode the message you must work out which sticks you need to make a length of 31cm and convert this information into the binary code that tells you the letter. Decoding will be easy because your sticks form part of a superincreasing series (each stick is longer than the sum of the lengths of all the smaller sticks).

Taking the largest length off first leaves 31-20 = 11 so the coded letter used the 20 cm stick. 11-10 = 1 so the coded letter also involves the 10cm stick. With 1 left the 5-stick and the 3-stick are not used, just the 1-stick.

This gives you a binary code of 10011 (1x1cm+0x3cm+0x5cm+1x10cm+1x20cm).

So using the binary lookup table, the number 31 represents is 10011, which is the letter s.

Lookup Table

Letter
Binary Reference
Letter
Binary Reference
a
00001
n
01110
b
00010
o
01111
c
00011
p
10000
d
00100
q
10001
e
00101
r
10010
f
00110
s
10011
g
00111
t
10100
h
01000
u
10101
i
01001
v
10110
j
01010
w
10111
k
01011
x
11000
l
01100
y
11001
m
01101
z
11010


Using the sticks in your knapsack decode the message: 33,18, 20, 1, 31, 20, 30, 33.

That was easy, but say your knapsack code involved a non-superincreasing series that used 1,2,3,4,5cm sticks.

Using this knapsack can you decode the message 1, 5, 14, 4, 5, 8, 10, 5, 4, 7, 9?

Can you explain why superincreasing series are so much easier to decode?

You may also like

N000ughty Thoughts

How many noughts are at the end of these giant numbers?

Mod 3

Prove that if a^2+b^2 is a multiple of 3 then both a and b are multiples of 3.

Novemberish

a) A four digit number (in base 10) aabb is a perfect square. Discuss ways of systematically finding this number. (b) Prove that 11^{10}-1 is divisible by 100.

  • Tech help
  • Accessibility Statement
  • Sign up to our newsletter
  • Twitter X logo

The NRICH Project aims to enrich the mathematical experiences of all learners. To support this aim, members of the NRICH team work in a wide range of capacities, including providing professional development for teachers wishing to embed rich mathematical tasks into everyday classroom practice.

NRICH is part of the family of activities in the Millennium Mathematics Project.

University of Cambridge logo NRICH logo