Ch6 Discussion 04

Learn: scanl.

Find the first 40 partial sums of the sequence 1+1/2+1/3+1/4+… by using scanl.

Exercises

  1. Take in a list [(Float,Bool)] of (gpa, admitted) student data, find all of the pairs where the student was admitted with a gpa of less than 3.0.

  2. Shopping. Given $200 and a list of Int prices of items, find:

    a. How much money remains after buying each item possible, in order from left to right.

    b. A list of how much you have at the start, and then your remaining balance after each item.

    Examples:

     shopA 200 [90,20,60,150,5] == 25
     shopB 200 [90,20,60,150,5] == [200,110,90,30,30,25]
    
  3. Progress Bar. Given a list of integers (download sizes), produce a list of strings of ‘X’ indicating what percent of the total number has been downloaded so far (so cumulative percent). Each X should represent 5 percent of the total amount. Round the percents down to the nearest multiple of five. Begin with “0%” as the first item.

     progressBar [5,8,12,15,10] ==
        ["","XX","XXXXX","XXXXXXXXXX","XXXXXXXXXXXXXXXX","XXXXXXXXXXXXXXXXXXXX"]
    

    In the example above, the total of the numbers is 50. The first number is 5, which is 10% of 50. There should be two X’s because each X represents 5% of the total. The next number is 8. Combining 5 and 8 gives a total of 13, which is 26% of 50. There should be five X’s because when you round 26 down to the nearest multiple of 5, you get 25.

    Another example:

     progressBar [2,3] == ["","XXXXXXXX","XXXXXXXXXXXXXXXXXXXX"]
    
Last modified October 9, 2023: Chapter six reworked, added notes. (14cd5ab)