Your task is to find how many distinct Blackjack sequences can be found in an ordered list of 12 cards.
A Blackjack sequence is defined as a sequence of consecutive cards whose sum of points is exactly 21. Points are counted according to the following table:
Symbol | Name | Points Symbol | Name | Points
-------+-------+-------- -------+-------+--------
2 | Two | 2 9 | Nine | 9
3 | Three | 3 T | Ten | 10
4 | Four | 4 J | Jack | 10
5 | Five | 5 Q | Queen | 10
6 | Six | 6 K | King | 10
7 | Seven | 7 A | Ace | 1 or 11
8 | Eight | 8
Input
A 12-character string, using the symbols described above. We do not care about the colors of the cards, so they are not provided.
Example:
K6K6JA3Q4389
Output
The number of distinct Blackjack sequences that can be found in the input string.
Example:
K6K6JA3Q4389
includes two distinct Blackjack sequences:
JA
, with the Ace being counted as 11 points (10 + 11 = 21)A3Q43
, with the Ace being counted as 1 point (1 + 3 + 10 + 4 + 3 = 21)
So the answer would be 2
.
Rules
- Two Blackjack sequences are considered distinct if they contain different cards or the same cards in different orders. If the exact same sequence appears at different positions in the input list, it must be counted only once.
- The Blackjack sequences may overlap each other.
- Each kind of card may appear up to 12 times in the sequence. (We assume that the cards are picked from at least 3 different decks.)
- If no Blackjack sequence can be found in the input string, you must return
0
or any other falsy value. - This is code-golf, so the shortest answer in bytes wins. Standard loopholes are forbidden.
Test cases
The sequences are provided for information purposes, but you're only required to output the number of them.
Input | Output | Distinct sequences
-------------+--------+--------------------------------------------------------
3282486Q3362 | 0 | (none)
58A24JJ6TK67 | 1 | 8A2
Q745Q745Q745 | 1 | Q74
AAAAAAAAAAAA | 1 | AAAAAAAAAAA
T5AQ26T39QK6 | 2 | AQ, 26T3
JQ4A4427464K | 3 | A442, 44274, 7464
Q74Q74Q74Q74 | 3 | Q74, 74Q, 4Q7
37AQKA3A4758 | 7 | 37A, 37AQ, AQ, AQK, QKA, KA, A3A475
TAQA2JA7AJQA | 10 | TA, TAQ, AQ, QA, A2JA7, 2JA7A, JA, AJ, AJQ, JQA
TAJAQAKAT777 | 13 | TA, TAJ, AJ, JA, JAQ, AQ, QA, QAK, AK, KA, KAT, AT, 777