How many Blackjack sequences in that list?
Python 2, 215 bytes
def b(s,a=[],r=range):
S=map(lambda x:":">x>"1"and int(x)or 10-(x=="A")*9,s)
for i in r(12):
for j in r(13):
if 21in[x*10+sum(S[i:j])for x in r(S[i:j].count(1)+1)]and s[i:j]not in a:a+=s[i:j],
return len(a)
Comments added:
def b(s,a=[],r=range): # Define the function b and a list, a, which holds all the blackjack sequences
S=map(lambda x:":">x>"1"and int(x)or 10-(x=="A")*9,s) # Set S to the score of each card in b
for i in r(12): # Loop with i from 0 to 11
for j in r(13): # Loop with j from 0 to 12
if 21in[x*10+sum(S[i:j])for x in r(S[i:j].count(1)+1)]\ # If 21 is included in all the possible sums that the scores between i and j in S can be
and s[i:j]not in a: # And that sequence is not already included,
a+=s[i:j], # Append that sequence to a
return len(a) # Return the amount of elements in a
Jelly, 30 29 bytes
1e×5,⁵Ḥ‘
O_48«26%⁴µSeÇ
ẆÇÐfQL
Try It Online! or check out the test suite
How?
Note that, if we always value an ace as 1 then the only valid sums are 21 and 11, the latter being acceptable iff an ace appears in the sequence.
ẆÇÐfQL - Main link: string
Ẇ - all non-empty contiguous sublists
Ðf - filter keep if...
Ç - last link (2) as a monad ...is truthy
Q - unique results
L - length
O_48«26%⁴µSeÇ - Link 2, isBlackjackSubtring: char array e.g. ['A','2','8','Q']
O - cast to ordinal values [ 65, 50, 56, 81]
_48 - subtract 48 [ 17, 2, 8, 33]
26 - 26
« - minimum (vectorises) [ 17, 2, 8, 26]
⁴ - 16
% - modulo [ 1, 2, 8, 10]
µ - monadic chain separation (call the result v)
S - sum(v) 21
Ç - last link (1) as a monad link_1(v) [11,21]
e - exists in? 1
1e×5,⁵Ḥ‘ - Link 1 validSums: value list (where A is 1, and {T,J,Q,K} are 10)
1e - 1 exists in? (are there any aces? Yields 1 or 0)
×5 - multiply by 5 (5 or 0)
⁵ - 10
, - pair ([5,10] or [0,10])
Ḥ - double ([10,20] or [0,20])
‘ - increment ([11,21] or [1,21])
- ^
- note: if no ace is in the sequence it's sum can't be 1 anyway
JavaScript (ES6), 144 138 129 128 126 124 bytes
g=([c,...s],a=[],q=new Set)=>c?g(s,[...a,[,21]].map(([x,y,A])=>[x+=c,y-=+c||(c<'B'?A=1:10),A,y&&y^10*A||q.add(x)]),q):q.size
Old attempt at 128:
s=>(q=new Set,f=s=>s?f(s.slice(1))&f(s.slice(0,-1))&[...s].map(c=>t+=-c||~(c<'B'?A=0:9),t=A=21)|t&&t-10*!A?q:q.add(s):q)(s).size