## Challenge source:

SPOJ: https://www.spoj.com/problems/SIGNPOST/ dated 2018-03-22

# Challenge definition == Example input/output:

## Input 0

The hero was deep inside the dragon’s lair.
But he was not afraid; he knew what was coming.
Each dragon lair has some crossroads. At each crossroad, one can go either left or right.
At each crossroad there is a signpost, indicating what is to the left, and what is to the right, always in the same format.
One direction leads to the dragon.
If the hero,in full armour, went into the dragon’s bedroom, he would surely wake him up and become breakfast in bed.
So, the hero will definitely choose the other option.
The hero always reads this signpost into a  single line, by itself.
Oh, here comes the first crossroads, thought the hero to himself.
Left to dragon. Right to princess.
Oh no, what is this sorcery!?
What heroes don’t know, is that the signposts are cursed.
Whoever reads one, forgets which of the two options he definitely didn’t want to pick.
So the hero needs your help - Every time he manages to read a signpost,tell him where he needs to go.


## Output 0

Right, to the princess!


## Input 1

The story contains at most 100 lines, none of which are over 100 characters long.
The signposts are always read into a single, separate line, and strictly follow the following format:
Left to x. Right to y.
Where x,y are non-empty strings made up of letters of the english alphabet, one of them is ’dragon’, and the other is NOT ’dragon’.
This line must have no missing, or extra, spaces.
Notice that the above example is not a valid signpost, as it violates ’one of x,y is dragon’.
Often, heroes just mentally prepare for the inevitable signpost they will face.
Right to dragon. Left to princess.
Hm, on a real signpost the directions would probably be the other way around,thought the hero.
Wait, what is this before me!?
Left to dragon. Right to goodluck.
Left to YouWillNeedIt. Right to dragon.
What is happening!? Where should I go???
Left to havefun. Right to dragon.
Left to dragon. Right to dragon.
What the hell kind of sign was that?


## Output 1

Right, to the goodluck!
Left, to the YouWillNeedIt!
Left, to the havefun!


## Technical

Standard input/output rules apply, standard loopholes are forbidden.

Find lines matching 'Left to x. Right to y.' where exactly one of x,y is dragon and the other is a single word other than 'dragon', output the other one in the format 'Left, to the x!' or 'Right, to the y!' in the order that they are in the input. The single word contains only lower-/uppercase alphabets.

This is , shortest code in bytes wins.

• I strongly suggest moving this to the sandbox for thorough feedback. – Adám Jan 7 at 19:30
• @MrRedstoner Sure, but examples are not enough. I find it unclear what information needs to be extracted from the input. Please specify what the actual challenge is. Don't just illustrate with some examples. Have a look around at challenges that have a lot of upvotes and see how they were written. – Adám Jan 7 at 19:51
• @MrRedstoner Just wanted to say that I personally really dig this kind of specification, for it's really creative and a breath of fresh air on this site, but we're probably in the minority here. Maybe take this kinda format to puzzling.SE instead? They have more sense of fun there ;) – KeizerHarm Jan 7 at 23:38
• This is not a decision-problem. – Arnauld Jan 8 at 0:05
• This is copy-pasted from SPOJ problem "SIGNPOST". At a minimum, this should have had a link with attribution, but the bigger issue is that posting this here under Stack Exchange's license violates SPOJ's copyright. And I can't imagine SPOJ would be happy to have easily Googleable answers anyone can copy-paste and submit. – xnor Jan 8 at 2:04

preg_match_all('/(Left) to (.*)\. (Right) to (.*)\./',$argn,$o,2);foreach($o as$m)if($x=2*($m[2]==$d=dragon)xor$m[4]==$d)echo"{$m[$x+1]}, to the {$m[$x+2]}! ";  Try it online! • Loving the PHP Warning: – Mr Redstoner Jan 7 at 20:15 • @MrRedstoner, he just needs to wrap the word dragon in quotation marks to avoid errors and warnings. – The art of being alive Jan 9 at 18:54 • @Theartofbeingalive I took it to mean he found humor in the message Use of undefined constant dragon - assumed 'dragon'. Which it is kinda funny. – 640KB Jan 9 at 18:56 • @640KB, interesting behavior) – The art of being alive Jan 9 at 19:02 # JavaScript (ES9), 139 132 bytes s=>s.replace(/(Left) to (\w+)\. (Right) to (\w+)\.|./gs,g=(s,a,b,c,d)=>(b=='dragon'&d!=b?c+, to the${d}!
:'')+(s&&g('',0,d,a,b)))


Try it online!

# Perl 5-n, 127 bytes

/^Left to (\w+)\. Right to (\w+)\.$/&&say($1eq dragon?$2eq dragon?next:"Right, to the$2!":$2eq dragon?"Left, to the$1!":next)


Try it online!

# Jelly, 63 bytes

Ḳ€ṁƑƇ6¹¹Ṫ3ƭ€K“£ṖnlÄŀ'ḟʋæGyẈ»ƑƊƇŒHċÐḟ¥€“¥³|»LḂ$ƇḢ;"“,“ the“!”KƊ€  Try it online! A monadic link taking a list of strings and returning a list of strings. ## Explanation ### Part 1 Ḳ€ | Split each at spaces ṁƑƇ6 | Keep only those invariant when moulded to length 6 ƊƇ | Keep only those where the following is true: ¹¹Ṫ3ƭ€ | Tail of every third word (popped); leave the other wirds unchanged K | Join with spaces “£ṖnlÄŀ'ḟʋæGyẈ»Ƒ | Invariant when replaced with "Left to . Right to ."  ### Part 2  ¥€ | For each line: ŒH | - Split in half ċÐḟ “¥³|» | - Keep the halves without "dragon"$Ƈ                 | Keep lines where the following is non-zero:
L                    | - Length
Ḃ                   | - Mod 2
Ɗ€ | For each line:

# AWK, 154 $$\\cdots\$$ 131 121 bytes
/^Left to \w+\. Right to \w+\.\$/&&/dragon/&&!/dragon.+dragon/{sub(/[^.]+dragon..?/,"");sub(/\./,"!");sub(/ /,", ");print}