Skip to content

Instantly share code, notes, and snippets.

@elderica
Created January 8, 2023 13:32
Show Gist options
  • Save elderica/511c39b0e08d3c62f49a3b51325b3f27 to your computer and use it in GitHub Desktop.
Save elderica/511c39b0e08d3c62f49a3b51325b3f27 to your computer and use it in GitHub Desktop.
IIJmio Mobile Planner
from collections import namedtuple
from itertools import product
from functools import reduce
from pprint import PrettyPrinter
Plan = namedtuple('Plan', ['type', 'data_amount', 'price'])
plans_voice = [
Plan(type='voice', data_amount=2, price=850),
Plan(type='voice', data_amount=4, price=990),
Plan(type='voice', data_amount=8, price=1500),
Plan(type='voice', data_amount=15, price=1800),
Plan(type='voice', data_amount=20, price=2000),]
plans_sms = [
Plan(type='sms', data_amount=2, price=820),
Plan(type='sms', data_amount=4, price=970),
Plan(type='sms', data_amount=8, price=1470),
Plan(type='sms', data_amount=15, price=1780),
Plan(type='sms', data_amount=20, price=1980),]
plans_data = [
Plan(type='data', data_amount=2, price=740),
Plan(type='data', data_amount=4, price=900),
Plan(type='data', data_amount=8, price=1400),
Plan(type='data', data_amount=15, price=1730),
Plan(type='data', data_amount=20, price=1950),]
plans_esim = [
Plan(type='esim', data_amount=2, price=440),
Plan(type='esim', data_amount=4, price=660),
Plan(type='esim', data_amount=8, price=1100),
Plan(type='esim', data_amount=15, price=1430),
Plan(type='esim', data_amount=20, price=1650),]
plans = list(product(
plans_voice,
plans_voice,
plans_esim))
def keyf(p):
data_amount = sum(q.data_amount for q in p)
price = sum(q.price for q in p)
return data_amount / price
plans.sort(key=keyf)
PlanComb = namedtuple('PlanComb', ['comb', 'data_amount', 'price'])
def make_comb(p):
comb = tuple((q.type, q.data_amount) for q in p)
data_amount = sum(q.data_amount for q in p)
price = sum(q.price for q in p)
return PlanComb(comb=comb, data_amount=data_amount, price=price)
prices = tuple(make_comb(p) for p in plans)
filtered = list(p for p in prices
if 3000 <= p.price and p.price <= 4100
and 24 <= p.data_amount and p.data_amount <= 36
)
pp = PrettyPrinter()
pp.pprint(filtered)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment