Your goal is to write a full program or function that takes 5 positive integers and a string with an image filename as input [X1,Y1], [X2,Y2], N, image.jpg
in any reasonable format, where:
- First couple
[X1,Y1]
are the top leftX
,Y
coordinates (<=20
) of the blue rectangle area in the example picture (16,11
). - Second couple
[X2,Y2]
are the bottom rightX
,Y
coordinates (<=20
) of the blue rectangle area in the example picture (20,22
). - Fifth number
N
such0 <= N <= 9
is the number that has to be found. - Sixth parameter is a string with the filename of this JPG picture.
Output how many of N
's are present in the indicated area (outlined in blue in the picture for this example):
Click here to obtain a bigger clean version of the same image.
In the picture there are 500 numbers from 0
to 9
(included) arranged in 20 columnns per 25 rows, in monospaced Courier New
font.
Each different number has a different color (you can take advantage of this fact or ignore it and consider or convert the image in monocrome if that helps you).
Test cases:
[4,4],[13,5],1,image.jpg > 4 (outlined in red)
[4,4],[13,5],4,image.jpg > 2 (outlined in red)
[17,5],[17,5],2,image.jpg > 1 (outlined in magenta)
[17,5],[17,5],9,image.jpg > 0 (outlined in magenta)
[20,8],[20,9],3,image.jpg > 1 (outlined in cyan)
[20,8],[20,9],2,image.jpg > 0 (outlined in cyan)
[16,11],[20,22],0,image.jpg > 8 (outlined in blue)
[16,11],[20,22],3,image.jpg > 9 (outlined in blue)
[3,14],[11,20],7,image.jpg > 6 (outlined in green)
[3,14],[11,20],5,image.jpg > 6 (outlined in green)
[3,14],[11,20],8,image.jpg > 8 (outlined in green)
[1,1],[20,25],0,image.jpg > 47 (whole picture)
[1,1],[20,25],8,image.jpg > 50 (whole picture)
[1,1],[20,25],1,image.jpg > 55 (whole picture)
Rules:
- This is code-golf so the shortest code wins.
- You must take as input this JPG file.
- You are not allowed to hardcode the matrix of numbers represented in the JPG, or the results.
- Standard loopholes are forbidden.