Skip to content

Instantly share code, notes, and snippets.

/coupon.rb Secret

Created May 9, 2016 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/306f0a1fe2a694c9a0b54ba41e244b71 to your computer and use it in GitHub Desktop.
Save anonymous/306f0a1fe2a694c9a0b54ba41e244b71 to your computer and use it in GitHub Desktop.
coupon.rb
# ruby coupon.py 100 50 5
# 1-50|2-100|3-150|4-200|5-250
# ruby coupon.rb 199 155 10
# 1-44|2-88|3-132|4-176|5-220|6-264|7-308|8-352|9-396|10-440
reg = ARGV[0].to_i
sale = ARGV[1].to_i
coupon_max = ARGV[2].to_i
price = reg - sale
coupon = ''
1.upto(coupon_max) do |index|
coupon << "#{index}-#{price * index}|"
end
coupon = coupon[0...-1]
puts coupon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment