Grade Calculator Algorithm Development

My Computer Science 1 classes have spent the past two class periods developing two different algorithms for a “minimum grade calculator” assignment.

Our grades are broken up as follows:

  • Semester 1 (S1) – 50% of Year
    • Quarter 1 (Q1) – 45% of Semester 1
    • Quarter 2 (Q2) – 45% of Semester 1
    • Semester Exam 1 (SE1) – 10% of Semester 1
  • Semester 2 (S2) – 50% of Year
    • Quarter 3 (Q3) – 45% of Semester 2
    • Quarter 4 (Q4) – 45% of Semester 2
    • Semester Exam 2 (SE2) – 10% of Semester 2

The assignment was to develop a program that would let students know the minimum needed grade(s) for the remaining grading periods to pass for both the semester and for the year. As part of this project, the only remaining grades are Q4 and SE2. This is 55% of the semester and 27.5% of the year.

We started by spending two days in algorithm development. The play had been for one day, but you’ll see why it took us two days.

Algorithm – Minimum for Semester

We started with development of a minimum grade for the semester. So, we started with this:

s2 = ( ( q3 * 2 ) + ( q4 * 2 ) + se2 ) / 5

We then condensed it to the following:

s2 = ( ( q3 * 2 ) + ( MIN * 3 ) ) / 5

The “MIN” is the minimum grade that is needed for the 3/5 of the average that is still outstanding. We then moved to isolate the “MIN” variable as follows:

s2 = ( ( q3 * 2 ) + ( MIN * 3 ) ) / 5
( 5 * s2 ) = ( q3 * 2 ) + ( MIN * 3 )
( 5 * s2 ) - ( q3 * 2 ) = MIN * 3
( ( 5 * s2 ) - ( q3 * 2 ) ) / 3 = MIN

We verified the algorithm against an established dataset and it checked.

Algorithm – Minimum for Year (Take 1)

The minimum for the year algorithm was the one that gave us a problem. We got it developed by the end of the first day, but it failed testing. You’ll see why, but we didn’t get a chance to correct it until the next class.

We started with the following:

y = ( s1 + s2 ) / 2

We then expanded it to the following:

y = ( s1 + ( ( ( q3 * 2 ) + ( q4 * 2 ) + se2 ) / 5 ) ) / 2

Like earlier, we consolidated the 6/10 of the year average (3/5 of the semester 2 average) as follows:

y = ( s1 + ( ( ( q3 * 2 ) + ( MIN * 3 ) ) / 5 ) ) / 2

The “MIN” is the minimum grade that is needed for the 3/5 of the semester average that is still outstanding. We then moved to isolate the “MIN” variable as follows: (NOTE: This is where our error occurred).

y = ( s1 + ( ( ( q3 * 2 ) + ( MIN * 3 ) ) / 5 ) ) / 2
2 * y = s1 + ( ( ( q3 * 2 ) + ( MIN * 3 ) ) / 5 )
( 10 * y ) = s1 + ( q3 * 2 ) + ( MIN * 3 )
( 10 * y ) - s1  = ( q3 * 2 ) + ( MIN * 3 )
( 10 * y ) - s1  - ( q3 * 2 ) = ( MIN * 3 ) 
( ( 10 * y ) - s1  - ( q3 * 2 ) ) / 3 = MIN

When we verified this against the dataset, it failed the tests. Regretfully, we ran out of time to correct it, so we had to push the correction to the next class period.

Algorithm – Minimum for Year (Take 2)

We verified the original algorithm once again and determined that it was wrong and would result in a logic error if used.

We analyzed the notes:

y = ( s1 + ( ( ( q3 * 2 ) + ( MIN * 3 ) ) / 5 ) ) / 2
( 2 * y ) = s1 + ( ( ( q3 * 2 ) + ( MIN * 3 ) ) / 5 )
( 10 * y ) = s1 + ( q3 * 2 ) + ( MIN * 3 )
( 10 * y ) - s1  = ( q3 * 2 ) + ( MIN * 3 )
( 10 * y ) - s1  - ( q3 * 2 ) = ( MIN * 3 ) 
( ( 10 * y ) - s1  - ( q3 * 2 ) ) / 3 = MIN

We discovered that the error occurred at line 3. So, we adjusted the algorithm as follows:

y = ( s1 + ( ( ( q3 * 2 ) + ( MIN * 3 ) ) / 5 ) ) / 2
( 2 * y ) = s1 + ( ( ( q3 * 2 ) + ( MIN * 3 ) ) / 5 )
( ( 2 * y ) - s1 ) = ( ( q3 * 2 ) + ( MIN * 3 ) ) / 5
( 5 * ( ( 2 * y ) - s1 ) ) = ( q3 * 2 ) + ( MIN * 3 )
( ( 5 * ( ( 2 * y ) - s1 ) ) - ( q3 * 2 ) ) = MIN * 3
( ( 5 * ( ( 2 * y ) - s1 ) ) - ( q3 * 2 ) ) / 3 = MIN

We verified the algorithm against an established dataset and it checked.

Lesson Plans – Week of 2018-03-18

Lesson Plans – Week of 2018-03-18

  • (1 A/B) Principles of Applied Engineering
  • (2A) Computer Science 1
  • (2B) Computer Science 2
  • (3A) Robotics 1 / Robotics 2 / FTC 11242
  • (3B) Robotics 1 / Robotics 2 / FTC 12645
  • (4A) Computer Science 1
  • (5 A/B) Principles of Applied Engineering

Eric Evans – Planboard Week – 2018-03-18

Q3 Grade Distribution 2017/2018

Today, we are closing the 3Q grading period for the 2017/2018 school year. I have a total of 134 students with 50 of them enrolled in either Robotics 1 or Robotics 2.

Through my career, I have seen many students slip with their grades during this grading cycle. Regretfully, this trend has not abated much this year.

Robotics 1, Robotics 2, and Computer Science 2 have 100% of students passing. But the more curriculum-based courses have failures.

As you can see, Computer Science 1 has an overall failure rate of 13.33% (4 of 30 students). 75% of those failures come from one class period as a result of failure to complete a major multi-part project involving 2-dimensional arrays in Python.

The vast majority of the class (73%) received an A. The majority of those (63%) came from a single class period.

All-in-all, I am happy with the performance of both sections as we had some difficult concepts to cover during this grading period.

As you can see, Principles of Applied Engineering has an overall failure rate of 4.26% (2 of 47 students). The failures are evenly distributed between both sections of this course.

One section comprised 60% of the A’s, 42% of the B’s and 55% of the C’s. The other section was 40%, 58%, and 45% respectively.

This grading period, we covered mechanical, materials, and electrical engineering. Many students struggled with mechanical engineering and their grades reflected those challenges.

Interactive Circuits Lab

Today in PAE, we did an interactive circuits lab. I assigned the students to create 3 different circuits from the PHET Interactive Circuit Construction Kit: DC – Virtual Lab hosted by University of Colorado – Boulder.

Circuit 1 was a simple series circuit consisting of two lights, two batteries, and a switch:

Circuit 2 was a somewhat easy series circuit consisting of one light, three batteries, a switch, and a 120 Ohm resistor:

Circuit 3 was a parallel circuit consisting of three lights, each controlled independently with a switch:

Circuit 4 was a parallel circuit identical to circuit 3, but had a series “master switch” in it:

Circuit 5 was a short circuit with an over-heated power supply:

The students appeared to have fun with the lab and were engaged the entire class time. Thank you UC-Boulder for this nice interactive tool!

Coding Bat Logic Problems – Day 2

Last class we looked at the first of 4 logic problems on Coding Bat in Computer Science 1 ( http://funmultiplies.com/coding-bat-logic-problems-day-1 ). We’re now looking at the last 4 logic problems of that Coding Bat set in CS1 as we get ready to depart for Spring Break.

alarm clock

http://codingbat.com/prob/p119867

Here is the setup of this problem:

Given a day of the week encoded as 0=Sun, 1=Mon, 2=Tue, …6=Sat, and a boolean indicating if we are on vacation, return a string of the form “7:00” indicating when the alarm clock should ring. Weekdays, the alarm should be “7:00” and on the weekend it should be “10:00”. Unless we are on vacation — then on weekdays it should be “10:00” and weekends it should be “off”.

def alarm_clock(day, vacation):
  if (day == 0 or day == 6) and vacation == True:
    return "off"
  elif (day == 0 or day == 6) and vacation == False:
    return "10:00"
  elif (day == 1 or day == 2 or day == 3 or day == 4 or day == 5) and vacation == False:
    return "7:00"
  else:
    return "10:00"

This one is not hard, but just involved with conditional statements. The major things to keep an eye out for are the spelling of the return “off” is all lower-case and the week starts on day 0 with Sunday.

love 6

http://codingbat.com/prob/p100958

Here is the setup for this problem:

The number 6 is a truly great number. Given two int values, a and b, return True if either one is 6. Or if their sum or difference is 6. Note: the function abs(num) computes the absolute value of a number.

def love6(a, b):
  if (a) == 6 or (b) == 6:
    return True
  elif (a) + (b) == 6 or (b) + (a) == 6:
    return True
  elif (a) - (b) == 6 or (b) - (a) == 6:
    return True
  else:
    return False

I personally do not like this problem because of the “Note” at the end. It throws many programmers off. Yes, you can solve this using absolute values, but it’s not necessary.

Once you get other that “distractor”, this is a simple conditional logic problem.

In 1 to 10

http://codingbat.com/prob/p158497

Here is the setup for this problem:

Given a number n, return True if n is in the range 1..10, inclusive. Unless outside_mode is True, in which case return True if the number is less or equal to 1, or greater or equal to 10.

def in1to10(n, outside_mode):
  if outside_mode == False and (n >= 1 and n <= 10):
    return True
  elif outside_mode == True and (n <= 1 or n >= 10):
    return True
  else:
    return False

This is a pretty simple conditional logic problem. If the Boolean flag is False, we are looking for numbers between 1 and 10 (inclusive) and if the Boolean flag is True, we are looking for numbers outside of 1 and 10 (inclusive).

On this particular question, I awarded extra credit if my students could explain mathematically why when the outside_mode Boolean flag is True, the Boolean operator must be OR.

The reason is that while the Boolean flag is False, num is to be between 1 and 10 inclusive. A number can be simultaneously between 1 and 10. As such, the Boolean AND is used in this statement.

Conversely, when the Boolean flag is True, num is to be outside of 1 and 10 inclusive. A number CANNOT be simultaneously less than 1 and greater than 10. As such, the Boolean OR is needed for this statement.

near ten

http://codingbat.com/prob/p165321

Here is the setup for this problem:

Given a non-negative number “num”, return True if num is within 2 of a multiple of 10. Note: (a % b) is the remainder of dividing a by b, so (7 % 5) is 2.

def near_ten(num):
  if num % 10 == 0 or num % 10 == 1 or num % 10 == 2 or num % 10 == 8 or num % 10 == 9:
    return True
  else:
    return False

This particular one needs a little bit of explanation on the algorithm that was used. The general concept is pretty straightforward, but the formula may not be.

Here, we are looking at the modulus of num by 10. In this case, that will always return a 0, 1, or 2 if the number is a multiple of 10, or 1 greater than a multiple of 10, or 2 greater than a multiple of 10 respectively.

On the other side, we will always return an 8 or 9 if the number is 2 less than a multiple of 10, or 1 less than a multiple of 10 respectively.

Beyond the algorithm, the problem is a simple logic conditional program.

Coding Bat Logic Problems – Day 1

Today, we looked at logic problems in Coding Bat in Computer Science 1. Students had to use Boolean logic operators and conditional if/else an if/elif/else statements.

Cigar Party

http://codingbat.com/prob/p195669

Here is the setup of the problem:

When squirrels get together for a party, they like to have cigars. A squirrel party is successful when the number of cigars is between 40 and 60, inclusive. Unless it is the weekend, in which case there is no upper bound on the number of cigars. Return True if the party with the given values is successful, or False otherwise.

def cigar_party(cigars, is_weekend):
  if is_weekend == True and cigars >=40:
    return True
  elif is_weekend == False and cigars >=40 and cigars <=60:
    return True
  else:
    return False

Here, we used the Boolean AND operator to check the number of cigars in relation to the value of is_weekend.

Lines 2 – 3 address if it is a weekend AND are there at least 40 cigars. If so, a TRUE is returned.

Lines 4 – 5 address if is is NOT a weekend AND there are between 40 and 60 cigars. If so, a TRUE is returned.

Lines 6 – 7 address everything else as the default case and return a FALSE.

Date Fashion

http://codingbat.com/prob/p129125

Here is the setup of the problem:

You and your date are trying to get a table at a restaurant. The parameter “you” is the stylishness of your clothes, in the range 0..10, and “date” is the stylishness of your date’s clothes. The result getting the table is encoded as an int value with 0=no, 1=maybe, 2=yes. If either of you is very stylish, 8 or more, then the result is 2 (yes). With the exception that if either of you has style of 2 or less, then the result is 0 (no). Otherwise the result is 1 (maybe).

def date_fashion(you, date):
  if you <=2 or date <=2:
    return 0
  elif you >= 8 or date >= 8:
    return 2
  else:
    return 1

Here, the order of the conditions is EXTREMELY important. Let’s look at the case of you = 9 and date = 1.

In the code above, we would reach the first the first conditional statement with you <=2 is FALSE but date <=2 is TRUE. Since a Boolean OR is being used, only one of them must be true for the associated code to run. So, we return a value of 0 and exit the conditional loop, which is the correct response for the problem.

Now, let’s change the code to the following:

def date_fashion(you, date):
  if you >= 8 or date >= 8:
    return 2
  elif you <=2 or date <=2:
    return 0
  else:
    return 1

All that we have done is swap the conditions between lines 2 and 4 with each other. Let’s examine the case of you = 9 and date = 1 again.

We enter at the first conditional statement with you >= 8 is TRUE but date >= is FALSE. Since a Boolean OR is being used, only one of them must be true for the associated code to run. So, we return a value of 2 and exit the conditional loop, which is the incorrect response for the problem.

The order of our conditional statements is EXTREMELY important!

Squirrel Play

http://codingbat.com/prob/p135815

Here is the setup of the problem:

The squirrels in Palo Alto spend most of the day playing. In particular, they play if the temperature is between 60 and 90 (inclusive). Unless it is summer, then the upper limit is 100 instead of 90. Given an int temperature and a boolean is_summer, return True if the squirrels play and False otherwise.

def squirrel_play(temp, is_summer):
  if is_summer == True and temp >= 60 and temp <= 100:
    return True
  elif is_summer == False and temp >= 60 and temp <= 90:
    return True
  else:
    return False

Lines 2 – 3 check if it is summer. If it is, we then check to see if the temperature is between 60 and 100 degrees inclusive. If it passes all 3 of these tests (Boolean AND), we return the value of TRUE.

Lines 4 – 5 check if it is NOT summer. If it is NOT summer, we then check to see if the temperature is between 60 and 90 degrees inclusive. If it passes all 3 of these tests (Boolean AND), we return the value of TRUE.

Lines 6 -7 are the default case if neither of the above tests can be passed and returns the value of FALSE.

Caught Speeding

http://codingbat.com/prob/p137202

Here is the setup of the problem:

You are driving a little too fast, and a police officer stops you. Write code to compute the result, encoded as an int value: 0=no ticket, 1=small ticket, 2=big ticket. If speed is 60 or less, the result is 0. If speed is between 61 and 80 inclusive, the result is 1. If speed is 81 or more, the result is 2. Unless it is your birthday — on that day, your speed can be 5 higher in all cases.

def caught_speeding(speed, is_birthday):
  if is_birthday == True and speed <= 65:
    return 0
  elif is_birthday == False and speed <= 60:
    return 0
  elif is_birthday == True and speed >= 66 and speed <=85:
    return 1
  elif is_birthday == False and speed >=61 and speed <= 80:
    return 1
  else:
    return 2

Much like the problem before earlier, we a set of Boolean AND statements. When using the Boolean AND we must remember that ALL conditions must be satisfied for the statement to be considered TRUE and to thereby execute the associated instructions.

Lines 2 – 3 and 6 – 7 are working with when is_birthday is TRUE while lines 4 – 5 and 8 – 9 are working with when is_birthday is FALSE. All of these lines are using comparative operators for the speeds.

Working with Resistor Color Bands

Today, in PAE, we did a lab where we were looking at resistor color bands.

With this particular resistor, we have color band 1 is green, color band 2 is violet, color band 3 is red, and color band 4 if silver.

On bands 1 and 2, the colors represent the following:

Color Value
Black 0
Brown 1
Red 2
Orange 3
Yellow 4
Green 5
Blue 6
Violet 7
Gray 8
White 9

The 3rd band represents the multiplier.

Color Value
Black 1
Brown 1 x 101
Red 1 x 102
Orange 1 x 103
Yellow 1 x 104
Green 1 x 105
Blue 1 x 106
Violet 1 x 107
Gold 1 x 10-1
Silver 1 x 10-2

The final band relates to the tolerance.

Color Value
Blank +/- 20%
Silver +/- 10%
Gold +/- 5%

So, the example above would be the following values:

5 , 7 , 1 x 102 , +-/10%

That would be 57 x 1010Ω with a tolerable variance of +/- 10%.

10% of 57 x 1010Ω is 57Ω. So to calculate the total range, we would do the following:

57 x 1010Ω + 57Ω = Upper Range

57 x 1010Ω – 57Ω = Lower Range

So, the resistor in the example would have a total operating range of:

627Ω to 513Ω

Coding Bat Recursive Problems – Day 1

Today, we are looking at a primer for recursion using problems in CodingBat in Computer Science 2. We looked at 3 different problems from CodingBat.

Bunny Ears

http://codingbat.com/prob/p183649

Here is the setup of the problem:

We have a number of bunnies and each bunny has two big floppy ears. We want to compute the total number of ears across all the bunnies recursively (without loops or multiplication).

public int bunnyEars(int bunnies) {
  if (bunnies == 0){
    return 0;
  } else {
    return 2 + bunnyEars(bunnies-1);
  }
}

Let’s use an input of 6. With this, we would anticipate the output to be 12, since each bunny has 2 ears.

Line 3 will not be run since the condition set in line 2 is FALSE. Currently, bunnies is set to 6.

So, we move on to line 4, which is the start of the default case, and is executed on line 5. So with bunnies set to 6, we return a 2 and then add that to the number of bunny ears from the next bunny (bunnies – 1), which is bunny #5.

Now, bunnies = 5, so line 2 is still FALSE, so we run the default case on line 6. We return a 2 and add that to the number of bunny ears from the next bunny (bunnies – 1), which is bunny #4.

Now, bunnies = 4, so line 2 is still FALSE, so we run the default case on line 6. We return a 2 and add that to the number of bunny ears from the next bunny (bunnies – 1), which is bunny #3.

Now, bunnies = 3, so line 2 is still FALSE, so we run the default case on line 6. We return a 2 and add that to the number of bunny ears from the next bunny (bunnies – 1), which is bunny #2.

Now, bunnies = 2, so line 2 is still FALSE, so we run the default case on line 6. We return a 2 and add that to the number of bunny ears from the next bunny (bunnies – 1), which is bunny #1.

Now, bunnies = 1, so line 2 is still FALSE, so we run the default case on line 6. We return a 2 and add that to the number of bunny ears from the next bunny (bunnies – 1), which is 0.

Now, bunnies = 0, so line 2 is now TRUE, so we return a 0 and exit the loop.

We now add the following together:

  • 0 from when bunnies = 0 (cumulative total = 0)
  • 2 from when bunnies = 1 (cumulative total = 2)
  • 2 from when bunnies = 2 (cumulative total = 4)
  • 2 from when bunnies = 3 (cumulative total = 6)
  • 2 from when bunnies = 4 (cumulative total = 8)
  • 2 from when bunnies = 5 (cumulative total = 10)
  • 2 from when bunnies = 6 (cumulative total = 12)

The total is returned as 12 ears.

Bunny Ears 2

http://codingbat.com/prob/p107330

Here is the setup of the problem:

We have bunnies standing in a line, numbered 1, 2, … The odd bunnies (1, 3, ..) have the normal 2 ears. The even bunnies (2, 4, ..) we’ll say have 3 ears, because they each have a raised foot. Recursively return the number of “ears” in the bunny line 1, 2, … n (without loops or multiplication).

public int bunnyEars2(int bunnies) {
  if (bunnies == 0){
    return 0;
  } else if (bunnies % 2 != 0){
    return 2 + bunnyEars2(bunnies-1);
  } else{
    return 3 + bunnyEars2(bunnies-1);
  }
}

For this one, let’s use an input of 5. We would expect the output to be 12 since bunnies 1, 3, & 5 have a total 6 ears and bunnies 2 & 4 have a total of 6 ears.

Line 3 will not be run since the condition set in line 2 is FALSE. Currently, bunnies is set to 5.

So, we move on to line 4. This condition is looking to see if we are working with an even numbered or odd numbered bunny. We have set the condition to use the modulus of 2 of the integer of bunnies. If the modulus is NOT 0, then the statement is TRUE and therefore it is an ODD numbered bunny.

Line 6 is the start of the default case which is used if we are working with an EVEN numbered bunny.

Now, bunnies = 5, so line 2 is FALSE, and line 4 is TRUE. We return a 2 and add that to the number of bunny ears from the next bunny (bunnies – 1), which is bunny #4.

Now, bunnies = 4, so line 2 is FALSE, line 4 is FALSE, so we run the default case at line 6. We return a 3 and add that to the number of bunny ears from the next bunny (bunnies -1), which is bunny #3.

Now, bunnies = 3, so line 2 is FALSE, and line 4 is TRUE. We return a 2 and add that to the number of bunny ears from the next bunny (bunnies – 1), which is bunny #2.

Now, bunnies = 2, so line 2 is FALSE, line 4 is FALSE, so we run the default case at line 6. We return a 3 and add that to the number of bunny ears from the next bunny (bunnies -1), which is bunny #1.

Now, bunnies = 1, so line 2 is FALSE, and line 4 is TRUE. We return a 2 and add that to the number of bunny ears from the next bunny (bunnies – 1), which is 0.

Now, bunnies = 0, so line 2 is now TRUE, so we return a 0 and exit the loop.

We now add the following together:

  • 0 from when bunnies = 0 (cumulative total = 0)
  • 2 from when bunnies = 1 (cumulative total = 2)
  • 3 from when bunnies = 2 (cumulative total = 5)
  • 2 from when bunnies = 3 (cumulative total = 2)
  • 3 from when bunnies = 4 (cumulative total = 10)
  • 2 from when bunnies = 5 (cumulative total = 12)

The total is returned as 12 ears.

Triangle

http://codingbat.com/prob/p194781

Here is the setup of the problem:

We have triangle made of blocks. The topmost row has 1 block, the next row down has 2 blocks, the next row has 3 blocks, and so on. Compute recursively (no loops or multiplication) the total number of blocks in such a triangle with the given number of rows.

public int triangle(int rows) {
 if (rows == 0){
   return 0;
 } else {
   return rows + triangle(rows - 1);
 }
}

Here, we are building something that looks like this:

Like the cases before it, line 2 is a condition looking for when we are to row 0. If line 2 is FALSE, we will move to line 4. For this example, let’s use rows = 4. With this, the output should be 10 as there are 10 cubes needed to complete a 4 row triangle.

So, we start with rows = 4. Line 2 is FALSE, so we move to line 4 to execute line 5, where we return the row number and add it to the number of cubes on the next row (rows – 1), which is row #3.

We are returning the row number as that is equal to the number of cubes of each row (e.g. row 7 = 7 cubes, row 4 = 4 cubes, etc…).

We now move to rows = 3. Line 2 if FALSE, so we move to line 4 to execute line 5, where we return the row number and add it to the number of cubes on the next row (rows – 1), which is row #2.

We now move to rows = 2. Line 2 if FALSE, so we move to line 4 to execute line 5, where we return the row number and add it to the number of cubes on the next row (rows – 1), which is row #1.

We now move to rows = 1. Line 2 if FALSE, so we move to line 4 to execute line 5, where we return the row number and add it to the number of cubes on the next row (rows – 1), which is 0.

Now, rows = 0, so line 2 is now TRUE, so we return a 0 and exit the loop.

We now add the following together:

  • 0 from when rows = 0 (cumulative total = 0)
  • 1 from when rows = 1 (cumulative total = 1)
  • 2 from when rows = 2 (cumulative total = 3)
  • 3 from when rows = 3 (cumulative total = 6)
  • 4 from when rows = 4 (cumulative total = 10)

Lesson Plans – Week of 2018-03-04

Lesson Plans – Week of 2018-03-04

  • (1 A/B) Principles of Applied Engineering
  • (2A) Computer Science 1
  • (2B) Computer Science 2
  • (3A) Robotics 1 / Robotics 2 / FTC 11242
  • (3B) Robotics 1 / Robotics 2 / FTC 12645
  • (4A) Computer Science 1
  • (5 A/B) Principles of Applied Engineering

Eric Evans – Planboard Week – 2018-03-04

Finishing the Matrix

Today, we finished the assignment over a matrix (2-dimensional array) in Python by calculating the ranking points for the teams in the FIRST Tech Challenge El Dorado League of North Texas for the 2017/2018 season.

As you may recall from the previous post titled “Continuing the Matrix“, when there is a tie in the qualifying points, the 3 highest ranking points for each team are summed together to break the tie. The team with the higher sum wins the tie-break.

I am going to remove lines 147 to 157 from last class, which was a test print and am going to replace them with the following to calculate the sum of the 3 highest ranking points.

teams[0][13] = (teams[0][5] + teams[0][7] + teams[0][9] + teams[0][11]) - min(teams[0][5], teams[0][7], teams[0][9], teams[0][11])
teams[1][13] = (teams[1][5] + teams[1][7] + teams[1][9] + teams[1][11]) - min(teams[1][5], teams[1][7], teams[1][9], teams[1][11])
teams[2][13] = (teams[2][5] + teams[2][7] + teams[2][9] + teams[2][11]) - min(teams[2][5], teams[2][7], teams[2][9], teams[2][11])
teams[3][13] = (teams[3][5] + teams[3][7] + teams[3][9] + teams[3][11]) - min(teams[3][5], teams[3][7], teams[3][9], teams[3][11])
teams[4][13] = (teams[4][5] + teams[4][7] + teams[4][9] + teams[4][11]) - min(teams[4][5], teams[4][7], teams[4][9], teams[4][11])
teams[5][13] = (teams[5][5] + teams[5][7] + teams[5][9] + teams[5][11]) - min(teams[5][5], teams[5][7], teams[5][9], teams[5][11])
teams[6][13] = (teams[6][5] + teams[6][7] + teams[6][9] + teams[6][11]) - min(teams[6][5], teams[6][7], teams[6][9], teams[6][11])
teams[7][13] = (teams[7][5] + teams[7][7] + teams[7][9] + teams[7][11]) - min(teams[7][5], teams[7][7], teams[7][9], teams[7][11])
teams[8][13] = (teams[8][5] + teams[8][7] + teams[8][9] + teams[8][11]) - min(teams[8][5], teams[8][7], teams[8][9], teams[8][11])
teams[9][13] = (teams[9][5] + teams[9][7] + teams[9][9] + teams[9][11]) - min(teams[9][5], teams[9][7], teams[9][9], teams[9][11])
teams[10][13] = (teams[10][5] + teams[10][7] + teams[10][9] + teams[10][11]) - min(teams[10][5], teams[10][7], teams[10][9], teams[10][11])

Let’s take a look at what we have going on here by just taking a look at the first line in this code segment:

teams[0][13] = (teams[0][5] + teams[0][7] + teams[0][9] + teams[0][11]) - min(teams[0][5], teams[0][7], teams[0][9], teams[0][11])

As you can see, we start by saying that we are going to populate column with 13 with some data. That data is the value of columns 5, 7, 9, & 11 added together and then the smallest of those values subtracted from that sum.

Remember, only the top 3 scores are used in the calculation and it we add the 4 scores together and then subtract the smallest (min) from that total, we get the data we need.

We now need to display our data.

print(teams[0][0] + " - " + teams[0][1] + " - " + str(teams[0][12]) + " (" + str(teams[0][13]) + ")")
print(teams[1][0] + " - " + teams[1][1]  + " - " + str(teams[1][12]) + " (" + str(teams[1][13]) + ")")
print(teams[2][0] + " - " + teams[2][1]  + " - " + str(teams[2][12]) + " (" + str(teams[2][13]) + ")")
print(teams[3][0] + " - " + teams[3][1]  + " - " + str(teams[3][12]) + " (" + str(teams[3][13]) + ")")
print(teams[4][0] + " - " + teams[4][1]  + " - " + str(teams[4][12]) + " (" + str(teams[4][13]) + ")")
print(teams[5][0] + " - " + teams[5][1]  + " - " + str(teams[5][12]) + " (" + str(teams[5][13]) + ")")
print(teams[6][0] + " - " + teams[6][1]  + " - " + str(teams[6][12]) + " (" + str(teams[6][13]) + ")")
print(teams[7][0] + " - " + teams[7][1]  + " - " + str(teams[7][12]) + " (" + str(teams[7][13]) + ")")
print(teams[8][0] + " - " + teams[8][1]  + " - " + str(teams[8][12]) + " (" + str(teams[8][13]) + ")")
print(teams[9][0] + " - " + teams[9][1]  + " - " + str(teams[9][12]) + " (" + str(teams[9][13]) + ")")
print(teams[10][0] + " - " + teams[10][1]  + " - " + str(teams[10][12]) + " (" + str(teams[10][13]) + ")")

Let’s take a look at what we have going on here by just taking a look at the first line in this code segment:

print(teams[0][0] + " - " + teams[0][1] + " - " + str(teams[0][12]) + " (" + str(teams[0][13]) + ")")

Here, we are displaying a concatenation of the team number from column 0, with a space/hyphen/space, with the team name from column 1, with a space/hyphen/space, with the sum of the qualifying points for the team from column 12, with a space, with the sum of the three highest ranking points in parenthesis from column 13.

The output should look like the following:

Python 3.6.1 (default, Dec 2015, 13:05:11)
[GCC 4.8.2] on linux

127 - The Fighting Pickles - 23 (867)
5443 - Synergy - 18 (737)
9402 - Hive of Steel - 15 (739)
9403 - CyberSwarm - 29 (932)
10143 - Bits & Bots - 14 (763)
11085 - Mad Hackers - 16 (718)
11242 - ERROR 451 - 28 (812)
12645 - S.C.R.E.W. Ups - 19 (874)
12650 - Cannot Compute - 12 (673)
12992 - Vindicators - 6 (316)
13915 - Eagles Robotics - 14 (407)

Following is a complete overview of the code that was created over the 3 days of this lesson:

w = 14 #Width of matrix
h = 11 #Height of matrix
teams = [[0 for x in range(w)] for y in range(h)]
teams[0][0] = "127"
teams[1][0] = "5443"
teams[2][0] = "9402"
teams[3][0] = "9403"
teams[4][0] = "10143"
teams[5][0] = "11085"
teams[6][0] = "11242"
teams[7][0] = "12645"
teams[8][0] = "12650"
teams[9][0] = "12992"
teams[10][0] = "13915"
teams[0][1] = "The Fighting Pickles"
teams[1][1] = "Synergy"
teams[2][1] = "Hive of Steel"
teams[3][1] = "CyberSwarm"
teams[4][1] = "Bits & Bots"
teams[5][1] = "Mad Hackers"
teams[6][1] = "ERROR 451"
teams[7][1] = "S.C.R.E.W. Ups"
teams[8][1] = "Cannot Compute"
teams[9][1] = "Vindicators"
teams[10][1] = "Eagles Robotics"
teams[0][2] = "Ben Barber Innovation Academy"
teams[1][2] = "Harmony School of Innovation"
teams[2][2] = "Henderson Junior High School"
teams[3][2] = "Henderson Junior High School"
teams[4][2] = "Harmony School of Innovation"
teams[5][2] = "Mansfield High School"
teams[6][2] = "Ferris High School"
teams[7][2] = "Ferris High School"
teams[8][2] = "Ferris Junior High School"
teams[9][2] = "Italy High School"
teams[10][2] = "Faith Family Academy"
teams[0][3] = "Mansfield, TX"
teams[1][3] = "Ft. Worth, TX"
teams[2][3] = "Stephenville, TX"
teams[3][3] = "Stephenville, TX"
teams[4][3] = "Ft. Worth, TX"
teams[5][3] = "Mansfield, TX"
teams[6][3] = "Ferris, TX"
teams[7][3] = "Ferris, TX"
teams[8][3] = "Ferris, TX"
teams[9][3] = "Italy, TX"
teams[10][3] = "Waxahachie, TX"
teams[0][4] = 6
teams[1][4] = 0
teams[2][4] = 2
teams[3][4] = 6
teams[4][4] = 6
teams[5][4] = 4
teams[6][4] = 10
teams[7][4] = 6
teams[8][4] = 6
teams[9][4] = 4
teams[10][4] = 0
teams[0][5] = 210
teams[1][5] = 105
teams[2][5] = 132
teams[3][5] = 183
teams[4][5] = 212
teams[5][5] = 184
teams[6][5] = 220
teams[7][5] = 156
teams[8][5] = 160
teams[9][5] = 164
teams[10][5] = 0
teams[0][6] = 6
teams[1][6] = 4
teams[2][6] = 4
teams[3][6] = 10
teams[4][6] = 2
teams[5][6] = 0
teams[6][6] = 6
teams[7][6] = 4
teams[8][6] = 4
teams[9][6] = 0
teams[10][6] = 0
teams[0][7] = 257
teams[1][7] = 257
teams[2][7] = 220
teams[3][7] = 314
teams[4][7] = 205
teams[5][7] = 0
teams[6][7] = 238
teams[7][7] = 277
teams[8][7] = 224
teams[9][7] = 0
teams[10][7] = 0
teams[0][8] = 6
teams[1][8] = 6
teams[2][8] = 6
teams[3][8] = 6
teams[4][8] = 4
teams[5][8] = 6
teams[6][8] = 6
teams[7][8] = 6
teams[8][8] = 0
teams[9][8] = 2
teams[10][8] = 6
teams[0][9] = 188
teams[1][9] = 168
teams[2][9] = 156
teams[3][9] = 218
teams[4][9] = 160
teams[5][9] = 202
teams[6][9] = 244
teams[7][9] = 184
teams[8][9] = 156
teams[9][9] = 152
teams[10][9] = 140
teams[0][10] = 5
teams[1][10] = 8
teams[2][10] = 3
teams[3][10] = 7
teams[4][10] = 2
teams[5][10] = 6
teams[6][10] = 6
teams[7][10] = 3
teams[8][10] = 2
teams[9][10] = 0
teams[10][10] = 8
teams[0][11] = 400
teams[1][11] = 312
teams[2][11] = 363
teams[3][11] = 400
teams[4][11] = 346
teams[5][11] = 332
teams[6][11] = 330
teams[7][11] = 413
teams[8][11] = 289
teams[9][11] = 0
teams[10][11] = 267
teams[0][12] = teams[0][4] + teams[0][6] + teams[0][8] + teams [0][10]
teams[1][12] = teams[1][4] + teams[1][6] + teams[1][8] + teams [1][10]
teams[2][12] = teams[2][4] + teams[2][6] + teams[2][8] + teams [2][10]
teams[3][12] = teams[3][4] + teams[3][6] + teams[3][8] + teams [3][10]
teams[4][12] = teams[4][4] + teams[4][6] + teams[4][8] + teams [4][10]
teams[5][12] = teams[5][4] + teams[5][6] + teams[5][8] + teams [5][10]
teams[6][12] = teams[6][4] + teams[6][6] + teams[6][8] + teams [6][10]
teams[7][12] = teams[7][4] + teams[7][6] + teams[7][8] + teams [7][10]
teams[8][12] = teams[8][4] + teams[8][6] + teams[8][8] + teams [8][10]
teams[9][12] = teams[9][4] + teams[9][6] + teams[9][8] + teams [9][10]
teams[10][12] = teams[10][4] + teams[10][6] + teams[10][8] + teams [10][10]
teams[0][13] = (teams[0][5] + teams[0][7] + teams[0][9] + teams[0][11]) - min(teams[0][5], teams[0][7], teams[0][9], teams[0][11])
teams[1][13] = (teams[1][5] + teams[1][7] + teams[1][9] + teams[1][11]) - min(teams[1][5], teams[1][7], teams[1][9], teams[1][11])
teams[2][13] = (teams[2][5] + teams[2][7] + teams[2][9] + teams[2][11]) - min(teams[2][5], teams[2][7], teams[2][9], teams[2][11])
teams[3][13] = (teams[3][5] + teams[3][7] + teams[3][9] + teams[3][11]) - min(teams[3][5], teams[3][7], teams[3][9], teams[3][11])
teams[4][13] = (teams[4][5] + teams[4][7] + teams[4][9] + teams[4][11]) - min(teams[4][5], teams[4][7], teams[4][9], teams[4][11])
teams[5][13] = (teams[5][5] + teams[5][7] + teams[5][9] + teams[5][11]) - min(teams[5][5], teams[5][7], teams[5][9], teams[5][11])
teams[6][13] = (teams[6][5] + teams[6][7] + teams[6][9] + teams[6][11]) - min(teams[6][5], teams[6][7], teams[6][9], teams[6][11])
teams[7][13] = (teams[7][5] + teams[7][7] + teams[7][9] + teams[7][11]) - min(teams[7][5], teams[7][7], teams[7][9], teams[7][11])
teams[8][13] = (teams[8][5] + teams[8][7] + teams[8][9] + teams[8][11]) - min(teams[8][5], teams[8][7], teams[8][9], teams[8][11])
teams[9][13] = (teams[9][5] + teams[9][7] + teams[9][9] + teams[9][11]) - min(teams[9][5], teams[9][7], teams[9][9], teams[9][11])
teams[10][13] = (teams[10][5] + teams[10][7] + teams[10][9] + teams[10][11]) - min(teams[10][5], teams[10][7], teams[10][9], teams[10][11])
print(teams[0][0] + " - " + teams[0][1] + " - " + str(teams[0][12]) + " (" + str(teams[0][13]) + ")")
print(teams[1][0] + " - " + teams[1][1]  + " - " + str(teams[1][12]) + " (" + str(teams[1][13]) + ")")
print(teams[2][0] + " - " + teams[2][1]  + " - " + str(teams[2][12]) + " (" + str(teams[2][13]) + ")")
print(teams[3][0] + " - " + teams[3][1]  + " - " + str(teams[3][12]) + " (" + str(teams[3][13]) + ")")
print(teams[4][0] + " - " + teams[4][1]  + " - " + str(teams[4][12]) + " (" + str(teams[4][13]) + ")")
print(teams[5][0] + " - " + teams[5][1]  + " - " + str(teams[5][12]) + " (" + str(teams[5][13]) + ")")
print(teams[6][0] + " - " + teams[6][1]  + " - " + str(teams[6][12]) + " (" + str(teams[6][13]) + ")")
print(teams[7][0] + " - " + teams[7][1]  + " - " + str(teams[7][12]) + " (" + str(teams[7][13]) + ")")
print(teams[8][0] + " - " + teams[8][1]  + " - " + str(teams[8][12]) + " (" + str(teams[8][13]) + ")")
print(teams[9][0] + " - " + teams[9][1]  + " - " + str(teams[9][12]) + " (" + str(teams[9][13]) + ")")
print(teams[10][0] + " - " + teams[10][1]  + " - " + str(teams[10][12]) + " (" + str(teams[10][13]) + ")")