## 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

## Lesson Plans – Week of 2018-02-25

#### Lesson Plans – Week of 2018-02-25

• (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-02-25

## Number Conversions from Base 10

I have written a few posts (Post 1, Post 2, & Post 3) concerning various base number systems. In all of these posts, I covered how to convert from a non-decimal base into a decimal base. In other words, I covered how to get INTO base-10. This post is going to cover the inverse (decimal base into non-decimal base).

#### Modulus

We will need to start by reviewing the concept of modulus division. Let’s look at the standard division problem 5/2. We would typically say that the answer is 2.5 and this would be correct.

Now, modulus is simply the remainder of a division problem. Go back to when you were first introduced to division. In Texas, this is typically in 4th grade. Let’s take a look at that division problem of 5/2 again. When you were learning division, you would have said the answer was 2r1. The 1 is the modulus. When we’re writing the problem to just solve modulus, we would write it as 5%2.

#### Mechanics

##### Decimal to Octal

Let’s say that we have the decimal number (base 10) 4,814 and we want to convert it to an octal (base 8).

We will be building the number from right-to-left. The first thing we will do is solve 4,814/8. This equals 601r6. So, our first digit of the solution (starting on the right) is 6.

`6`

Now, we solve 601/8, which equals 75r1. So, our second digit of the solution (floating from right-to-left) is 1.

`16`

Now, we solve 75/8, which equals 9r3. So, our third digit of the solution (floating from right-to-left) is 3.

`316`

Now, we solve 9/8, which equals 1r1. So, out fourth digit of the solution (floating from right-to-left) is 1.

`1316`

Finally, we solve 1/8, which equals 0r1. So, our fifth and final digit of the solution (floating from right-to-left) is 1.

`11316`

So, the decimal number (base 10) 4,814 is equal to the octal (base 8) 11316.

As you can see, this is a bit of a process, but once you know the process, it is very simple. I now want to take a look at going to number systems with more digits than base 10, for example: base 16.

Let’s say that we have the decimal number (base 10) 4,814 and we want to convert it to a HEX (base 16).

We start by solving 4,814/16, which gives us 300r14. Remember, that is number systems with more than 10 digits, we start using letters.

10 = A
11 = B
12 = C
13 = D
14 = E
15 = F

So, the first digit of our solution (building from right-to-left) is E.

`E`

Now, we solve 300/16, which gives us 18r12. So, the second digit of our solutions (building from right-to-left) is C.

`CE`

Now, we solve 18/16, which gives us 1r2. So, the third digit of our solution (building from right-to-left) is 2.

`2CE`

Finally, we solve 1/16, which gives us 0r1. So, the fourth digit of our solution (building from right-to-left) is 1.

`12CE`

So, the decimal number (base 10) 4,814 is equal to the hexadecimal (base 16) 12CE.

## Lesson Plans – Week of 2018-02-18

#### Lesson Plans – Week of 2018-02-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-02-18

## CS2 10-Jan-2018

Stacks vs Arrays

#### TEKS – §126.34 (Computer Science 2):

• c.3 – Research and information fluency. The student locates, analyzes, processes, and organizes data. The student is expected to:
• c.3.D – manipulate data structures using string processing;
• c.3.F – identify and use the structured data type of one-dimensional arrays to traverse, search, modify, insert, and delete data;

#### Lesson Objectives:

1. The student will be able to create and manipulate a stack data structure.
2. The student will be able to create and manipulate a 1-d array structure.

#### Materials Needed:

1. NetBeans
2. stackedData.dat File (queued phone calls)
3. arrayData.dat File (numbered list)

#### Description of Lesson:

Students will create a basic stack of 10 queued phone calls and pull the top item off of the stack. Discussion will focus on the fact that items are read from top to bottom from the data file. As such, items at the bottom of the file are the last ones placed into the stack.

```import java.io.*;
import java.util.*;

public static void main(String[] args) throws IOException{
Scanner numbers = new Scanner( new File("stackedData.dat")); //Accesses the data file.
Stack firstStack = new Stack(); //Constructor to build an empty stack called "firstStack".
while(numbers.hasNextLine()){ //Opening loop that run as long as the file has a nextLine.
firstStack.push(numbers.nextLine()); //Loop executes a push to enter the data from the data file to the stack.
} //Closes the while loop.
System.out.println("Next Call in Queue is " + firstStack.pop()); //Outputs the item on the top of the stack. Item is removed.
}
}```

Students will then create a 1-D array of a set of numbers. They will manipulate that data set as well.

```import java.io.*;
import java.util.*;
import java.util.Arrays;

public class billy {
public static void main(String[] args) throws IOException{
Scanner nmbrs = new Scanner( new File("arrayData.dat"));
int[] myNewArray = new int[10];
int indexNumber = 0;
while (nmbrs.hasNext()){
int numberFromFile = nmbrs.nextInt();
myNewArray[indexNumber] = numberFromFile;
indexNumber++;
}
System.out.println("Unsorted: " + Arrays.toString(myNewArray));
Arrays.sort(myNewArray);
System.out.println("Sorted: " + Arrays.toString(myNewArray));
int subtr = myNewArray[9] - myNewArray[8];
System.out.println(myNewArray[9] + " - " + myNewArray[8] + " = " + subtr);
}
}```

• Daily Grade – Stack (50%) / Array (50%)

## STEAM: Wisdom from the Front Lines

Today, I had the opportunity to attend a professional development entitled STEAM: Wisdom from the Front Lines that was held at Brookhaven College and coordinated by Education Service Center: Region 10.

The training brought together, in a single room, STEAM educators from secondary and higher ed in an Ed Camp formatted one-day conference. While K-12 and higher ed coordinate with each other at the higher levels, they rarely coordinate at the local level. Today was a first for many of us.

We got to hear what higher ed would like in our graduates and they gave us ideas on projects and programs that we could implement to get them there. It was very insightful and helpful.

On a selfish note, I have recruited an additional team to our robotics league from Faith Family Academy in Waxahachie!

## Computer Science 2 S&S

At the conclusion of last school year, I had a curve-ball thrown at me concerning my plans to offer AP Computer Science 2 based upon an adopted AP syllabus when I requested the course authorization. This course would align with the AP Computer Science – A Exam. In addition, the course would count as a Language Other Than English (LOTE) credit for our students.

Well, the State of Texas had other plans on that. According to TEA, Computer Science 2 can count as an AP credit OR a LOTE credit, but NOT both.

As we already have HB-5 students in progress that need CS2 as their second LOTE credit, we have elected to drop the AP designation. However, I am still modeling the course after the AP CS2 curriculum from the adopted syllabus, which will allow the students to be prepared to take the AP Computer Science – A Exam at the conclusion of the year, if they would like.

Here is what I am planning to cover in CS2 this year:

• Weeks 1 – 2
• Computer Systems
• Numerical Representations, Limitations of Finite Representations, Number Bases & Conversions, Hardware, and Programming Languages
• Weeks 3 – 4
• Objects & Primitive Data
• Simple Data Types (int, Boolean, double, char), Variable & Constant Declarations, Assignment & Arithmetic Expressions, Console Output, Primitives vs. Objects, Create Objects with Classes, References, JAVA Library Classes (String, Integer, Double, Math, & Scanner), and Random Numbers
• Weeks 5 – 6
• Conditional Programming Statements
• Software Development Process, Control Flow, Boolean Expressions, Laws, Truth Tables, and Conditional Expressions
• Weeks 7 – 9
• Iterative Statements
• Flow of Control, While, For, Infinite, and Nested Loops, and Algorithm Analysis (Running Time and Execution Counts)
• Weeks 10 – 12
• Writing Classes
• Anatomy of Classes (Constructors & Methods, Declarations of Class, Interface, Instance, variable, Method and Parameter), Method Overloading, Method Decomposition, Object Relationships, Pre & Post Conditions, and Data Abstraction & Encapsulation
• Weeks 13 – 15
• Enhancing Classes
• References, Exceptions, Class Design, == vs equals, Object Parameter Passing, Error Handling, Interfaces & Abstract Classes, JAVA Library Classes (Comparable & List Interfaces) and Identifications of Reusable Components from Existing Code Using Classes and Class Libraries
• Weeks 16
• Fall Semester Exam Review
• Week 17
• Fall Semester Exam
• Week 18 – 21
• 1D/2D Arrays & Searching
• 1-Dimensional & 2-Dimensional Arrays (Creation, Insertions, Deletions, Transversals, & Algorithms), Searching Algorithms & Comparison (Sequential & Binary), and Choosing Appropriate Data Representation & Algorithms
• Weeks 22 – 24
• Lists, Array Lists, Selection & Insertion Sorts
• Lists & Array Lists (Creation, Insertions, Deletions, Transversals, & Algorithms), Sorting Algorithms & Comparison (Selection & Insertions, and Choosing Appropriate Data Representation & Algorithms
• Weeks 25 – 27
• Inheritance
• Inheritance (Subclass, Overriding, Hierarchies, Using Class Members, Polymorphism, & Class Hierarchy Design), Interfaces & Abstract Classes, JAVA Library Classes (Object), Reading & Understanding Class Specifications (is-a vs. has-a), Understanding & Implementing a Given Class Hierarchy, Extending a Given Class with Inheritance, and Applying Functional Decomposition.
• Weeks 28 – 30
• Recursion / Merge & QuickSorts
• Recursive (Thinking, Programming, & Sorting), Flow of Recursive Control, Sorting Algorithms (Merge & Quick), and Comparison With Other Sort Options
• Weeks 31 – 33
• AP Practice Exam and Computer Ethics
• Responsible Use of Computer Systems (Reliability, Privacy, Intellectual Property, Legal Issues, & Social/Ethical Ramifications of Computer Use), and AP Practice Exam
• Week 34
• AP Computer Science – A Exam
• Weeks 35 – 36
• RoboCode
• Cooperative Programming, Research, Reading Code, and Comparing Strategies & Algorithms

## Roster First Glance & Gender Inequality

I now have my first glance at my rosters today in Skyward.

Here is how it looks right now:

• 1st Period – Principles of Applied Engineering
• 16 TOTAL (13 Males / 3 Females)
• 5th Period – Principles of Applied Engineering
• 16 TOTAL (16 Males / 0 Females)
• 2A – Computer Science 1
• 15 TOTAL (13 Males / 2 Females)
• 4A – Computer Science 1
• 12 TOTAL (10 Males / 2 Females)
• 2B – Computer Science 2
• 8 TOTAL (8 Males / 0 Females)
• 3A – Robotics 1
• 19 TOTAL (13 Males / 6 Females)
• 3B – Robotics 1
• 20 TOTAL (17 Males / 3 Females)
• 3A – Robotics 2
• 7 TOTAL (6 Males / 1 Female)
• 3B – Robotics 2
• 5 TOTAL (4 Males / 1 Female)

Converting these to percentages, this means that 9.28% of my Principles of Applied Engineering, 14.81% of my Computer Science 1, 23.08% of my Robotics 1, and 16.67% of my Robotics 2 classes are female.

A study from Jensen and Nutt shows 74% of females have interest in engineering technology ahead of entry to junior high. At conclusion of high school that interested drops to 2%.

Considering setting my 2017/2018 professional goal to be to develop a program that encourages more females into STEM.

According to US Dept of Ed 2015 study, 10.4% of males earned an engineering STEM credit compared to 2% of females.

Proposing 3 All-Girls STEM Camps for 2018:

• Camp 1 – Completed 4th / 5th Grade
• Camp 2 – Completed 6th Grade
• Camp 3 – Completed 7th / 8th Grade

The major groups to support would be camps 1 and 2.