#!/usr/bin/env ruby
$VERBOSE = true

class Array
  include Comparable
  def count(v)
    reject{|x|x!=v}.length
  end
end

def pokerkey(h)
  v = h.map{|x|x[0]}.sort.reverse
  g = v.uniq.map{|x|[v.count(x),x]}.sort.reverse
  c = g.map{|x|x[0]}
  r = g.map{|x|x[1]}
  f = (h.map{|x|x[1]}.uniq.length == 1)
  r = [5, 4, 3, 2, 1] if r == [14, 5, 4, 3, 2]
  v = [5, 4, 3, 2, 1] if v == [14, 5, 4, 3, 2]
  s = ((0..3).map{|i|v[i+1]+1==v[i]}.count(true) == 4)
  return [8, *r] if s and f
  return [7, *r] if c[0] == 4
  return [6, *r] if c[0] == 3 and c[1] == 2
  return [5, *v] if f
  return [4, *r] if s
  return [3, *r] if c[0] == 3
  return [2, *r] if c[0] == 2 and c[1] == 2
  return [1, *r] if c[0] == 2
  return [0, *r]
end