Sometimes I make bad jokes... And a bad joke I like to make involves interpreting exclamation marks in sentences as the factorial sign.
Your task is to write a program that receives a sentence and applies the factorial joke to the sentence.
The "factorial joke" consists of looking for exclamation marks "!" and doing the factorial of whatever is to the left of it. If the thing to the left is an integer, then the usual factorial is used. If the thing to the left is a word (a sequence of characters in
[a-zA-Z], delimited by spaces), then we want to concatenate all of the subsequent prefixes of the word.
E.g. if the word was
abcd! = abcdabcaba.
However, there is an exception, which is when the sentence contains a "1!" or "2!", because
1! = 1 and
2! = 2 and the joke doesn't really work. In these cases, your program can do whatever it wants EXCEPT applying the factorial joke or returning the same sentence.
A sentence with characters in the range
[a-zA-Z0-9 !] with the restriction that only one exclamation mark "!" is present and to the right of an integer or a "word". This means you don't have to worry with things as
"abc4!" as a word here is defined as a sequence of alphabetical characters delimited by spaces.
The same sentence, but with the factorial joke applied to the word or integer on the left of the exclamation mark.
You can find a Python reference implementation here
We lost the match 3 to 0! -> We lost the match 3 to 1 ora bolas! -> ora bolasbolabolbob give me 4! -> give me 24 I wanted 2! give me 2 -> undefined Let us build a snowman! -> Let us build a snowmansnowmasnowmsnowsnosns We are late because it is past 17! -> We are late because it is past 355687428096000 I only have one! -> I only have oneono I only have 1! -> undefined Incredible! I have never seen anything like it -> IncredibleIncrediblIncredibIncrediIncredIncreIncrIncInI I have never seen anything like it What an amazing code golf challenge this is! -> What an amazing code golf challenge this isi So many test cases! -> So many test casescasecascac These are actually just 11! -> These are actually just 39916800 No wait! there are 13 -> No waitwaiwaw there are 13
This is code-golf so shortest submission in bytes, wins! If you liked this challenge, consider upvoting it... And happy golfing!