tot_cards = 9

options = [[1,1] ]
labels = [ 1 ]  

(tot_cards-1).times do |cnt|  
  inp = options[cnt] 
  out =  inp.clone  
  out  << 0
  inp.each_index  { |i| out[i+1] += inp[i] }
  options << out 
end 

options_tot = options.collect { |inp| inp.sum } 

# puts options[1..5]  
# puts options_tot  

fold_keys = [ ]  
fold_cnts = [] 
fold_percents = [] 

options.each_with_index  do |opt, idx|
  cards_cnt = idx+1 
  fold_point = (cards_cnt + 1)/2 
  opt_cnt = opt.length    
  odd_hand = cards_cnt.odd?           
  keys  = fold_point.times.to_a.collect{|i| [cards_cnt - i, i] }   
  keys << [ fold_point ] unless odd_hand  
  fold_keys << keys  

  cnts = keys.collect{|ks| ks.inject(0){|v,k| v+=opt[k]}} 

  fold_cnts  << cnts

  tot = options_tot[idx] 
  fold_percents << cnts.collect{ |c| 100.0 * c / tot }   
 
end

8.times do | idx | 

  puts "\nChances when #{idx+1} cards are split between two hands"

  keys = fold_keys[idx] 
  percents = fold_percents[idx] 
  accum = 0  

  keys.each_with_index do | k, i | 
    percent = percents[i] 
    accum += percent
    phead  =  k.length == 1 ? "even #{k[0]}" : k.join(' / ')   
    ahead  =  "one hand more than #{k.first-1}" 
    puts "\t#{phead} = #{percent.round(1)}%\t#{ahead} = #{accum.round(1)}%" 
     
  end  


end 



