Please help me with my hw question I am very stuck! Thank you 3.) [8 pts] Consid
ID: 3732750 • Letter: P
Question
Please help me with my hw question I am very stuck! Thank you
3.) [8 pts] Consider Snow White and her Concurrent MetateM friends the dwarves. Let's assume that dwarves can bid for sweets if they have the money, e.g. dwarfl might have the rules Omoney (N) A N22]ask(dwarfl,2) O[money(N) A give(dwarf1,c)]money (N-c) Write a rule for dwarf2 that says if dwarf1 bids b, and b is higher than m (where myLastBid (m), that is m is the amount of dwarf2's last bid), that dwarf2 will bid b+1 if he has the money (where money (N) is the amount of money the dwarf has).Explanation / Answer
Please find the answer to the following question.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
[money(N) ^ N>=2] => ask(dwarf1,2)
[money(N) ^ give(dwarf1)] => ask(dwarf1,C)] => money(N-C)
Here, since we are not aware in what language coding has to be done, we
will write the algrithm for the same.
In this algorithm, we are having dwarfs, for the sake of simplcity of understanding, we are
considering only 2 dwarfs, dwarf1 and dwarf2.
dwarf1 and dwarf2 are bidding for sweets.
dwarf2 has already bid for money M.
money(N) is the total amount that we have.
Now, we have to write the algorithm for dwarf2 . So we need to take some assumptions which willl become
the initial values for the variables when coding the actual program.
Here, let dwarf2_money be C and dwarf2_LastBid be M.
=> dwarf2_money = C.
=> dwarf2_lastBid = M.
=> dwarf1 bids B,
=> if(B is greater than M)
if(C is greater than B)
=> dwarf2 bids B+1
=> dwarf2_money = C - (B+1)
else
=> dwarf1 gets the sweets.
else
=> dwarf2 gets the sweets.
In the above mentioned algorithm, I tried to explain the logic behind the program.
This algorithm can be iterated for n numbers of dwafs and also, we can use loops to get the money and the list bid value of the dwarfs.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Let me know if any doubts you have.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////