Created
May 8, 2020 04:09
-
-
Save bitfishxyz/4771622654133a72d0bd78a5bd4121f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get the price of apples from a fruit store | |
function getApplePrice(fruitStore) { | |
'start visiting the fruit store'; | |
'walk to the fruit shop'; | |
if('the fruit store was not open'){ | |
'stop the process of visiting the fruit store'; | |
return false; | |
} | |
if('the fruit store did not have apples'){ | |
'stop the process of visiting the fruit store'; | |
return false; | |
} | |
'Ask the shopkeeper the price of the apples'; | |
return thePriceOfApples; | |
} | |
// Buy apples from the fruit store | |
function buyApples(fruitStore, weight) { | |
'walk to the fruit store'; | |
while('the weight of the apples in this bag' < weight){ | |
'choose the best of all the red apples that are not in the bag'; | |
if('this apple can fit into the current bag'){ | |
'load this apple into the current bag'; | |
} else { | |
// switch the bag | |
if('I still have some spare bags') { | |
'pick one of these and make it the current bag'; | |
} else { | |
try('ask the shopkeeper for a bag') { | |
'take the bag the shopkeeper gave me as the current bag'; | |
} catch ('the shopkeeper refused to give me the bag') { | |
'take all the apples out of all my bags'; | |
'stop the process of visiting the fruit store'; | |
} | |
} | |
} | |
} | |
'based on the total weight of all the apples in all my bags and \ | |
the unit price given by the store owner, calculate the price I should pay' | |
'ask the shopkeeper for my share of the money' | |
if('the price I calculated' == 'the price given by the shopkeeper') { | |
'pay the money to the shopkeeper'; | |
} else { | |
'recalculate the price of the apples'; | |
'explain the price I have calculated to the shopkeeper and ask him if he agrees'; | |
if('he agrees'){ | |
'pay the money to the shopkeeper'; | |
} else { | |
'take all the apples out of all my bags'; | |
'stop the process of visiting the fruit store'; | |
} | |
} | |
} | |
'the apple purchase process begins'; | |
'Declare a variable `lowestPriceFruitStore`, used to represent the fruit store with the lowest apple prices.'; | |
for(fruitStore of [fruitStroe0, fruitStroe1, fruitStroe2]){ | |
getApplePrice(fruitStore); | |
if('current apple prices in the fruit store' < 'the apple prices of lowestPriceFruitStore'){ | |
'assign the current fruit store to lowestPriceFruitStore' | |
} | |
} | |
buyApples(lowestPriceFruitStore) | |
'the apple purchase process ends'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment