My challenges tend to be a little bit hard and unattractive. So here something easy and fun.
Alcuin's sequence
Alcuin's sequence A(n)
is defined by counting triangles. A(n)
is the number of triangles with integer sides and perimeter n
. This sequence is called after Alcuin of York.
The first few elements of this sequence, starting with n = 0
are:
0, 0, 0, 1, 0, 1, 1, 2, 1, 3, 2, 4, 3, 5, 4, 7, 5, 8, 7, 10, 8, ...
For instance A(9) = 3
, because the only triangles with integer sides and perimeter 9
are 1 - 4 - 4
, 3 - 3 - 3
and 2 - 3 - 4
. You can see the 3 valid triangles down below.
There are some quite interesting pattern in this sequence. For instance A(2*k) = A(2*k - 3)
.
For more information, see A005044 on OEIS.
Challenge
But your challenge is about the binary representation of these numbers. If we convert each sequence number to it's binary representation, put them in column vectors and line them up, it creates a quite interesting binary picture.
In the following picture you can see the binary representation of the sequence numbers A(0), A(1), ..., A(149)
. In the first column you can see the binary representation of A(1)
, in the second column the representation of A(1)
, and so on.
You can see some sort of repeating pattern in this picture. It even looks kinda like fractals, if you look for instance at the image with the sequence numbers A(600), A(601), ..., A(899)
.
Your job is to generate such an image. Your function, your script will receive two integer 0 <= m < n
, and it has to generate the binary image of Alcuin's sequence A(m), A(m+1), A(m+2), ..., A(n-2), A(n-1)
. So the input 0, 150
generates the first picture, the input 600, 900
the second picture.
You can use any popular graphics format you want. Let's say every format that can be converted to png using image.online-convert.com. Alternatively, you may display the image on screen. No leading white rows are allowed!
This is code-golf. So the shortest code (in bytes) wins.
white=1 and black=0
or the other way around? \$\endgroup\$white=0 and black=1
. So the other way.A(0)
produces a white column,A(9)=3
produces a white column with 2 black pixel at the bottom. \$\endgroup\$0,0,0,1,0,2
while the list at the beginning of the question says0,0,0,1,0,1
. \$\endgroup\$