Friday, May 28, 2010

F1 Circuit for Online Games

Now that Street View in map is available, online racing games can use the F1 Circuits.

Flatten the water curvature inside a capillary tube

Apparatus and materials

• Capillary tube
• Trough

Technical notes

Use clean apparatus and water. Wash in strong detergent, rinse in clean water, then in distilled water and take care not to put grease from your fingers on it.

The height of the capillary tube should be greater than the height to which water will rise inside it.

Procedure

a Fill the trough with water and place a capillary tube in it. The water will rise inside the tube, to a height 'h' above the water surface in the cup (diagram a).

b Observe the concave curvature of water inside the capillary tube. The curvature forms an angle, say 'θ', on the inside wall of the capillary tube.

c Now, lower the capillary tube such that the height of the capillary tube above the water surface in the beaker is less than 'h' (diagram b).

d Observe the concave curvature starts reducing and the angle at which the water surface meets the inside wall of the capillary tube is greater than 'θ'.

e When the tube is fully lowered to the surface level of water in the cup you will notice that the water surface flattens (diagram c).

Teaching notes

1 Water rises inside the capillary tube due to adhesion between water molecules and the glass walls of the capillary tube. This adhesion, together with surface tension in the water, produces an effect called 'capillarity', with a characteristic concave surface.

The water rises until the weight of the column equals the vertical component of the forces of adhesion.

The weight W of the water column = π r2 h ρ g
where ρ is the liquid density

θ is the angle of contact between liquid and glass
r is the internal radius of the tube
h is the maximum height of the liquid column
g is the gravitational field strength
γ is the surface tension of the liquid

The vertical supporting forces around the circumference of the liquid surface = γ cos θ x 2 π r

so

π r2h g = 2 π r γ cos θ
and h = 2 γ cos θ /r ρ g

The narrower the tube, the higher the water will rise. Nature uses this effect to carry water up from roots to leaves in plants, including trees.
Capillary action

2 When the tube is lowered so that the water surface inside the tube is at any height less than h, θ becomes larger so that the weight of the water column and the forces of adhesion remain balanced.

When the water surface inside and outside the capillary tube are level, the surface is shaped by surface tension alone.

Mobile App - Shopping Planner

This can be a mobile app capable of loading regular items that we checkout from the retail chains on to our mobiles. We should be able to plan our future buys by adding / removing items from this list using the app and beam the plan back to the retailers.

Benefits:
1. Opens out a new marketing channel for the retailers.
2. Retailers can forecast their sales and stock accordingly.
3. Shoppers can compare the prices of similar goods from other stores.

Personalized Grading at Schools

Percentile grading system compare ones outcome with that of a group and hence the grading cannot be generalized when compared with other groups. Also, it churns only the creamy layers in terms of encouraging to stand out from the rest.

Personalized grading compares ones grading with that of his / her previous numbers. This way one gets motivated by the improvement made each time. Again, the motivation not only happens in creamy layer but across the board and brings in more dynamics.

Mobile devices that take control of laptop while on the move

Mobile enhancements are generally carried out for the core functionality i.e for voice / text / image transactions. This idea aims at adding features to the mobile products apart from its core functionality.

Petty (but more productive) operations can be carried out in ones laptop by using the mobile device as a remote control. Petty activities might be:

* Proactively switching-on the laptop so that user need not wait during the windows start up
* Browsing the slides during a power point presentations
* Viewing contacts stored in the address book without having to take the laptop out

Observer pattern applied: Solving Sudoku, easy ones

This article is intended for audience associated with software development and others who are interested in solving Sudoku (http://en.wikipedia.org/wiki/Sudoku) puzzles with little knowledge about Object Oriented programming. As we know Sudoku can be played at various difficuly levels, here I discuss about solving easy ones and how we can apply observer software pattern for the same. The essence of observer pattern is that one or more objects (called observers or listeners) are registered (or register themselves) to observe an event that may be raised by the observed object (the subject).

We solve Sudoku by following certain routines in our mind. Thus we have to apply handful of patterns to solve each of these routines. I am taking just one of these patterns good enough for solving easy ones and delve in to detail. We all know, we will be given a Sudoku 9x9 array with few cells filled with values 1 to 9. The placement and values of numbers guarantees a unique solution. The puzzle is solved by placing appropriate values in the remaining cells such that the numbers are not repeated vertically, horizontally or within the 9 minor 3x3 arrays.

Routine followed
To start with, each cell can have any value between 1 and 9, inclusive, with equal probability. When each of the given numbers is placed in the corresponding cell, the adjacent cells (horizontally, vertically and within the minor array) loose the opportunity to have this number. This is the crux of the problem that we are discussing. Let’s implement a class to define a cell that holds all possible entries.
public class Cell {

private List values = new ArrayList();
private int row;
private int col;

// Add all possible entries (1 to 9) in each cell
public Cell(int row, int col) {
this.row = row;
this.col = col;
for (int n = 1; n <= 9; n++) {
values.add(new Integer(n));
}
}

}


Placing a number in a cell reduces the array list to have just that number and remove the corresponding entry in the adjacent cells (8 vertically, 8 horizontally and 4 remaining cells in the minor array). As we place more numbers the size of array list in each of the cells gets reduced.

Pattern applied
Having said the routine that we want to follow in order to reduce the possibilities; how can we trigger the adjacent cells such that they respond to placing a number in a particular cell? The answer is to apply observer pattern. Here the observers are adjacent cells. See below code that has the criteria to identify the adjacent cells:
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
boolean isSame = (i == row) && (j == col);
boolean isSameLine = (i == row) || (j == col);
boolean isMinor = (i/3 == row/3) && (j/3 == col/3);
if ( !isSame && (isSameLine || isMinor)) {
// logic to add observers goes here

}
}
}

We need to re-look our definition of a cell as each cell is an observable to the adjacent cells and at the same time an observer of the adjacent cell. Refer below redefined cell class. The super class, observable, has the implementation to notify observers (here it refers to adjacent cells). Update method is the implementation of Observer interface that is called placing a value in a cell. Here we want to remove an entry from the array list.
public class Cell extends Observable implements Observer { 


// add the known value … and notify observers
public void setValue(int value) {

super.notifyObservers(new Integer(value));
}

// Observe and remove the entry set in the observable
public void update(Observable o, Object arg) {
values.remove(arg)

}
}
Class definitions
Let us put together the definition of cell class below:
package my.apps.sudoku;

import java.util.Observable;
import java.util.Observer;
import java.util.ArrayList;
import java.util.List;

public class Cell extends Observable implements Observer {
private List values = new ArrayList();
private boolean isSolved = false;
private int row;
private int col;

// Add all possible entries (1 to 9) in each cell
public Cell(int row, int col) {
this.row = row;
this.col = col;
for (int n = 1; n <= 9; n++) {
values.add(new Integer(n));
}
}

// add cells that are in the same line or same box as observers
public synchronized void addObserver(Cell[][] cells) {
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
boolean isSame = (i == row) && (j == col);
boolean isSameLine = (i == row) || (j == col);
boolean isSecondary = (i/3 == row/3) && (j/3 == col/3);
if ( !isSame && (isSameLine || isSecondary)) {
super.addObserver(cells[i][j]);
}
}
}
}

// add the known value after clearing and notify observers
public void setValue(int value) {
values.clear();
values.add(new Integer(value));
isSolved = true;

super.setChanged();
super.notifyObservers(new Integer(value));
}

// Observe and remove the entry set in the observable
public void update(Observable o, Object arg) {
values.remove(arg);
if (!isSolved && values.size() == 1) {
Integer value = (Integer)values.get(0);
setValue(value.intValue());
}
}

// A cell is solved if the it has just one value
public int getValue() {
if (values.size() == 1) {
return ((Integer)values.get(0)).intValue();
}
return 0;
}
}
Below is the code for creating a collection of cell and setting up the values. It also demonstrates with a sample:
package my.apps.sudoku;

import java.util.Observable;
import java.util.Observer;
import java.util.ArrayList;
import java.util.List;

public class Sudoku {
private Cell [][] cells = new Cell[9][9];

public Sudoku() {

// initialize the cell
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
cells[i][j] = new Cell(i,j);
}
}

// add observers
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
cells[i][j].addObserver(cells);
}
}
}

// set known values
public void setup(int [][] puzzle) {
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
if (puzzle[i][j] != 0) {
cells[i][j].setValue(puzzle[i][j]);
}
}
}
}

public int getCellValue(int i, int j) {
return cells[i][j].getValue();
}

public static void main(String [] args) {

int [][] puzzle = {
{0, 6, 2, 3, 0, 0, 9, 0, 0},
{0, 0, 0, 0, 8, 0, 0, 0, 7},
{8, 0, 0, 0, 0, 5, 0, 0, 4},

{0, 0, 5, 0, 2, 0, 0, 0, 6},
{0, 3, 0, 9, 4, 6, 0, 5, 0},
{4, 0, 0, 0, 5, 0, 7, 0, 0},

{7, 0, 0, 6, 0, 0, 0, 0, 3},
{5, 0, 0, 0, 3, 0, 0, 0, 0},
{0, 0, 3, 0, 0, 7, 8, 9, 0}
};

Sudoku sudoku = new Sudoku();
sudoku.setup(puzzle);
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
System.out.print(sudoku.getCellValue(i, j) + "|");
}
System.out.println();
}
}

Magic Square in 3 easy steps!

1. Form a Square Matrix writing numbers 1 to nxn in sequence. Here n is the order of the Magic Square, say 5.
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25

2. We are trying to identify the final Matrix from the above. Form two matrices, one for identifying the row and another to identify the column.
4 5 1 2 3    3 2 1 5 4
5 1 2 3 4 4 3 2 1 5
1 2 3 4 5 5 4 3 2 1
2 3 4 5 1 1 5 4 3 2
3 4 5 1 2 2 1 5 4 3
You will see the middle column of the first Matrix starts with 1 and are in sequence. Columns on either side can be filled by subtracting and adding 1. The second Matrix is a mirror image.

3. Form the final Matrix by writing the number from initial Matrix in the corresponding row and column. For e.g 4, 3 (Step 2) = 18 (Step 1)
18 22 1 10 14
24 3 7 11 20
5 9 13 17 21
6 15 19 23 2
12 16 25 4 8
The above steps are applicable for any order of the Magic Square!

A Java program to do this:

/*
* Magic Square
*/
int order = 5;
for (int row = 0; row < order; row++) {
for (int col = 0; col < order; col++) {
int rowMatrix = (((order + 1) / 2 + row + col) % order);
int colMatrix = (((order + 1) / 2 + row + order - col - 1) % order) + 1;
System.out.print(((rowMatrix * order) + colMatrix) + "\t")
}
System.out.println();
}

Followers