function a($,$p)
;???
;$r input card order
;$p input chosen piles
dim $t,$q,$r,$b
;$t countdown from 52 cards
;$q current pile number
;$ holds value of current card
;$b sum of values of chosen pile card values
$ = Join(Split($,10),K) ; replaces all 10s bij K to make sure every 2 positions there is 1 card value in every 2 positions
$t=36 ;since we have to ignore 16 cards of the leftover cards 52 - 16
While $
$r = 10*(1>$)+$-9*(65=asc($)) ;gets the current pile card value
$ = right($,$r*2-24) ;removes cards from card order
$q = $q + 1 ;move to next pile (start at 0)
If Ascan(Split($p), $q) + 1 ;check wether the current pile is one of the chosen ones
$t = $t - 12 + $r ;remove the cards from the leftover cards
$b = $b + $r ;add the current value to the chosen pile sum
If $t = $b ;if both calculations match then set the output (since one counts up and the other counts down this is always the last iteration
$a = $t
endfunction