Implementing Helper Functions
Warming up to Order Some Good Stuff
So you understand Katya’s functions, and have a bit more knowledge of the sharemarket than you might have expected. Now it’s time to start thinking about functions that will be useful in completing makeOrders
!
Now your heuristic is up to you, and should certainl be your own creation. However, there are many functions which could be very useful for a variety of heuristics.
Brainstorming Useful Functions
For each of the following, don’t just write the function- also brainstorm with your peers where this function might be useful, and what kind of heuristic it would be used for.
Write & brainstorm… (single list functions)
- a function that returns the average of a list
- a function that finds the largest element of a list
- a function that finds the smallest element of a list
- a function that finds the difference between the largest and smallest values of a list
Write & brainstorm… (lists of lists)
- For a list of
StockHistory
, return theStock
with the largest average stock price (you might need something to help find the maximum average while using the tuple data type here!) - For a list of
StockHistory
, return theStock
with the smallest difference between the largest and smallest values of a list
Once you feel comfortable with these functions and understand how they could be used, try and code up a heuristic! Then, it’s time for you to go to the NEXT LEVEL. You better head to our advanced heuristics room for that!