| 26 October 2026 | Challenge 043 |
Olympic Equations
Task 1: Olympic Rings
There are 5 rings in the Olympic Logo as shown below. They are color coded as in Blue, Black, Red, Yellow and Green.

We have allocated some numbers to these rings as below:
Blue: 8
Yellow: 7
Green: 5
Red: 9
The Black ring is empty currently. You are given the numbers 1, 2, 3, 4 and 6. Write a script to place these numbers in the rings so that the sum of numbers in each ring is exactly 11.
Solution
There are nine numbers to be distributed within the rings, five rings that specify an equation for the numbers they contain and four numbers that are given.
This means there are nine variables and nine linear equations on these variables. If these equations were linearly independent, they would specify a unique solution. In this case, the specification of a target set for the unknown values would make the problem over-determined.
Otherwise - if the equations were linearly dependent - we had to search for a solution that matches the specification. But let’s just try…
Taking \(x_i\) as the value in the segments from left to right and top to bottom, we find the linear equations:
\[\begin{pmatrix} 1 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 1 & 0 & 1 \\ 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ \end{pmatrix} \begin{pmatrix} x_1 \\ x_2 \\ x_3 \\ x_4 \\ x_5 \\ x_6 \\ x_7 \\ x_8 \\ x_9 \\ \end{pmatrix} = \begin{pmatrix} 11 \\ 11 \\ 11 \\ 11 \\ 11 \\ 9 \\ 8 \\ 5 \\ 7 \\ \end{pmatrix}\]This can be solved with any solver - if the matrix’ determinant is nonzero. Actually it is \(1\).
Perl
Using PDL::LinearAlgebra::msolve to solve the equations.
use strict;
use warnings;
use PDL;
use PDL::LinearAlgebra;
sub olympic_rings {
my $a = pdl
'1 0 0 1 0 0 0 0 0;
0 1 0 0 1 1 0 0 0;
0 0 1 0 0 0 1 0 0;
0 0 0 1 1 0 0 1 0;
0 0 0 0 0 1 1 0 1;
1 0 0 0 0 0 0 0 0;
0 0 1 0 0 0 0 0 0;
0 0 0 0 0 0 0 1 0;
0 0 0 0 0 0 0 0 1';
my $b = pdl '11 11 11 11 11 9 8 5 7';
msolve($a, $b->dummy(0))->flat;
}
Calling the full program from the shell:
$ perl/ch-1.pl
[9 6 8 2 4 1 3 5 7]
See the full solution to task 1.
J
Almost the same in J. It comes with a builtin solver:
a =: ". S: 0 cutopen 0 : 0
1 0 0 1 0 0 0 0 0
0 1 0 0 1 1 0 0 0
0 0 1 0 0 0 1 0 0
0 0 0 1 1 0 0 1 0
0 0 0 0 0 1 1 0 1
1 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 1
)
b =: 11 11 11 11 11 9 8 5 7
b %. a
9 6 8 2 4 1 3 5 7
See the full solution.
Task 2: Self-descriptive Numbers
Write a script to generate Self-descriptive Numbers in a given base.
In mathematics, a self-descriptive number is an integer m that in a given base b is b digits long in which each digit d at position n (the most significant digit being at position 0 and the least significant at position b - 1) counts how many instances of digit n are in m.
For example, if the given base is 10, then script should print 6210001000. For more information, please checkout wiki page.
Solution
Use a wormhole to access the solution in week 107.