+1 vote
in Programming Languages & Algorithms by

Write an algorithm for making a peanut butter and jelly sandwich, using a vocabulary of just 20 words (you choose the words). Assume that all ingredients are available in the cabinet or refrigerator and that the necessary tools are in a drawer under the kitchen counter. The instructions must be very simple and exact because the person making the sandwich has no knowledge of food preparation and takes every word literally.

1 Answer

0 votes
by
selected by
 
Best answer

Take the jars of jelly and peanut butter from the fridge

Get a blunt knife from the kitchen

Take a slice of the bread and put it on a tray or flat surface

Take a knife using its handle and insert its sharper end into the jar containing peanut butter to scrape little amount of the peanut butter from the jar

Spread the scraped peanut butter onto the surface of the slice of bread

if the peanut butter covers all the surface of the bread, take another slice of bread and put it on the flat surface

Else

Insert the sharper end of the knife again into the jar containing peanut butter to scrape more peanut butter and spread it onto the surface of the slice of bread until the whole surface is full covered.

Insert the sharper end of the knife into the jar containing jelly to scrape the jelly and spread it on the second slice

If the scrapped jelly does not cover the whole surface of the slice of bread, scrape more jelly from the jar and spread it on the slice until it is fully covered

Else,

Place the jellied slice over the buttered slice and align the edges of the two slices and press them together then cut the combined slices diagonally

The sandwich is now ready to be served.

Related questions

Welcome to CPEN Talk
Solution-oriented students of computer engineering on one platform to get you that

ONE SOLUTION

Chuck Norris can instantiate an abstract class.
...