Your task is to write a program or function which, given two nonzero integers x
and y
, returns a truthy value if the image at coordinates x
east and y
north of xkcd's click and drag comic is mostly white and a falsey value otherwise.
Specifications
- The image should be retrieved from imgs.xkcd.com/clickdrag/[y]n[x]e.png, where
[y]
and[x]
are replaced with the absolute values of the inputy
andx
values. - If
x
is negative,e
should be changed to aw
. Ify
is negative,n
should be changed to as
. - If a 404 error is returned, assume the image is mostly white (output truthy) if
y
is positive and mostly black otherwise. This is because (as far as I can tell) xkcd stores neither completely white regions of the sky nor completely black regions of the ground, leading to less data in their servers and these 404s you must handle. This error handling is not intended to deal with the images not being available. - "white" is defined as rgb #FFFFFF. You may assume that the images are only white(#FFFFFF) and black(#000000), without gray or other colors. "Mostly white" is defined as at least 2097153 pixels of the image are white (because the png the program should retrieve from img.xkcd.com is always 2048x2048 pixels).
- The program may have any behavior when dealing with pixels that are not exactly #FFFFFF nor #000000 but must produce the same output as expected for the test cases.
Example
The image at x=2
, y=9
should be retrieved from imgs.xkcd.com/clickdrag/9n2e.png
and appears as follows (formatted as quote to show border):
It is mostly white, so the program should return a truthy value.
Input / Output
Input should be two integers or a list of two integers representing x
and y
.
Output should be a truthy or falsy value corresponding to if the image is mostly white.
Input and output should be through any standard I/O method.
Test Cases
Truthy (as (x,y))
2,9
7,-17
9, 5
3, 2
-5, 1
1, 3
Falsy (as (x,y))
3, 1
3, -1
7, -16
2, 1
5, 1
17, -1
#fff
is black or, alternatively, that any colour that isn't#000
is white? \$\endgroup\$