puzzles nerant's profileNerant BlogBlogListsNetwork Tools Help

Nerant Blog

Puzzles To Whet Your Intellectual Appetite

puzzles nerant

There are no categories in use.
No list items have been added yet.

Feed

The owner hasn't specified a feed for this module yet.
This person's network is empty (or maybe they're keeping it private).
November 14

Face Book Puzzle : It's A Small World

After getting busy with software release for last 1 month, I finally got some time to post new problem.

Face Book Puzzle: It's a Small world

Looks a like shortest distance problem.

Best Of luck!

Description:
As a popular engineer, you know many people in your home city. While traveling around town, visiting your friends, you realize it would be really handy to have a program that tells you which of your friends are closest based upon which friend you are currently visiting.

Being an engineer who is interested in writing software that is useful to everyone, you decide to write a general solution to your quandary. Each of your friends lives at a unique latitude and longitude. For the purposes of this program, the world is flat, and the latitude and longitude are for all intents and purposes Cartesian coordinates on a flat plane. For example, in our flat world, lat 45, long -179 is not as close to lat 45, long 179 when compared to lat 45, long 170.

Write a program that takes a single argument on the command line. This argument must be a file name which contains the input data. Your program should output the nearest three other friends for each friend in the list. You are virtually a celebrity and your friend list can be astoundingly huge; your program must have a running time of faster than O(n^2) and be robust and resource efficient.


Input specifications

The input file consists of multiple lines, all of which follow the same format. Each line has three values separated by an amount of white space. The first value is the unique id number of that friend, expressed as an integer. The second value is the latitude of that friend, expressed as a float or integer. The third and last value is the longitude of that friend, expressed as a float or integer. Every friend lives at a unique combination of latitude and longitude (e.g. no two friends will ever share the exact same values). Each line ends with a single new line, except for the last line of the file, which may or may not have a terminating new line.

Example input file:
1  0.0      0.0
2 10.1 -10.1
3 -12.2 12.2
4 38.3 38.3
5 79.99 179.99
You are guaranteed that your program will run against an input file that is well formed, and has at least four lines. You are also guaranteed that your list of friends have unique distances between one another; no two distinct pairs of friends will have the same distance between them.


Output specifications

In the order presented in the input file, output the nearest three friends for each friend. Each line of output should start with the integer id of the friend followed by a single space character, and then the list of three nearest other friend ids followed by a single new line. Even the last line of the output should terminate in a new line. This list should be comma-delimited, with no spaces. The list must be in order of proximity, with the closest of the three being first, and the farthest of the three being last.

Example output:
1 2,3,4
2 1,3,4
3 1,2,4
4 1,2,3
5 4,3,1

October 07

Sudoku

combinationations

How many Sudoku's are there? .... billion?

get an exact answer!



Magic Square

Recreation Mathematics

Got this problem while reading "journal of recreational mathematics".

In a magic square of n cells, the numbers from 1 ... n square are placed such that, that sum of rows, columns , diagonals add up to same number.

example :

for 1x1   =
   1

for 3 x 3  (only solution)

8 1 6   
3 5 7
4 9 2 

Sum of each row / col / diagonal = 15

There are 880 solutions for 4x4 magic square.

Solve the problem and implement it in most efficient way you can think of. I will publish the ideas as they come in.


October 06

8 Queen

Calssic Programming Puzzle.

Given eight queens on a standard 8 x 8 chessboard, how many unique positions-- exclusive of rotations and mirror images-- can those eight queens occupy without attacking each other?
September 30

Bicoloring

Bicoloring : GRAPHS


The four-color theorem states that every planar map can be colored using only four colors in such a way that no region is colored using the same color as a neighbor. After
being open for over 100 years, the theorem was proven in 1976 with the assistance of a computer.

Here you are asked to solve a simpler problem.

Decide whether a given connected graph can be bicolored, i.e., can the vertices be painted red and black such that no two adjacent vertices have the same color. To simplify the problem, you can assume the graph will be connected, undirected, and not contain self-loops (i.e., edges from a vertex to itself).

Input

The input consists of several test cases. Each test case starts with a line containing the number of vertices n, where 1 < n < 200. Each vertex is labeled by a number from 0
to n-1. The second line contains the number of edges l. After this, l lines follow, each containing two vertex numbers specifying an edge.
An input with n = 0 marks the end of the input and is not to be processed.

Output

Decide whether the input graph can be bicolored, and print the result as shown below.

Sample Input
3
3
0 1
1 2
2 0
9
8
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0

Sample Output
NOT BICOLORABLE.
BICOLORABLE.