how i can get the lowest price on every job here | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

how i can get the lowest price on every job here

i have this job 1 job 2 job 3 job 4 A 5 7 4 3 B 10 3 7 6 C 7 4 5 3 D 3 1 2 3 i have that question there are 4 workers and jobs, each worker has the price of each job, how can i look for which workers will work at the lowest prices with different workers ex : price of a , b, c, d is 5+3+5+3=16 price of a , b, d, c is 5+3+2+3=13

7th Oct 2018, 3:24 AM
Ruuko
Ruuko - avatar
12 Answers
+ 3
There are probably better ways than trying every combination, but they might be more difficult to implement. Here's what I would do: Find every combination of A, B, C, D, for example with nested loops. Find the price of each combination and compare it with the minimum price that is stored in a variable. If the price of the combination is lower, update the minimum price variable accordingly. You can store the optimal combination in a string variable or in an array of strings as there are (spoiler warning) two combinations that share the lowest price.
7th Oct 2018, 6:05 AM
Anna
Anna - avatar
+ 3
No problem
7th Oct 2018, 2:02 PM
Anna
Anna - avatar
+ 2
I could post a possible solution in python but I don't think it would help you implement the pattern described above because the python code is totally different 🤓
7th Oct 2018, 1:58 PM
Anna
Anna - avatar
+ 2
thanks for your hard work
7th Oct 2018, 2:00 PM
Ruuko
Ruuko - avatar
7th Oct 2018, 11:22 PM
Hatsy Rei
Hatsy Rei - avatar
+ 1
Daniel (kabura) I think that would lead to worker D doing every job (because he's the cheapest in every category), but as I understand it, every worker can only do one job, so it has to be a combination of A-B-C-D.
7th Oct 2018, 6:11 AM
Anna
Anna - avatar
+ 1
Yes, there are fancy algorithms (like https://en.m.wikipedia.org/wiki/Hungarian_algorithm ), but what Anna said works perfectly, and is fairly simple to implement.
7th Oct 2018, 1:52 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 1
what the main issue is i dont know how to write it to code 😞
7th Oct 2018, 1:56 PM
Ruuko
Ruuko - avatar
+ 1
oh its okay
7th Oct 2018, 1:59 PM
Ruuko
Ruuko - avatar
0
You can create int pirice tables for each employee, and then find the smallest value in each table
7th Oct 2018, 6:06 AM
Daniel (kabura)
Daniel (kabura) - avatar
0
i just want to know how it works
7th Oct 2018, 1:59 PM
Ruuko
Ruuko - avatar