In mathematics, the factorial of an integer (denoted by an symbol) is as follows:
On Reddit, there is a subreddit /r/unexpectedfactorial, dedicated to trolling users who have accidentally included a factorial in their post or comment.
Here are some examples of unexpected factorials:
Original: By 2007, I was only 5!
Response: Wow, 120 years old is quite old.
Original: Calculators explode when dividing by 0!
Response: Hmm, dividing by 1 shouldn't make your calculator explode…
Input Specification
Your program is required to detect an unexpected factorial in a single line of text input, and output the actual value of (luckily for you, you are not required to phrase it into a statement). If the input does not contain any unexpected factorial, output -1
. The input may contain spaces, punctuation and numbers.
The input should only contain 1 unexpected factorial, but may contain multiple exclamation marks.
Output Specification
Your program should output a single integer, the full actual value of .
Constraints
Subtask 1 [0%]
Sample test cases.
Subtask 2 [30%]
Subtask 3 [70%]
Sample Input 1
Nice! I rate 5/7!
Sample Output 1
5040
Sample Input 2
How obvious - how necessary - was the mathematical ratio of its sides, the quadratic sequence 1:4:9! (from 2001: A Space Odyssey)
Sample Output 2
362880
Sample Input 3
This string does not contain any unexpected factorial!
Sample Output 3
-1
Comments
why am i getting #16 in batch 3 wrong?
Can an input include no exclamation marks?
/r/theydidthemath