7
1
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
@JonathanAllan Yes. – fireflame241 – 2017-06-10T01:43:38.413
@JonathanAllan I switched the X and Y for that. I will look over any other errors I may have made. – fireflame241 – 2017-06-10T01:46:27.720
How should we handle the greys? Can we assume that any colour that isn't exactly
#fff
is black or, alternatively, that any colour that isn't#000
is white? – Shaggy – 2017-06-10T14:40:22.137Those exist? Interesting. – CalculatorFeline – 2017-06-10T15:51:59.773
1@Shaggy You may have any behavior regarding pixels which are not white nor black. Updating in the question. – fireflame241 – 2017-06-10T15:58:13.090
2Boo-urns to input validation! (handling 404s) – Shaggy – 2017-06-10T16:50:17.467
To elaborate on the above: there are 2 situations where a 404 might arise. Either x and/or y are "out of bounds" and therefore the image doesn't exist; that would seem, to me, to be input validation, which, from what I've seen, generally doesn't go down well in code golf. Or the images have been deleted, which we shouldn't have to account for. My apologies for not catching this in Sandbox - I was probably pressed for time - but, given that there are only 3 answers so far, I don't think it's too late to change it, leaving a comment on each answer to notify them. – Shaggy – 2017-06-10T20:36:59.433
@Shaggy Xkcd's servers use 404, as far as I can tell, to hold regions of the sky and ground which are all white or all black respectively (Less space than having a fully white image for empty regions of the sky and fully black images for full regions of the ground. See this full map of the comic for reference) These parts are not out of bounds: Even 2n1e gives a 404 error because it is empty sky, not out of bounds. I understand with your second situation - not having any image to look up should not be accounted for.
– fireflame241 – 2017-06-10T20:49:22.390Ah, OK, I didn't know that. In that case, I suppose, I can see the need for error handling. I would, though, suggest expanding on that point in the spec to include this information. – Shaggy – 2017-06-10T20:54:12.053
One more point, again with apologies for not catching it in Sandbox: if an input is negative, is it's sign included in the URL. I'm guessing not but probably best to clarify. – Shaggy – 2017-06-10T21:14:31.323