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]) + ")")