How would you approach this?


Trying to solved a challenge from

Bob is a lackadaisical teenager. In conversation, his responses are very limited.

Bob answers ‘Sure.’ if you ask him a question.

He answers ‘Whoa, chill out!’ if you yell at him.

He answers ‘Calm down, I know what I’m doing!’ if you yell a question at him.

He says ‘Fine. Be that way!’ if you address him without actually saying anything.

He answers ‘Whatever.’ to anything else.

Bob’s conversational partner is a purist when it comes to written communication and always follows normal rules regarding sentence punctuation in English.

how would you approch it?

My first intuition was to look for the end special character with thestrings.Contains(), since, for my understanding;
if you yell a question, it ends in “!”
If you ask a question if ends in “?”
if you Yell a question if ends with “!?”
And if you address him without saying anything and example could be “bob” (Not sure about this one), you could check for bob in the word.
At last, a default answer to anything that does match any of the above.

I created a switch statement, but i ran into a problem if question ends in “!?” the switch statement will return true at first statement that is “!”

Also other problems like, if I ask a question with bob in it like “Bob have you taken out the trash?” It might return true at bob, instead of “?” (If Bob is checked for first that is)

Then I thought about splitting the string and check for the last element in the array, to see if it is equals to “!”, “?”… and so on.
But since it have to be correct punctuation, a sentence will end in “Example?” and not “Example ?”

I have been looking through the standard libary, but so far I failed to find a method that would be able to help me solved this problem, so I turn to you.
How would you go on about solving this problem?
I am not so much interested in the finished code, as I am in the steps it takes to solved a problem, you have no idea how to start.

Hope I make a bit of sense.

Hi. In the switch statement you could maybe put the case for !? first.

Then it will return true on both “!” and “?”, I tried that already sadly.

You misinterpreted the given test data to this exercise.

Yelling is not affected by the exclamation mark, yelling is determined by case of the letters only.

Also, please, whenever you have questions to exercism exercises, please tell that you are actually doing an exercism exercise.

This will make people aware of the actual testdata and exercism specifics (if there are some). As you present it, it looks like a random opaque home assignment from a school with a lot of missing data. Those that recognise this as an exercism assignment though, can tell you exactly what is wrong in your understanding as I did 2 sentences before.

1 Like

Could you please post some code. It is always easier to help then

I guess you should make some minimal lexical analysis on that text (tokenizer,parser,etc). Using a simple switch will fail at various text combinations.

Thanks for the feedback, I did not consider that it could be mistaken as homework :slight_smile: I edited the post and included a link to the exercise, I will give it another try now that I know yelling is all uppercases!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.