Skip to content

Instantly share code, notes, and snippets.

@abom
Forked from mie00/bills.py
Last active November 9, 2018 13:45
Show Gist options
  • Save abom/db0f8c66782ee91939226b80a6a1397d to your computer and use it in GitHub Desktop.
Save abom/db0f8c66782ee91939226b80a6a1397d to your computer and use it in GitHub Desktop.
For bills and stuff
#!/usr/bin/env python
def calc(gross, delivery, **d):
"""
usage:
>>> calc(120, 9,
Ashraf=40,
Thabet=20,
Awadi=20,
Ghanem=20)
net: 100
Ghanem: 24.5
Thabet: 24.5
Ashraf: 46.5
Awadi: 24.5
total: 120.0
"""
s = sum(map(lambda (x, y): y, d.items()))
a2 = [(name, (lambda x:int(x) + [0,0.5,0.5,1][int(4 * (x % 1))])(i * 1.0 * (gross - delivery) / s + 1.0 * delivery / len(d))) for (name, i) in d.items()]
print("net: %s"%(s))
print('\n'.join(map(lambda (x, y): '%s: %s'%(x, y), a2)))
print('total: %s'%sum(map(lambda (x, y):y, a2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment