Signpost reading

-3

Challenge source:

My: https://testovac.ksp.sk/tasks/ls18-signpost/download/ dated 11. 7. 2016

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.

Mr Redstoner

Posted 2020-01-07T19:27:49.787

Reputation: 233

Question was closed 2020-01-08T03:45:56.860

8

I strongly suggest moving this to the sandbox for thorough feedback.

– Adám – 2020-01-07T19:30:47.800

@Adám I just moved it out of Sandbox after a long period of no more responses https://codegolf.meta.stackexchange.com/a/18229/88701 Feel free to provide more feedback

– Mr Redstoner – 2020-01-07T19:33:58.357

It can be hard to get enough feedback. Advertising your need for feedback in The Nineteenth Byte tends to help. I am pretty sure this challenge is very underspecified.

– Adám – 2020-01-07T19:35:22.373

There are a variety of standard input/output rules for text. Can we, for example, take input as a list of lines? – Punintended – 2020-01-07T19:36:09.487

1@Punintended I'm pretty sure all the standard i/o rules for text are included. – Adám – 2020-01-07T19:36:46.247

1@MrRedstoner Is the challenge simply to recognise the three possible inputs (e.g. by looking at the 5th character or at the input length) and output the right one of the two possible output, or is there a larger domain of possible inputs and some sort of system to determine the appropriate output? – Adám – 2020-01-07T19:38:20.193

@Adám It should work for a general story of this format, that's the reason I wrote Example input/output at the begining. – Mr Redstoner – 2020-01-07T19:42:24.330

5@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 – 2020-01-07T19:51:56.283

1Disguising your specifications as test cases is rather confusing and not really helpful, as the first test case primes you to ignore the second. – Jo King – 2020-01-07T21:44:11.707

@Noodle9 "The signposts … strictly follow the following format: Left to x. Right to y." – 640KB – 2020-01-07T22:10:24.597

@640KB Ah, missed that - thanks :-) – Noodle9 – 2020-01-07T22:11:10.720

4@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 – 2020-01-07T23:38:13.223

2

This is not a decision-problem.

– Arnauld – 2020-01-08T00:05:52.817

12

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 – 2020-01-08T02:04:58.223

@xnor Sorry I didn't know. I actually got the challenge from elsewhere though, https://testovac.ksp.sk/tasks/ls18-signpost/download/ and sadly noone in the Sandbox seems to have noticed the source you cite.

– Mr Redstoner – 2020-01-08T05:51:09.453

@xnor So do I just delete the question then? Definitelly don't intend to argue with that, but it seems people feel the need to just pop by and downvote this further. – Mr Redstoner – 2020-01-08T17:13:46.240

@MrRedstoner I guess you might as well delete it, unless you plan on trying to get it fixed up and reopened. Interesting that your challenge source is dated before the SPOJ problem -- maybe whoever submitted it to SPOJ copied it from there without permission. Sorry the Sandbox was so unhelpful here. – xnor – 2020-01-09T02:56:03.363

Unfortunately, I don't think you can delete this since there are other answers. You can try asking each of them to delete their answers, and you can try flagging your question for moderation intervention to see if you can get help there. However, I think the most important thing to do is to add your reference and the SPOJ reference to the body of your post in case things actually went sour. – FryAmTheEggman – 2020-01-09T05:25:18.237

@FryAmTheEggman I tried clicking delete just to see what exactly would happen and it asks if I really want to delete something with answers, to me that implies it's possible. Will add those links. – Mr Redstoner – 2020-01-09T05:56:46.340

@xnor mind you I have no idea if my source is the original, it's possible there's a different source that both mine and SPOJ pulled from. – Mr Redstoner – 2020-01-09T06:28:07.017

1

Based on @xnor's comment above about the SPOJ copyright, I doubt it will be re-opened, so I'm just gonna leave my initial 05AB1E solution here for now since I didn't want to just discard it completely: 51 bytes. Someone please tag me if for whatever reason it does get edited and re-opened, then I will move this comment to an answer with explanation.

– Kevin Cruijssen – 2020-01-17T10:19:59.517

@KevinCruijssen Since people don't seem to be too fond of this kind of specification I don't intend to push for a reopening. As you might have noticed I've got an earlier source than SPOJ, so I don't consider that the main problem. Anyway, here's your upvote for being understanding at least. – Mr Redstoner – 2020-01-17T13:23:54.550

@MrRedstoner Yeah, I had already open-voted it before, but I see it's been closed again after it had been re-opened somewhere during my Christmas break. I had this prepared solution since right after it was closed in the beginning, and figured I'd just add it as a comment here instead of discarding it. Ah well, either way thanks for the challenge, I personally liked it. Don't let it discourage you too much. (And I can recommend using the Sandbox first for future challenges.)

– Kevin Cruijssen – 2020-01-17T13:39:18.210

Answers

3

PHP, 163 159 bytes

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!

640KB

Posted 2020-01-07T19:27:49.787

Reputation: 7 149

2Loving the PHP Warning: – Mr Redstoner – 2020-01-07T20:15:28.533

@MrRedstoner, he just needs to wrap the word dragon in quotation marks to avoid errors and warnings. – девочка с глазами ребёнка – 2020-01-09T18:54:54.987

1@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 – 2020-01-09T18:56:21.900

@640KB, interesting behavior) – девочка с глазами ребёнка – 2020-01-09T19:02:55.527

3

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!

Arnauld

Posted 2020-01-07T19:27:49.787

Reputation: 111 334

2

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!

Xcali

Posted 2020-01-07T19:27:49.787

Reputation: 7 671

-1 byte... – 640KB – 2020-01-07T21:11:50.510

2

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:
                Ḣ                | - Head
                 ;"“,“ the“!”    | - Concatenate in turn to "," " the" "!"
                             K   | - Join with spaces

Nick Kennedy

Posted 2020-01-07T19:27:49.787

Reputation: 11 829

2

AWK, 154 \$\cdots\$ 131 121 bytes

/^Left to \w+\. Right to \w+\.$/&&/dragon/&&!/dragon.+dragon/{sub(/[^.]+dragon..?/,"");sub(/\./,"!");sub(/ /,", ");print}

Try it online!

Noodle9

Posted 2020-01-07T19:27:49.787

Reputation: 2 776