This challenge is designed by Akshay More. You can refer to the Challenge details here.
The Treasure Hunt challenge is designed to test your string manipulation skills. You are expected to identify an 8 letter word based on the clues given below. The clues below will help you get each letter, but they are not in the same order to get the word straightforward. So once you get all the 8 letters, you have to shuffle them to identify a meaningful word.
Here are the broad steps to solve this challenge and we will deep dive into each of these steps:
- Extract text from the image
- Identify all 8 letters based on the clues shared
- Shuffle the letters to identify a meaningful word
We will start with using Steps action to perform each step discussed above. Let’s add steps as shown in the screenshot below to perform text extraction, identifying each letter and arriving at the final word.
Step: Extract the text from the image
Use the action ‘Capture Image by url’ available in the OCR package to extract the text and save it into a string variable called ‘sExtractedText’.
Enter the URL where the image file is stored, that is, https://uploads-us-west-2.insided.com/automationanywhere-en/attachment/treasurehuntinputtext.png . You can get this URL from the challenge page by copying the storage location of the image.
Use the action ‘Log to file’ to save the extracted text into a txt file for our future reference. Enter the file path. For ex: C: emp ext.txt (as a best practice, always use a path which is not linked to a specific user id, so that it will work for any user). And then pass the variable ‘sExtractedText’ in the attribute ‘Enter text to log’.
Now, let's solve each clue one by one.
Solving Clue 1: Identify the location where Jane’s parents stay and get the first letter from the identified word using the ‘Extract Text’ action with ‘After’ clause in Get characters attribute.
Read the text in the image and you can identify that Jane’s parents stay in Boston which appears before the text “, but she now works”. Use the ‘Extract text’ action in Strings package with the attributes as shown in the screenshot below and save the output to a variable called sFirstCharacter. As the clue asks us to use ‘After’ clause, we need additional processing to get the word Boston.
Use a message box to check the output. You will see the result like this.
Now, we have to extract the word Boston, so let's get the length of this extracted text and then get the letter B.
Solving Clue 2: Identify Peter’s daughter’s name and then get the 3rd letter using Substring Action
Peter’s daughter name is Flora, get the third letter from this word using Substring action. In the source string, enter the word Flora. Start from third position and get a single character by entering 1 in the Length attribute and save the output to a variable called sSecondCharacter. It will contain the letter “o”.
Solving Clue 3: Replace the string “Inten” in the word “Intention” with the string “na” and get the third letter from the resulting word
Use the action Replace Text, Enter the source string as “Intention”, Find string as “Inten”, and select find string as “Not a regular expression” as we are looking for the literal replacement and not a pattern. Enter Start from the field with value 1, No need to change anything in the Count attribute, leave it as is, and enter Replace with text as “Na” and store the output in a variable called sThirdCharacter. It will contain the text “Nation”.
Now, to get the third letter, use the action Substring, enter the source string as sThirdCharacter, Start from position 3, and length as 1, and save the output back into the same variable sThirdCharacter. Now it will contain the letter “t”.
Solving Clue 4:
- Extract the word between the words local and school
- Identify the length of the identified word and get the (n-1)th character. For ex: if the word is Mexico, then the length of this word is 6, (n-1)th character is the 5th character that is ‘C’
Use the action ‘Extract Text’ and enter the source string as sExtractedText. Select 'Before And/or after' attribute and enter the Start after text as "local". Add an “AND” condition and enter the ‘end before text’ as “school”. Select the option ‘Trim the extracted text’ and save the output to a string variable called sFourthCharacter.
Now we have the word "primary" with us and have to get the (n-1) letter. To do that, we need the length of the word using the action 'Length' and then get the (n-1) letter using the substring action.
Solving Clue 5: Identify the word that contains the character “;” (semi-colon), split the word using “;” (semi-colon) as delimiter and get the first letter from the second word
The word is “Ital;ian”, however OCR doesn’t seem to extract the character “;” (semi-colon), so we will type the word "Ital;ian" in the source string attribute of the action ‘String: Split’ and assign the output to a list variable lFifthCharacter. This action will store the source word into two words “Ital” and “ian” within the list variable.
Now, we have to get the first character from the second word. Use the ‘Extract Text’ action and enter the source word as lFifthCharacterr1], here we are using the index 1, since we need the letter from the second word “ian” from the list. If we use index 0, we will get the first word “Ital”.
Solving Clue 6: Reverse the word “phrase” and get the 2nd letter
Use the action ‘String: Reverse’ and enter the source word as “phrase” and save the output to a variable called sSixthCharacter.
Use the action ‘String: Substring’ and pass the variable sSixthCharacter as the source string. As we need the second letter to be extracted, enter the ‘Start from’ field attribute with value 2 and length as 1 as we just need one letter and save the output to the same variable sSixthCharacter.
Solving Clue 7: Identify the 4th letter from the official language of the Netherlands
The answer is “Dutch”. Use the action ‘String: Substring’ and pass the string “Dutch” as the source string. As we need the fourth letter to be extracted, enter the ‘Start from’ field attribute with value 4 and length as 1 as we just need one letter and save the output to a new string variable sSeventhCharacter.
Solving Clue 8: Using regular expression, identify the word ending with the letters “ol” from the paragraph shared in the image and get the fourth letter from the identified word
Here is the logic to come up with regular expresssions (Regex). One of the quick ways to learn about Regex is by referring to the website https://regex101.com/ . This site includes quick reference of all the patterns and you can try out your Regex with sample text. For this example, we need the words ending with the string “ol”, so we have to use the expression w*ol in the 'String: Find' Action. Here is the explanation for the regular expression: w - matches any word character (equivalent to a-zA-Z0-9_]) * matches the previous token between zero and unlimited times, as many times as possible ol - matches the characters ol literally (case sensitive) - identifies a word boundary Select 'find string' attribute as a regular expression and store the output to a numeric variable nCountIdentifier. This will store the starting position of the word "school" extracted using the regular expression.
Now, let's extract the word school by using the action 'String: Substring' with the source string as sExtractedText and starting position of the required word as nCountIdentifier variable along with the count as 6, as the word "School" contains 6 letters. Store the output to a new string variable called sEighthCharacter.
Next step is to get the fourth letter from the word "school" and we will perform the same using 'String: Substring' action as shown below.
Now, we have identified all the 8 letters and it comes out as “Botrisco”. Shuffle the letters to identify a meaningful word and the solution word is “roBotics”. The final rule to be satisfied is to ensure all the letters are in lower case except the first letter. Use the action String: Uppercase to convert the letter r to R, which was identified from Clue 4.
The next step is to convert the letter B to b, use the action String: Lowercase to convert the same for the letter identified from Clue 1.
Now display the result in the message box. It should look like the screenshot below.
Congratulations, you have now successfully completed the "Treasure Hunt" challenge!
Conclusion
String manipulation is one of the most important skillset required for an RPA developer and this challenge is a fun way to explore different actions in the String package. We just showed you one of the ways, this challenge can be solved. You may have noticed alternate approaches on social media. Explore more about advanced string manipulation techniques and enjoy the journey. Go be great!