Euleryx Problem 22 – Names Scores
My workflow:
Workflow:
Answer: 871198282
Last Week's Favourite Solution:
A tough call last week, as the solutions provided took a similar approach for identifying the factors. I would like to shout out both @Qiu and @AncientPandaman for providing such efficient brute force solutions to last week's challenge! Please find their solutions on page one of last week's post or click here.
Mathematical Theory:
Relatively straightforward challenge this week; however, that doesn’t mean we can't do a little rearranging to save a tool or two.
The way the question is phrased suggests that we need to do the following 4 steps:
1) Find the value of all letters in a given word
2) Sum the values of the letters in the word
3) Multiply this sum by the word's position in the list.
4) Sum the values calculated in the step above.
Taking the words Dog and Cat as an example the steps would go as follows:
Written as one formula, it reads:
2 x (4 + 15 + 7) + 1 x (3 + 1 + 20)
When written like this, you may notice that we don’t have to do the steps, as per the original order. Instead, let's do the multiplication before any of the addition.
By simply rearranging the formula, we have been able to remove an entire step from the process, meaning the workflow should run faster. Here's the updated process:
1) Find the values of all the letters in a given word
2) Multiply each letter by the word's position in the list.
3) Sum ALL the values together
Method:
1) First of all we need to split all the names into their own row, sort them, and then give them a rank (position number):
2) Now, separate out each letter from each word, using tokenise in the regex tool.
3) Calculate the value of each letter. This can be found by identifying its position in the alphabet. And multiplying said position by the overall name's rank (from when we sorted them alphabetically).
4) Sum all the letter values to arrive at the answer:
5) Submit your answer to the Project Euler Website!
Summary:
Even on simple problems, we can often look for efficiencies, sometimes by simply swapping the order of steps around.
Want to find out more, follow this link to our introduction post - Euleryx: Let The Games Begin.
@Pilsner
Thank you for the shout out. 😁
I think we are taking similar approach.
