Skip to content

Instantly share code, notes, and snippets.

@shapr
Created June 19, 2019 17:50
Show Gist options
  • Save shapr/c34d52220b04318fd2287a46a8147a58 to your computer and use it in GitHub Desktop.
Save shapr/c34d52220b04318fd2287a46a8147a58 to your computer and use it in GitHub Desktop.
"""
Pablo buys popsicles for his friends.
The store sells single popsicles for$1 each, 3-popsicle boxes for$2, and 5-popsicle boxes for$3.
What is the greatest number of popsicles that Pablo can buy with$8?
"""
from z3 import *
box1pop, box3pop, box5pop =Ints('box1pop box3pop box5pop')
pop_total=Int('pop_total')
cost_total=Int('cost_total')
s=Optimize()
s.add(pop_total == box1pop*1 + box3pop*3 + box5pop*5)
s.add(cost_total == box1pop*1 + box3pop*2 + box5pop*3)
s.add(cost_total==8)
s.add(box1pop>=0)
s.add(box3pop>=0)
s.add(box5pop>=0)
s.maximize(pop_total)
prints.check()
prints.model()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment