Skip to content

Instantly share code, notes, and snippets.

@alexpacer
Last active August 29, 2017 01:44
Show Gist options
  • Save alexpacer/c68bd497653b0836c2254aed57a13afc to your computer and use it in GitHub Desktop.
Save alexpacer/c68bd497653b0836c2254aed57a13afc to your computer and use it in GitHub Desktop.
The Sample script of producing followup betting
# -*- coding: utf-8 -*-
require 'optparse'
require 'bigdecimal'
class FollowupBetting
@@price = 5.98 # 賠率
@@bet_amt = 2 # 注金
@@init_multiplier = 1 # 起始倍率
@@spending = 0
@@amt_spent = 0 # 累計投入
@@revenue_limit = 600000 # 簡單最大限紅
@@tmp_term = nil
def initialize(opt)
@@price = opt[:price] || 5.98
@@bet_amt = opt[:bet_amt] || 2
@@init_multiplier = opt[:init_multiplier] || 1
@@revenue_limit = opt[:revenue_limit] || 600000
end
def init_multiplier
@@init_multiplier
end
def revenue_limit
@@revenue_limit
end
def type1(watermark, number_of_terms)
puts "我的全程最低盈利至少 #{watermark} %"
results = []
i = @@init_multiplier
(1..number_of_terms).each do |term|
break if revenue_check(i)
data = fourmula(term, i)
while data[:rev_percent] < watermark do
i = i + 1
if revenue_check(i) # 獎金超過, 停止產生下一期方案
data = nil
break
end
data = fourmula(term, i)
end
if !data.nil?
@@amt_spent = @@amt_spent + (i * @@bet_amt)
results << data
end
end
results
end
def type2(watermark, number_of_terms)
puts "全程最低盈利金額 #{watermark} 元"
results = []
i = @@init_multiplier
(1..number_of_terms).each do |term|
break if revenue_check(i)
data = fourmula(term, i)
while data[:bet_revenue] < watermark do
i = i + 1
if revenue_check(i) # 獎金超過, 停止產生下一期方案
data = nil
break
end
data = fourmula(term, i)
end
if !data.nil?
@@amt_spent = @@amt_spent + (i * @@bet_amt)
results << data
end
end
return results
end
def temp_term
@@tmp_term
end
def type3(max, number_of_terms)
puts "我的全程金額不超過 #{max} 元"
results = []
while true do
i = @@init_multiplier
tmp = []
(1..number_of_terms).each do |term|
@@tmp_term = fourmula(term, i)
tmp << fourmula(term, i)
@@amt_spent = @@amt_spent + (i * @@bet_amt)
i = i * 2
end
if tmp.last[:amt_spent] > max
break
else
@@init_multiplier = @@init_multiplier * 2 # 增加起始倍數
@@amt_spent = 0 # 重設累計投注
results = tmp
end
end
@@init_multiplier = results.first[:multiplier] if results.count > 0 # 起始倍數要等於結果 array 的第一個倍數
results
end
# 中獎金額會超過 30 萬,這邊*金有檔,不然如果不擋要更好的演算法才不會慢
def revenue_check(multiplier)
multiplier * @@price > @@revenue_limit
end
# Generates each term's multiplier
def fourmula(term, multiplier)
amt_spent = @@amt_spent + (multiplier * @@bet_amt) # 累計投入
bet_spent = multiplier * @@bet_amt # 當前投入
bet_revenue = BigDecimal.new((@@price * multiplier) - amt_spent, 8) # 盈利 = 獎金 * 倍率 - 投注金額
rev_percent = (bet_revenue / amt_spent).to_f * 100 # 盈利率 %
{
term: term,
multiplier: multiplier,
bet_spent: bet_spent,
amt_spent: amt_spent,
bet_revenue: bet_revenue.to_f,
rev_percent: rev_percent
}
end
end
def output(data)
puts "第 %d 期, 倍數 %d, 投注金額 %d, 累計投注 %d, 盈利 %f, 盈利率 %f %" %
[data[:term], data[:multiplier], data[:bet_spent], data[:amt_spent], data[:bet_revenue], data[:rev_percent]]
end
OptionParser.new do |parser|
initMultiplier = 1 # 起始倍數
price = 3.98 # 賠率
bet_amt = 2.0 # 單注金額
terms = 0
c = FollowupBetting.new({
:price => price,
:bet_amt => bet_amt,
:init_multiplier => initMultiplier
})
puts "獎金: #{price}, 下注金額: #{bet_amt}, 起始倍數: #{initMultiplier}"
parser.on("-r", "--revenue [Revenue]", "全程最低盈利率") do |v|
start = Time.now
terms = 5
puts "投注 #{terms} 期, 開始時間: #{start}"
r = c.type1(v.to_i, terms)
r.each do |x|
output(x)
end
puts "中獎金額 => #{price * r.last[:multiplier]}, 限紅 #{c.revenue_limit}"
fin = Time.now
puts "結束時間: #{fin}, 花費時間: #{fin - start}"
end
parser.on("-a", "--amount [Amount]", "全程最低盈利金額") do |v|
start = Time.now
terms = 60
puts "投注 #{terms} 期, start: #{start}"
r = c.type2(v.to_i, terms)
r.each do |x|
output(x)
end
if r.count > 0
puts "中獎金額 => #{price * r.last[:multiplier]}, 限紅 #{c.revenue_limit}"
end
fin = Time.now
puts "結束時間: #{fin}, 花費時間: #{fin - start}"
end
parser.on("-m", "--max [Amount]", "我的全程金額不超過") do |v|
start = Time.now
terms = 10
puts "投注 #{terms} 期, start: #{start}"
r = c.type3(v.to_i, terms)
if r.count == 0
puts "全程追號不足追 #{terms} 期 #{(c.temp_term.nil?) ? "" : "至少需要 " + c.temp_term[:amt_spent].to_s + " 元"} "
else
r.each do |x|
output(x)
end
puts "起始倍率 => #{c.init_multiplier}"
end
fin = Time.now
puts "結束時間: #{fin}, 花費時間: #{fin - start}"
end
end.parse!
@alexpacer
Copy link
Author

if you've got ruby, run it like this

ruby followup_betting.rb -m 5000

ruby followup_betting.rb -a 100

ruby followup_betting.rb -r 100

you may want to adjust prices and bet amount if needed, change it at line 139 - 141

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