23
Given an image, output the [width in pixels of a full vertical section]1 (if one exists). If no vertical section exists, output 0
.
Input may be provided as a local file or a nested array. If you choose to take input as a nested array, white pixels should be represented by a truthy value while non-white pixels should be represented by a falsey value.
1. the number of contiguous, all-white columns
You can assume that
no image will be larger than 1000 square pixels
there will be no more than one full vertical section per image
Examples
Inputs:
Outputs:
50
57
0
0
Here are the first two examples, highlighted (in yellow) to show their sections:
Can there be islands of black in the middle so that there's multiple vertical sections? – xnor – 2016-02-29T22:41:20.200
@xnor: There will only ever be one full vertical section per image. I'll add that to the spec. – Zach Gates – 2016-02-29T22:43:26.513
My code is outputting 50 for the first test case, but correct numbers for the last 3, with the vertical slice from columns 233 to 282 (=50 pixels across). Can you confirm 48 is the correct number? – David – 2016-02-29T23:03:23.940
@David: I see the correct slice from columns 232 to 282 (exclusive). I believe you're right. – Zach Gates – 2016-02-29T23:10:27.357
If we take input as a nested array, can the nesting go either way (column nesting vs row nesting)? – xnor – 2016-02-29T23:28:55.977
@xnor: Only row nesting ;) – Zach Gates – 2016-02-29T23:30:02.640
2
I don't think anyone's having problems, but it might be worth explicitly mentioning that you're looking for the number of contiguous, all-white columns. It's clear from the example, but it's generally preferred to not rely on examples or test cases.
– MichaelS – 2016-03-01T02:04:47.673@MichaelS: Great idea. I'm gonna quote you on that. Thanks! – Zach Gates – 2016-03-01T03:34:18.553