Close
-->

Heuristic algorithm for the Traveling Salesman Problem

Problem Statement:

A salesman must visit n cities, passing through each city only once,beginning from one of them which is considered as his base,and returning to it.The cost of the transportation among the cities (whichever combination possible) is given.The program of the journey is requested,that is the order of visiting the cities in such a way that the cost is the minimum.

Pseudo Code:

Input : Number of cities n and array of costs c(i,j) i,j=1,..n (We begin from city number 1)
Output:Vector of cities and total cost.

Download code JavaScript.

-->

Problem Statement:

Dronacharya has set up a task for Arjun. He has an archery range in the form of a
square grid of size N x N. He places K targets at distinct points of the grids. Arjun has a
special ability that he can shoot all targets in a particular row or column with a single
arrow. But this shot is so powerful that the arrow is lost after the shot. Write a program
which will tell Arjun the minimum number of arrows that he must use in order to hit all the targets put in the archery range. Assume that Arjun will use only the specified kind of
shot even if he has to shoot a single target.

Sample Problem:

O represents a target and + represents an empty grid point.
The range is set in the form shown below.
O + O
+ O +
+ O +
For this setting of the range, Arjun can first shoot an arrow across row 1 to destroy the
targets at (1, 1) and (1, 3), and then he can shoot an arrow down column 2 to destroy
the remaining targets. Hence the minimum no of arrows required are 2.

My Solution:

Download the code.
This time I have coded using JavaScript (effect of my project :) )

-->

Mon 7 Jan 2008

The Golden Rectangle

Posted by bash under Algorithm
No Comments 

Given a rectangle having sides in the ratio 1:phi, the golden ratio phi is defined such that partitioning the original rectangle into a square and new rectangle results in a new rectangle having sides with a ratio 1:phi. Such a rectangle is called a golden rectangle.

This featured on SFMC Notice board.

GoldenSpiral

For more reading: http://mathworld.wolfram.com/GoldenRectangle.html

-->
 

Mon 7 Jan 2008

remainder

Posted by vaibhav under Algorithm
No Comments 

find the remainder when 3^2007 is divided by 7

ANS:6

solution: Let N = 3^2007= (3^3)^669 = 27^666 = (28-1)^669

expanding using binomial theorem   N= terms contaaining 28 -1(since 669 is odd)

thus,N =28k-1(k is integer), thus N+7=28k+6

when 28k+6 is divided by 7 remainder=6

thus N+7 gives remainder 6 when divided by 7

hence N gives remainder 6!

-->
 

Mon 7 Jan 2008

Eight odd squares

Posted by bash under Mathematics
[2] Comments 

I was reading through and I found this, really good to think on, simple solution though: 

Lagrange’s Four-Square Theorem states that every positive integer can be written as the sum of at most four squares.  For example, 6 = 22 + 12 + 12 is the sum of three squares.  Given this theorem, prove that any positive multiple of 8 can be written as the sum of eight odd squares.

Reference: http://www.qbyte.org/puzzles/puzzle16.html#p159

-->
 

Thu 16 Aug 2007

Techie at work!

Posted by bash under Algorithm
1 Comment 

This is to inform you that I am currently working with MAQ Software as Software

Development Engineer.

-->
 

Sun 21 Jan 2007

Straight Lines

Posted by goddfather under Mathematics
[3] Comments 

There are ‘n’ straight lines in a plane in a general position. No two parallel and no three concurrent. All of them intersect each other. Find the number of disjoint regions into which the plane is divided by these lines??               For eg: for 3 straight lines the number of disjoint regions is 7.    

Calculate for ‘n’= 64.

-->
 

Sun 21 Jan 2007

Straight Lines

Posted by goddfather under Mathematics
[2] Comments 

There are ‘n’ straight lines in a plane. No two of them are parallel and no three are concurrent. All of them intersect each other. There intersection points are joined in pairs. Find the number of new straight lines that are formed??

Calculate for ‘n’= 64.

-->
 

Wed 17 Jan 2007

Staircase Problem

Posted by goddfather under Mathematics
[3] Comments 

Here is one of the best staircase problems. An elegant solution is expected to this one..

There is a staircase and a person intends to climb it. He can take either one or two steps at a time. In this way, in how many ways can he climb a 12 step staircase??

-->
 

Tue 16 Jan 2007

Magic Square

Posted by bash under Algorithm
[2] Comments 

A magic square is an n x n matrix of the integers 1 to n2 such that the sum of every row, column and diagonal is the same.

Problem Statement: Generate magic square for odd values of n

Download C code

Explanation:
Coxeter has given the following simple rule for generating a magic square when n is odd:
Start with 1 in the middle of the top row; then go up and left, assigning numbers in increasing order to empty squares; if you fall off the square imagine the same square as tiling the plane and continue; if a sqaure is ocupied, move down instead and continue.

-->
 

Next Page »