25
5
This is the second in a series, the third is Two roads diverged in a yellow wood (part 3)
This is based on Two roads diverged in a yellow wood (part 1), a previous challenge of mine. It was fairly well received, but it was also fairly trivial (a Java answer in 52 bytes!) So I made something more complex...
The inspiration
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;...2 paragraphs trimmed...
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 goal is to find the road least travelled by in your string input. You must output one of 2 values that are distinct from each other that signal which way you should turn to take the road less traveled by. Once the road forks (the trail of hexagons changes to numbers) you are at the intersection. From there, there will be 2 paths made up of digits. The path whose digits has the lowest sum will be the road not taken. Note that the road not taken may have a larger path but a lower path sum. Here are some examples / test cases from a program that prints "left" or "right" for the path not taken:
1 2
1 2
1 2
#
#
#
left (3 < 6)
1 2
2 2
1 1
#
#
#
left (4 < 5)
12 2
11 2
1 1
#
#
#
right (6 > 5)
99 989
99 89
99 99
99 99
#
#
#
#
left (72 < 79)
1111 1110
001 111
11 11
11 11
#
##
##
##
left (9 < 10) (Note: 1111 is interpreted as 1+1+1+1=4, not 1111=1111)
1 1
0 1
1 1
1 1
1 1
1 1
1 1
#
#
#
#
#
left (6 < 7)
1 1
0 1
1 1
1 1
1 1
1 1
1 1
#
#
#
#
#
left (6 < 7)
Things to assume & remember
- There will always be 2 paths. No more, no less.
- You can take input from STDIN one line at a time, a string containing LF characters, or a string containing a literal backslash and a n. If you need input in any other way, ask for approval in the comments.
- You don't have to worry about invalid input or tied paths. Those will never be inputted to your program / function.
- The input can be of any length in width or height, less than the string limit of your language.
- There will never be a
#
and a number in the same line. - All digits in the path are positive integers 0 to 9.
- Input or output with a trailing newline is allowed.
- See my JS ES6 answer below for an example.
- There will always be at least 1 space between the 2 paths.
- The 2 paths will always have the same height for each map, but may be different on other maps.
- If you are confused about a specific test case, please tell me.
- 1111 is interpreted as 1+1+1+1=4, not 1111=1111. The map is a series of one-digit numbers, not numbers of arbitrary length.
- This is code-golf, so the shortest answer in bytes wins!
- Standard loopholes forbidden
If you have any questions about this challenge, ask me in the comments, and good luck!
Hey, you can see all the answers and their byte count by pasting
$("div > h1").map(function(){return $(this).text()}).get().join("\n");
into your console! – programmer5000 – 2017-03-29T15:21:17.7271Here's a alternative version with removed whitespace and ignored strikedthrough answers
let answers = $('div > h1').map(function(){return $(this).clone().children(':not(a)').remove().end().text().replace(/\s+/g,' ').trim()}).get();answers.splice(0, 1);answers.join('\n');
– David Archibald – 2017-03-29T18:15:26.2002A # is not a hexagon... – user253751 – 2017-03-30T02:08:19.250
1
"but it was also fairly trivial (a Java answer in 52 bytes!)" 43 bytes now. ;)
– Kevin Cruijssen – 2017-03-30T12:08:08.420Closevotes again? What the hell is wrong with you? – Matthew Roh – 2017-04-04T06:26:05.347