This question already has an answer here:
- ??? Question Marks? [closed] 2 answers
- if there are exactly
- and whether the sum of each pair equals to 10.
- A string of arbitary length.
- The number of exclamation marks to check for
if there are exactly
n exclamation marks between each pair, return truthy value, otherwise falsy value.
Pair is defined as two digits with at least one exclamation mark between them
- The string may contain
- lowercase letters
- digits (1-9)
- and obviously exclamation marks (
- In case no digit pair is found, return a falsy value.
- The exclamation will not appear at start or end of the string
asas6!!4somevbss5!!asa5 , 2 ---> true sasdasd3!2ssjdn3! sdf!3 , 1 ---> false asjsj8sj!!!! 2 sjsadasd9!!!!1 , 4 ---> true sal7!!3 , 2 ---> true nodtejsanhf , 2 ---> true 2is digit no excla 5 , 8 ---> true a!1!9!8!2!a , 1 ---> true (thanks @ngn)
The last two cases were
false imo but as suggested by Adam (who has more experience than me and probably knows better :) ), they were made true
Winning criteria :
this is code-golf so shortest code in bytes for each language wins.
Don't forget :
You must check whether the sum of the two numbers equals 10 or not too, along with whether each pair is separated via
n exclamation marks
Credit ? :
@Laikoni found a challenge on coderbyte similar to this : Here. O_o ? I didn't know that
Some explanation :
@ngn suggested this case
a!!1!2!3a45!6!!a , 1 (return false)
a!! --> ignore this 1 --> here we go start ! --> sum so far = 1 2 --> sum = 3, and stop
Yep the sum of each pair must be 10 and since the sum of the first pair wasn't 10, no need to go on. :)