CSE 121e: Week 03

Ponder and Prove

Introduction

You have two major task groups this week. The first is to rework a few of the functions from last week to deal with zeros. The second is to do calculations relative to an ice cream shop.

Your Tasks

Task Group 1

Last week, there were a few situations that could not be put into the unit tests until you learned how to create and write functions. This week's project has modified unit tests for those functions involving division. You will find those functions and their unit tests in the team_builder.erl file.

  1. Download the shop.zip file. Edit the team_builder.erl file such that you
    1. Re-create the divide/2 function in such a way that it passes its updated unit tests.
    2. Re-create the lower_divide/2 function in such a way that it passes its updated unit tests.
    3. Re-create the remainder/2 function in such a way that it passes its updated unit tests.

Task Group 2

You own an ice cream shop, The Double Dip, that only offers two-scoop cones. Based on previous data collected regarding your customers, to reduce waste and increase profitability, you have decided on having two lists customers can select from.

List one is:

List two is:

Data collected by your staff indicates that Chocolate is your customers’ preferred flavor from list one. To aid you in deciding how to plan your ice cream purchases in future weeks, you need to know all the possible combinations of flavors customers can choose. Customers can select one flavor from list one and one flavor from list two.

Depending on how you design your task solutions, you may need some list BIF's not covered in the reading.

  1. Complete the stubbed-out cone_combinations/2 function in the cone_combination_builder.erl file so it passes all of its unit tests.

    This function should return a list of all possible combinations of list one and list two.

  2. AFTER completing the code for (1) and examining the generated list, you realize your customers might want to combine any flavor in a list with any flavor in either list. In fact they might want a Chocolate-Chocolate cone. That means you will have to change your menu to have a single list with instructions for the customer to “select a flavor for each scoop”.

    Complete the stubbed-out cone_combinations/1 function in cone_builder.erl so it passes all of its unit tests.

  3. You become curious regarding how popular the top 10 cone combinations are. You decide to gather data about the popularity of all of these cone combinations. After having done so, you create a list of 2-tuples. Each 2-tuple consists of the number of purchases of that combination followed by a 2-tuple that consists of the flavors for the top and bottom scoops, {purchase_count,{top_flavor,bottom_flavor}}.

    You decide to print an advertisement extolling the availability of these top 10 cone combinations.

    Complete the stubbed-out most_popular_combinations/1 function in cone_builder.erl so it passes all of its unit tests.

Definitions

Stretch Challenge (Optional)

Find and read several postings online about map, filter, and reduce. Go back to a part of an assignment from a previous class that used loops and lists or arrays. Rewrite that portion of the assignment in Erlang using only map/2, filter/2, and foldl/2. When appropriate, feel free to use mapfoldl/3 or any other function from the lists module. You should also feel free to use list comprehensions.

Review

After completing the previous steps:

  1. Review one of the many possible solutions for this task,
  2. Compare and contrast your code with the possible solutions’ code, and
  3. Make note of any improvements you could make for future tasks.
  4. Make note of what your approach does well.