Skip to content

Instantly share code, notes, and snippets.

@baya
Last active October 13, 2015 01:08
Show Gist options
  • Save baya/4115408 to your computer and use it in GitHub Desktop.
Save baya/4115408 to your computer and use it in GitHub Desktop.
计算竞彩足球注数
# -*- coding: utf-8 -*-
# 竞彩注码算法
# 用例
# teams = [
# [1, '3', '0', '*'],
# [2, '3', '-'],
# [3, '3', '-'],
# [4, '3', '1', '*'],
# [5, '3', '0', '*'],
# [6, '3', '1', '-'],
# [7, '3', '0', '*'],
# ]
# betsum = CalContestBetsum play_kind: '5*6', teams: teams
# puts "注数为#{betsum}"
class CalContestBetsum < Dun::Land
data_reader :play_kind, :teams
attr_reader :single_checkpoints, :betsum
# 1*1 表示单关
BET_TABLE = {
'1*1'=>[1],
'2*1'=>[2], '2*3'=>[2, 1],
'3*1'=>[3], '3*3'=>[2], '3*4'=>[2,3], '3*7'=>[3, 2, 1],
'4*1'=>[4], '4*4'=>[3], '4*5'=>[4,3], '4*6'=>[2],'4*11'=>[4,3,3], '4*15'=>[4, 3, 2, 1],
'5*1'=>[5], '5*5'=>[4], '5*6'=>[5, 4], '5*10'=>[2], '5*16'=>[5, 4, 3], '5*20'=>[3, 2], '5*26'=>[5, 4, 3, 2], '5*31'=>[5, 4, 3, 2, 1],
'6*1'=>[6], '6*6'=>[5],'6*7'=>[6, 5],'6*15'=>[2], '6*20'=>[3], '6*22'=>[6, 5, 4],
'6*35'=>[3,2],'6*42'=>[6, 5, 4, 3], '6*50'=>[4, 3, 2],'6*57'=>[6, 5, 4, 3, 2], '6*63'=>[6, 5, 4, 3, 2, 1],
'7*1'=>[7],'7*7'=>[6],'7*8'=>[7,6],'7*21'=>[5],'7*35'=>[4],'7*120'=>[7,6,5,4,3,2],
'8*1'=>[8], '8*8'=>[7],'8*9'=>[8,7],'8*28'=>[6],'8*56'=>[5],'8*70'=>[4],'8*247'=>[8,7,6,5,4,3,2],
'9*1'=>[9],
'10*1'=>[10],
'11*1'=>[11],
'12*1'=>[12],
'13*1'=>[13],
'14*1'=>[14],
'15*1'=>[15]
}
def initialize data
super data
@single_checkpoints = split_to_signle_checkpoints
end
def split_to_signle_checkpoints
single_checkpoints = []
teams.each {|team|
team[1..-2].uniq.each {|st|
single_checkpoints << [team[0], st]
}
}
single_checkpoints
end
# 将数组teams拆分成包含有num个元素的组合
# Params
#
# num - 拆分后的组合中含有的元素个数
# teams - 从此集合中取num个元素进行组合
#
# Example:
# # [[[1,3],[2,3]], [[1,3],[3,3]], [[1,3],[4,3]],[[2,3],[3,3]], [[2,3],[4,3]], [[3,3],[4,3]]]
# comb(2, [[1, 3], [2, 3], [3, 3], [4, 3]])
#
def check_points_combination(num)
single_checkpoints.combination(num).to_a.delete_if {|checkpoint|
cf = checkpoint.map {|cp| cp[0] }
cf.size > cf.uniq.size
}
end
def call
@betsum = BET_TABLE[play_kind].inject(0){|betsum, num|
betsum + check_points_combination(num).uniq.length
}
end
end
@WPCWEG
Copy link

WPCWEG commented Jul 1, 2014

O_o 这是Ruby 写的吗?撸主有没有其他语言版本的?

@baya
Copy link
Author

baya commented Sep 25, 2014

ruby写的,没有其他语言版本

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment