function a($,$b)
dim $c, $x, $f, $v
;$c - current card
;$v - the subject knowledge
;$ - original stack of 52 cards, inside for each used to count cards in current stack
;$x - count of stacks this far
;$f - first card in a new stack
$a = 36 ;52 cards - 16
for each $c in split($)
if 0=$f ;no cards in stack yet, get the face value of the first card
$f = 10*(1>$c)+$c-9*('A'=$c) ;case sensitive 199 code has this: ('a'=$c | 'A'=$c) ;value of first card. you could also use ucase() but it doesn't look as good.
$ = 0 ;new stack
endif
$ = 1+$ ;add a card to the current stack
if 12=$+$f ; is same as 11 = count of cards in stack minus one plus first card value
$x = 1 + $x ;another card stack on da table
if 1+ascan(split($b),$x) ;if this is one of the stacks the mark selected
$a = $a - $ ;magician removes from the count of cards, the amount of cards $ in the stack that the subject selected
$v = $v + $f ;subject selects their stack and sees the face value of $
endif
$f = 0 ;start a new stack
endif
next
if $a^$v ;if our calculated sum $a does not match to the sum of marks cards $v, return 0. never will happen so kinda pointless ;)
$a=0
endfunction