N
N
NamnaR2018-12-24 21:31:55
Algorithms
NamnaR, 2018-12-24 21:31:55

How to choose a multiplicity from the listed multiplicity for a given amount?

Guys, good afternoon, tell me, please, with the algorithm. I won't put my mind to it.
I ask for help in the matter.
Multiplicities 30, 70, 90, 100 are given. The amount that the user enters.
if the user enters 60 , then this amount does not change. if the user enters 45-> sum 70 155->160(30+70+30+30)
150->150(90+30+30)
UPD
The task is as follows. Given a box of 30 pieces - 2 packs, a box of 70 pieces - 3 packs, a box
of 90-1 packs, a box of 100 - 8 packs multiplicity equal to 60 (2 boxes of 30)
- if the user entered 45, then you need to dial the SUM of multiplicities equal to 70 (1 box of 70, because the priority is to give a smaller number of coins)
- if the user entered 155, then you need to dial the SUM of multiplicities equal to 160 (4 boxes 30 70 30 30, or if the number of coins is to give 2 boxes 90 and 70)
The customer can order the number of goods exceeding the availability (30*2+70*3+90+8*100=1160). but then it will be on order. The main thing for me is to forbid the client to order 5 positions - you can order only 30.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dimonchik, 2018-12-24
@dimonchik2013

'60' is a number, not a sum

K
kantenbors, 2018-12-29
@kantenbors

This condition is not clear:
"if the user entered 45, then you need to dial the SUM of multiplicities equal to 70 (1 box of 70, because the priority is to give a smaller number of coins)"
If without it, then the solution is like this (for 45, the answer will be 60) :
def f(v):
n=(v+9)//10
if n<7: n=(n+2)//3*3
if n in (8,11): n+=1
return n*10

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question