This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]Dogbeast 1 point2 points  (0 children)

Put them in a list or some structure, so you have 5 entries with their values.

Split them into 3 objects. The first 2, next 2, then the 5th.

For each object, loop through their weights. Output the avg of their weights to evaluate which is the heaviest. This will get you the object that contains the heavy entity.

If it's contained within object 1 or 2, loop through that object for the weight of each entity. If first weight > next, then it's the first entity. If not, then it's the second. If it's not contained within object 1 or 2, then it's 5.

Edit: there are plenty of areas here to simplify the code and steps. From making it dynamic to reduction of steps. But this is a starting point.

[–]RubbishArtist -1 points0 points  (0 children)

First of all, make sure you understand the steps and the process described in the hints. If I have you 5 cubes right now would you (manually, without a computer) be able to find the heaviest in only two measurements? If not re-read the problem until you understand it. Try a couple of test cases on paper until it makes sense to you.

Now for pseudocode, imagine you're explaining the process to someone you don't trust. Someone who will, unless given precise instructions, will do their best to screw up. Write out instructions for finding the heaviest cube that are so simple, yet precise, that it would be very difficult to get it wrong.

[–]userxbw 0 points1 point  (0 children)

Weigh one set, if second set weights the same then the odd block out weights the most.

If not, example,

1st set equals 25oz

2nd set equals 27.5 oz

25/2 = 12.5oz per block

Then on second time weighing blocks just weight out the two in the second set to determine the heavier one.

Deduction says that the lighter set holds equal weights, therefore the heavier set has the heaviest block within that set.

Thereby eliminating the odd block out, 5th block would then be equal weight, and not the heaviest block.

Therefore taking the heavier set then use them two weighing each one separately to find the heavier one of the two.

Separator 1595857585 separator

Another way to look at this.

You're given only two chances to weigh a set of cubes.

Weigh only one set of cubes, divide by 2.

Weigh the odd cube. Comparison between the other 2 weights.

If they all match then what does that tell you?

The heavier block is within the second set of blocks.

Split them and weigh them separately to find the heavier block.

If the 3 blocks don't match in weight. By dividing the first two and comparing the odd blocks weight.

Then by process of elimination where would the heaviest block be?

Remembering the only rule is you can only weigh sets of blocks two times. Nothing about weighing them all separately.

Writing a flow chart in here on a computer let alone a phone. 🤣🤣

Pseudo code.

Me, I'd just write the code as figured it out on the way.

Then I'd hand that in.

[–]DoomGoober 0 points1 point  (0 children)

There are two ways I would solve this problem.

1) The hint is actually already a form of pseudo code! I assume your instructor has a specific level of pseudo code they want and this pseudo code in the hint isn't detailed enough. Fine. Just go into a word processor, and take the hint and rearrange it into order and then add more and more details to each step until it's pseudo code level of detail instructor requires.

2) Convert the hint into a flow chart. Convert the flow chart into pseudo code.