14
3
This is the first in a series, the second is Two roads diverged in a yellow wood (part 2)
This challenge is inspired by Robert Frost's famous poem, "The Road Not Taken":
Two roads diverged in a yellow wood,
And sorry I could not travel both
And be one traveler, long I stood
And looked down one as far as I could
To where it bent in the undergrowth;Then took the other, as just as fair,
And having perhaps the better claim,
Because it was grassy and wanted wear;
Though as for that the passing there
Had worn them really about the same,And both that morning equally lay
In leaves no step had trodden black.
Oh, I kept the first for another day!
Yet knowing how way leads on to way,
I doubted if I should ever come back.I shall be telling this with a sigh
Somewhere ages and ages hence:
Two roads diverged in a wood, and I —
I took the one less traveled by,
And that has made all the difference.
Notice the second to last line, I took the one less traveled by,
.
Your actual challenge
You will take input in the form like:
# ##
# ##
# ##
#
#
#
and you have to find the thinner road.
The road starts at the bottom with a #
. The other 2 roads, which always terminate on the top row, are the roads you have to examine. The road that is the thickest is most traveled by, and therefore it is not what you want. The other one is the least traveled by, and it is the one you want.
Output
Your program/function must output one of 2 distinct values (eg. 0 or 1, true or false), one for each possible position of the road not taken. For example, you could output 0 if the road not taken is on the left of the road taken, and 1 otherwise, or you could output the string "left" or "right", true, false, etc.
Test cases:
## #
## #
###
#
#
#
Might output "right".
## #
## #
###
##
#
#
#
Might output "right".
## #
## #
###
##
#
#
#
Might output "right".
## #
## #
###
#
#
#
#
Might output "right".
# ##
# ##
###
#
#
#
#
Might output "left"
# ##
# ##
###
#
#
#
#
Might output "left"
Notes
- This is code-golf, so the shortest answer in bytes wins
- Standard loopholes forbidden
- You must specify your outputs for "left" and "right" and they must be distinct
- Input will be one big string, and may have any amount of lines
- You don't need to worry about valid input.
- The road is always a Y shape, so you only have to look at the top.
- Have any questions? Comment below:
What defines the thickness of a road (I assume it is horizontal crosssection)? Will the roads always be one and two wide? – Post Rock Garf Hunter – 2017-03-28T19:48:27.857
1Yes, always # and ##, and horizontal crosssection. – programmer5000 – 2017-03-28T19:49:34.540
Is the road always a
Y
shape and never upside down? In that case, isn't it sufficient to only look at the top row? That kinda trivializes the problem. – AdmBorkBork – 2017-03-28T20:00:49.220Is it valid to replace actual newlines with the characters `\n" in the input? – Okx – 2017-03-28T20:08:01.713
Yes, it is valid. – programmer5000 – 2017-03-28T20:08:56.620
@programmer5000 Don't be strict on the input. Some languages have to take input that way. The challenge should not be about the input format, but rather about the challenge you've described. – mbomb007 – 2017-03-28T20:10:43.953
Why does this question have 2 upvotes and 2 downvotes? – programmer5000 – 2017-03-28T20:43:40.893
1Wasn't me. I quite like it. Well defined, good back story and clear examples. It's fairly easily doable and I think the idea of inviting obscure languages only adds extra flavour and could encourage some interesting answers. – ElPedro – 2017-03-28T20:52:00.853
1IBM/Lotus Notes Formula Language and Acc!! responses are proof of how inviting obscure languages to easy questions leads to interesting results. – programmer5000 – 2017-03-28T20:55:24.783
3I was just saying to myself: "You know a challenge is simple when you think, 'Hey, this will be easy in Acc!!'" ;) – DLosc – 2017-03-28T21:00:48.947
22
@programmer5000: I'm one of the downvoters. I downvoted the challenge because it's something of a chameleon challenge (in that it looks like it's about parsing or otherwise measuring the roads, but actually it's just "split on spaces, take the first section"), with a lot of background that's only tangentially related and to obscure the challenge still more; and because it's extremely easy (something that normally makes me downvote challenges). It's also incompletely specified (e.g. can inputs have widths other than 1 and 2?)
– None – 2017-03-28T22:09:07.433@programmer5000 is this comment correct? Can I return
– David Archibald – 2017-03-28T22:23:00.213' '
or#
?Sorry for another question, but I'm new to code golf. is removing the
a=>
making it no longer a function, and expecting an already defined variable ofa
to be defined valid? – David Archibald – 2017-03-28T22:51:26.2201
@DavidArchibald The default policy is that submissions must be a function or a full program. Expecting the input in a predefined variable makes the code a snippet, which isn't allowed unless the OP specifically permits it.
– DLosc – 2017-03-29T03:53:02.820Thanks, @DLosc. I thought I remembered seeing a challenge with an answer like that. Must've been stated by the OP. – David Archibald – 2017-03-29T04:36:48.697
Will the input string be gruaranteed to begin in a
#
? It is the case in all of the test cases... – MildlyMilquetoast – 2017-03-29T17:32:05.543@Mistah No, my test cases aren't great. – programmer5000 – 2017-03-29T17:32:42.163