Skip to content

Instantly share code, notes, and snippets.

@katsuyoshi
Last active October 1, 2021 23:45
Show Gist options
  • Select an option

  • Save katsuyoshi/67995f4d175800ecf84ff048077f50a7 to your computer and use it in GitHub Desktop.

Select an option

Save katsuyoshi/67995f4d175800ecf84ff048077f50a7 to your computer and use it in GitHub Desktop.
お題は「100日後に退職する47歳」 78日目: https://twitter.com/tome_ura/status/1443411147881783300
def combi_abx a,b,x
print "combi_abx(a:#{a}, b:#{b}, x:#{x})\t"
x100 = x / 100
a100 = a
b100 = b / 10
b100 = [b100 - 1, 0].max if (b % 10) < (x / 10) % 10
return 0 if a100 + b100 < x100
[b100, x100].min + ((a100 < x100) ? 0 : 1)
end
puts " => #{combi_abx(9,0,1000)}" # => 0
puts " => #{combi_abx(9,9,1000)}" # => 0
puts " => #{combi_abx(9,10,1000)}" # => 1
puts " => #{combi_abx(10,0,1000)}" # => 1
puts " => #{combi_abx(10,30,1000)}" # => 4
puts " => #{combi_abx(10,36,1050)}" # => 4
puts " => #{combi_abx(10,35,1050)}" # => 4
puts " => #{combi_abx(10,34,1050)}" # => 3
puts " => #{combi_abx(100,50,120)}" # => 2
puts " => #{combi_abx(100,50,1230)}" # => 5
puts " => #{combi_abx(100,50,1200)}" # => 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment