Skip to content

Instantly share code, notes, and snippets.

@bitfishxyz
Last active May 8, 2020 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitfishxyz/301bca440f50fe34b92909537d1687d1 to your computer and use it in GitHub Desktop.
Save bitfishxyz/301bca440f50fe34b92909537d1687d1 to your computer and use it in GitHub Desktop.
'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]){
'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';
}
if('the fruit store did not have apples'){
'stop the process of visiting the fruit store';
}
if('there is less than one kilogram of red apples left in the fruit shop'){
'stop the process of visiting the fruit store';
}
if('current apple prices in the fruit store' < 'the apple prices of lowestPriceFruitStore'){
'assign the current fruit store to lowestPriceFruitStore'
}
}
'start visiting the `lowestPriceFruitStore`';
'walk to the fruit shop';
while('the apples in this bag weigh less than 1 kilogram'){
'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';
}
}
'complete the purchase process and take away all the apples';
'the apple purchase process ends';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment