Snack Break Problem #9
Posted on February 24, 2016 by Shawnyg
Hello scripting enthusiasts! For this week's challenge, your task is to find the longest word in any given string, and only capitalize letters which have an index in the alphabet that is a prime number. There are 26 letters in the alphabet, so each letter has a corresponding number. It’s preferable that you use a function that I may call upon with any string value.
An example of a prime letter would be "B". It is the 2nd letter in the alphabet, and 2 is only divisible by itself and 1.
Example:
function assort(val) return "Result" end print(assort(“Hello”))
Now, the word must actually be a word consisting of only letters, no numbers.
For example: "123456789pie cat"
"cat" would be the longest word in my case, since it only has letters, and ONLY capitalize the prime letters within that string. If you want to go above and beyond, I’ve set an Elite and Supreme Challenge for you.
Elite challenge:
All previous requirements still apply, but you can't have a variable set set as a table, already previously defined with variables.
Supreme Challenge: All previous requirements still apply (including the elite challenge), however you may not create any variables containing string values, however string manipulation is allowed (ex: string.sub(), string.match(), etc. with strings inside is still allowed.) Example:
local variable = “1234”
The above example is not allowed.
I will be publishing the answer next week Wednesday, or possibly a bit earlier to bring a new Snack Break! Those who email me first with their answer will receive a shoutout on the next Snack Break related post I make! However, if someone completes the 'Supreme Challenge' first while you only complete the normal one, they will receive the shoutout, if they have the most efficient way. That means, if I submitted a Supreme first, and it was correct, but evaera submitted one that was more efficient, she'd win.
Just for you all to know, my name is Shawn and I’m the new Blog Manager here at Scripting Helpers. If you have any suggestions, feel free to hit that “Feedback” bar on your left screen, and it’ll make its way from the help desk to me.
Commentary
Leave a Comment