Guess the Text
Description:
Task
Write a function named entryGuesser
which figures out and returns a hidden text string, using two preloaded functions ( comesBefore
and comesAfter
) to figure it out.
Good luck. And please up vote if you find it challenging, entertaing, or at least thought provoking, as those were my goals in writing this kata. Enjoy.
-- Donald Arthur Kronos --
Description
This isn't meant to be easy. Are you up to the challenge?
Think of it as trying to guess a dictionary entry someone has in mind, but with a twist. The entries are sorted case sensative, so "Zebra" comes before "apple" because upper case letters always precede lower case letters.
For example, imagine if your best guess so far is "book", so you test to see whether the target enter comes before "book" or after "book".
So you check the value of comesAfter("book")
and the result it false.
You then know that the target entry doesn't come after book, so if it also doesn't come before "book" then you've guessed correctly.
But if you check the value of comesBefore("book")
and it turns out to be true, then "book" is not the target entry after all.
But what if the target entry is in al caps? Could it be "BOOK" we're looking for, instead of "book"?
When checking the value of comesBefore("BOOK")
returns a result of false, since we already learned that comesBefore("book")
is true, the entry we're looking for is either "BOOK" or something between "BOOK and "book". Perhaps the correct amswer is "CAT", or maybe it's a phrase like "Once upon a time...".
Now, you may be thinking, this guessing could take forever, but keep in mind that you do have two helpful functions preloaded to give your entryGuesser function clues, and computers can make a lot of guesses in a very short time.
Can you teach the computer how to use the clues available and figure out what the mytsery text string contains?
Constraints
Assume the target text string contains only characters within the first 1024 Unicode characters.
Keep an eye on performance, as naive solutions are likely to timeout; make sure to optimise (ref sol takes 5 seconds)
- 350 tests with normal alphabet (
0 <= text size <= 2100
) - 350 tests with extended alphabet (
0 <= char code <= 1023
) (0 <= text size <= 2100
)
- 350 tests with normal alphabet (
constraints added by dfhwze
Similar Kata:
Stats:
Created | Jul 18, 2015 |
Published | Jul 18, 2015 |
Warriors Trained | 370 |
Total Skips | 21 |
Total Code Submissions | 353 |
Total Times Completed | 44 |
JavaScript Completions | 44 |
CoffeeScript Completions | 6 |
Total Stars | 13 |
% of votes with a positive feedback rating | 92% of 19 |
Total "Very Satisfied" Votes | 17 |
Total "Somewhat Satisfied" Votes | 1 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 10 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 6 kyu |