Now that the deadline to submit solutions has passed, let's solve this week's puzzle:
This week's challenge comes from listener Al Gori, of Oak Ridge, N.J. Name a famous city in 10 letters that contains an "S." Drop the "S." Then assign the remaining nine letters their standard value in the alphabet — A = 1, B= 2, C = 3, etc. The total value of the nine letters is only 25. What city is it?
In my preview post, I suggested we start with these:
- C: a list of cities;
- I'm planning to use this one; it looks pretty good, and it's downloadable as a CSV, so we can easily pull the names from that without needing to scrape and clean HTML.
- We'll filter this so that we keep only city names that contain 10 letters (not counting spaces, hyphens, etc.) and exactly one 's'.
- function_lvs: Letter value sum function to take a string (a city name), look up the numerical value in the alphabet for each letter (minus the 's') and return that sum;
- for c in C:
- if function_lvs(c) == 25:
- print("Solution! "+c)
And that's pretty much how I solved it.
I filtered my list of cities down to these, which all contain exactly 10 letters including exactly 1 's'; note that they are lowercased with spaces and non-letters removed:
addisababa
casablanca
faisalabad
manchester
lubumbashi
jamshedpur
sanantonio
liupanshui
saharanpur
kermanshah
valparaiso
hermosillo
washington
khabarovsk
louisville
almansurah
santamarta
rustenburg
balashikha
arrusayfah
sacramento
utsunomiya
cheboksary
suratthani
From there, we just need to sum all the letter values except for the 's', and check if it's equal to 25. Obviously, if letter values can range from 1 to 26 and the sum of our 9 letters is only 25, our letters need to come primarily from the beginning of the alphabet.
Have you got it? You can see my solver script here on GitHub, and I've added the solution at the bottom of the script, so check it there if you just want the solution.