Wednesday, April 22, 2009

Crayon physics demo - the 2 towers

As if solving the first puzzle was not easy enough, the second puzzle can be solved like below. Just need to draw two boxes. One Box connecting the two towers and another to set the ball rolling.

crayon physics

This seems to be like a tutorial to solving the demo version of crayon physics, but dont limit your creativity to these solutions. Do explore more fun ways to solve these puzzles.

Actually dont just think of these as puzzles, they are a kind of art with purpose. The purpose of the art is to collect the star:) So wat are u waiting for pickup the crayons and start sketching.

Crayon Physics - awesomly talented game

Crayon physics is a really great game that tests your artistic sense and physics. No you dont need to be a particle physicist.

The demo version of the game comes with 7 puzzles and is very simple to learn and fun to play. The aim of the game is to collect stars by making a ball to move towards a star. The first puzzle can be solved easily based on the instructions given in the game background.

crayon physics

This is just one way to solve the game, but the same thing can be solved in innumerable different methods. The beauty of the game is tat its not a science, but an art. We learn handling the mouse, physics and art all at the same time :)

Hit the space bar to reset the game and the esc key to goto the menu. Do let me know if you solve the puzzles in the most artistic ways possible.

Wednesday, April 15, 2009

Robot Battle – the Dead Target Robot

Robot battle is a game that requires you to write programs to make the robots battle it out for supremacy. The robots have the same physical features; the program (the robot brain) is the only feature that decides the winning robot.

A distinct programming language called Robot Scripting language (RSL) is used to control the actions of the robot. The documentation included with the game is good enough to start writing your own robots (.prg files).

I just created a Dead Target Robot for doing target Practice. The Sample program created using the documentation included with the Robot Battle game defeats Dead Target Robot easily.

Source of Deadtarget.prg:

#The dumbest robot ever. Just sits and waits to get killed. Good for target practice.
Init
{
name( "Dead Target" )
author( "Nagarjun V" )
version( "0.1" )
}

Source of Sample.prg:

# Init section sets up robot and registers handlers
Init
{
name( "Sample" )
lockgun( true )
regcore( MyCore )
regdtcrobot( FoundRobot, 1 )
}

MyCore
{
# if scan finds a robot, the event handler runs
scan( )
radarright( 5 )
}

# scan detected a robot, shoot at it then check again
FoundRobot
{
fire( 1 )
scan( )
}

The results of a game between the above two robots:

Name

Points

1st

2nd

Sample

40

20

0

Dead Target 0.1

0

0

20

Sunday, April 12, 2009

Borg - inspired from communists ?

Individuality is defined as the state or quality of being an individual; a person separate from other persons and possessing his or her own needs, goals, and desires. Hence, a persons needs, goals and desires make up his or her individuality.

Individualists consider one’s goals and desire more important than any society, group or institution. While collectivism, stresses that communal, community, group, societal, or national goals should take priority over individual goals. A utopia in which the needs, goals and desires of each individual are same or sacrificed for the good of the society will destroy the concept of an individual. Similarly an interconnected collective like the Borg have no individuality.

The Borg is an extreme case of collectivism. Such an extreme type of Collectivism can be considered a fictional form of communism (which prefers common ownership to private ownership). So was the Borg inspired from communists? Does it play on the American fears of communism prevalent at the time Star Trek was written? The assimilation of cultures and beings can be compared to the growth of communism assimilating countries.

The Borg also resemble Ants in many ways:
Ant colonies also have some fertile males called "drones" and one or more fertile females called "queens".
The colonies are sometimes described as super organisms because ants appear to operate as a unified entity, collectively working together to support the colony

So is the Borg inspired from ants or communists or a combination of both?

Infix to postfix or prefix?

The order of operations or precedence rule is used to determine the order in which operations need to be performed. The order of operations is just a protocol used for easier and common understanding of expressions and is not based on any mathematical or logical theorem. The history of the order of precedence is not very clear and its origins cannot be attributed to any single source. The originator of this rule was not brilliant enough to suggest the post or pre fix notation :)

Various acronyms such as (all of which represent the same order of precedence):
PEMDAS - Parentheses Exponents Multiplication Division Addition Subtraction Also remembered using the sentence - "Please Excuse My Dear Aunt Sally"
BEDMAS - Brackets Exponents Division Multiplication Addition Subtraction
BIDMAS - Brackets Indices Division Multiplication Addition Subtraction
BIMDAS - Brackets Indices Multiplication Division Addition Subtraction
BIODMAS- Brackets Indices Of Division Multiplication Addition Subtraction
BODMAS - Brackets Of Division Multiplication Addition Subtraction
BOMDAS - Brackets Of Multiplication Division Addition Subtraction
BPODMAS- Brackets Power Of Division Multiplication Addition Subtraction

The Microsoft calculator program uses the order of operations in the scientific mode but ignored it in the standard mode. The Google calculator adheres to the order of preference strictly as can be see in the result of 6*3/4^2*3+2*(3/6-4)*3^(2-4).

Humans require the order of operations as we use conventional infix notation. However, the computers use a postfix notation like Reverse Polish notation , which obviates the need for the order of operations. Few computer languages use a prefix notation, which does not require the order of precedence as well. So should humans try to move from the infix to postfix or prefix notation?

Temporary variables – 5 common mistakes

Temporary variables are a type of variable which are used to store a value obtained from a particular computation or data source, which will be used in a later stage of the program. Although temporary variables serve very useful purposes, they can be the cause of major software bugs that seem to occur inexplicably. The common coding or programing mistakes associated with temp variables:

1. Loss of precision: The use of a lesser precision variable for a temp variable can lead to loss of precision which leads to bugs.


Ex: Using a Integer variable to store the result of a calculation that includes a higher precision like float or double. Even in langauages like java by explicitly typecasting(coders mistake).


2. Value out of bound: Similar to the first mistake but occurs in arrays and strings. Can mainly lead to rendering mistakes.


Ex:While using the last few characters of a string or last few values of an array.


3. Multiple inputs: The temporary variable value can get overwritten by incorrect code even before its value is used.


Ex: Status being changed even before the code required to be executed in previous status completes execution.

4. Excessive memory usage:The excessive use of temporary variables can have an impact on the memory usage of the program.


Ex:Using temp variables even when they are not absolutely needed.

5. No exception handling ( Like Null value, negative value) :The temporary variables can behave in weird ways if various exceptional cases are not anticipated and guarded against.

Ex:Not guarding against storing negative values in temp variables later used as array index etc.

Friday, April 3, 2009

Goldilocks - program to check the temperature

import java.io.Console;
import java.io.IOException;

class Goldilocks
{
public static void main(String[] args) throws IOException
{
Console c = System.console();
if (c == null) {
System.err.println("No console.");
System.exit(1);
}
String portemp = c.readLine("Enter the temperature of some porridge in degree centigrade: ");
int temp =(int)Float.parseFloat(portemp);
if (temp>40)
System.out.println("Too hot");
else if(temp<40)
System.out.println("Too cold");
else
System.out.println("just right ");
}
}