Given a string, return that string's "luck".
A string's luck, as I completely just made up for the purpose of this challenge, is an integer, determined as so:
- The base luck for a string is 1.
- For each consecutive letter it shares with the word "lucky" (case insensitive), multiply the luck by 2. For instance, if your string was "lumberjack" or "smack" you'd multiply by 4. (More specifically, 2^number of consecutive characters shared.)
- The shared letters have to be in the same consecutive order it appears in "lucky" but can start anywhere in the word for the same value ("luc" has the same 8* multiplier as "cky").
- If the word has multiple occurrences where it shares consecutive characters with lucky, use the longest consecutive string of the characters.
- For ANY letter it shares with the word "omen" subtract 2 from the luck.
- It can match a character any amount of times, in any order. For instance the string "nnnnnomemenn" loses 24 luck (12 matching letters)
Example:
luck("lucky")
>>32
2^5 (5 consecutive letters) = 32
luck("firetruck")
>>6
2^3 - 2 (3 consecutive letters from uck, e shared with omen)
luck("memes")
>>-7
1 - 8 (base amount, 4 shared with "omen")
This is code golf, so the answer with the fewest bytes wins.
You can input and output any way you'd like - write a function, use standard input, etc.
For functions, assume whatever data type would make sense for that language. (For example, in JavaScript, you'd be passed a String
and return a Number
)