We have a lot to learn about how other countries learn

December 6, 2016 Leave a comment

Take a look at @TheEconomist’s Tweet: https://twitter.com/TheEconomist/status/805955021070331904?s=09

Nested loops: looking for duplicates in arrays

December 1, 2016 Leave a comment

A and B are arrays of integers. Construct code to output all of the values that are in both A and B.

With questions like this, imagine you had to do it manually. Imagine you have two long lists of numbers on paper. How would you find all the values that occur in both lists?

You would probably look at the first number from list A and then scan all the way down list B to see if it’s there. If it was you’d make a note of it. Then you would get the next number from list A and do the same thing.

A computer algorithm will do exactly the same thing.

In pseudocode this is:

loop I from 0 to A.length - 1
  loop J from 0 to B.length - 1
    if A[I] = B[J] then
      output A[I]
    end if
  end loop
end loop

In Java it is:

for (int i = 0; i < a.length; i++) {
  for (int j = 0; j < b.length; j++) {
    if (a[i] == b[j]) {
      System.out.println(a[i]);
    }
  }
}

Towards the end of the semester…

November 29, 2016 Leave a comment
  • You have three lessons to work on and complete your Greenfoot games.
  • We have ICARE next week.
  • Does anyone know what the plan is for the Friday of next week?
  • We will do a peer review on Tuesday of the last week of the semester in which you will play and judge each others’ games according to a set of criteria.

Basic Java Class Structure

November 28, 2016 Leave a comment

Basic knowledge for IB Computer Science is the structure of a Java class. You should be able to create the class, its instance variables, constructor, get and set methods, and a toString() method, without even need to stop and think.

Question:

Create a Point class that has two instance variables x and y, corresponding to its coordinates on the Cartesian plane. Include an appropriate constructor that initialises these variables. Encapsulate the variables and provide a toString() method.

Answer:

public class Point {
   private int x;
   private int y;

   public Point(int x, int y) {
       setX(x);
       setY(y);
   }

   public int getX() {
      return x;
   }

   public int getY() {
      return y;
   }

   public void setX(int x) {
      this.x = x;
   }

   public void setY(int y) {
      this.y = y;
   }

   public String toString() {
      return "(" + x + "," + y +")";
   }
}

Block E Groups for Speed of Sound Experiment

November 14, 2016 Leave a comment

Group 1a
Nicolas, Aspen
Ottiger, Sebastian
Hwang, Do-Sung
Do, Nguyen

Group 1b
Seol, Subin
Hermans, Samuel
Sy, Russel Gabriel
Khoury, Alexander

Group 2a
Radhakrishnan, Harini
Cheon, Sae Joon
Lee, Byeong Cheon
Banwari, Ashwin

Group 2b
Siguion Reyna, Juan Antonio
Bantigue, Manuel Jerico
Halum, Kim Trevor
Hadaway, Katherine

Block D Groups for Speed of Sound Experiment

November 14, 2016 Leave a comment

Group 1a
Liu, Ethan
Oh, Junhyung
Hardin, Nicholas
Crowe, Mackenzie
Zamora, Antonio Manuel

Group 1b
Westfall, Nicole
Theodoropoulos, Konstantino
Bui, Bac Hai
Subramaniam, Abhinav

Group 2a
Phan, Khoa Duy
Gaikwad, Mayuresh
Ahmad, Syed Haroon
Alcantara, Conrado Jose
Reedy, Benjamin

Group 2b
Nam, Khi Hoon
Dy, Patrick Allan
Alvarez, Jaime
Niazi, Mohd. Shahzeb

Hatty Japes

November 7, 2016 Leave a comment

From Oxford University Admissions via Alex Bellos of The Guardian.

Alice, Bob and Charlie are well-known expert logicians; they always tell the truth. They are sat in a row, as illustrated above. In each of the scenarios below, their father puts a red or blue hat on each of their heads. Alice can see Bob’s and Charlie’s hats, but not her own; Bob can see only Charlie’s hat; Charlie can see none of the hats. All three of them are aware of this arrangement.

(i) Their father puts a hat on each of their heads and says: “Each of your hats is either red or blue. At least one of you has a red hat.” Alice then says “I know the colour of my hat.” What colour is each person’s hat?

(ii) Their father puts a new hat on each of their heads and again says: “Each of your hats is either red or blue. At least one of you has a red hat.” Alice then says “I don’t know the colour of my hat.” Bob then says “I don’t know the colour of my hat.” What colour is Charlie’s hat?

(iii) Their father puts a new hat on each of their heads and says: “Each of your hats is either red or blue. At least one of you has a red hat, and at least one of you has a blue hat.” Alice says “I know the colour of my hat.” Bob then says “Mine is red.” What colour is each person’s hat?

(iv) Their father puts a new hat on each of their heads and says: “Each of your hats is either red or blue. At least one of you has a red hat, and at least one of you has a blue hat.” Alice then says “I don’t know the colour of my hat.” Bob then says “My hat is red”. What colour is Charlie’s hat?

(v) Their father puts a new hat on each of their heads and says: “Each of your hats is either red or blue. Two of you who are seated adjacently both have red hats.” Alice then says “I don’t know the colour of my hat.” What colour is Charlie’s hat?