Monday, November 26, 2007
Common Sense is not Common
There were once four learned and accomplished men. One day they said to themselves, "Of what use is all our learning if we do not seek the employment of a great king?" Accordingly, they set out for the capital.
Now among these four, three were particularly brilliant. The fourth was far inferior to the others in intellect, but he was the one with the most sense.
On the road, they came upon the skeleton of a lion. "Let us bring this lion back to life," proposed the first. "Yes, this will bring us great fame," agreed the second and third. The fourth one said, "If you bring this lion back to life, he will attack and devour you."
"Don't interrupt!" cried the first, who already used his superior knowledge to put flesh on the bones. The second quickly introduced blood, and the third was about to breathe life into the lion.
"We should think of safety," said the fourth.
"Quiet!" said the third from the depths of his labor.
"Well, then, I shall go sit in this tree," said the fourth. "Just in case."
The lion came back to life and killed the wise men. The only one who survived was the man with common sense.
Courtesy: Link
Now among these four, three were particularly brilliant. The fourth was far inferior to the others in intellect, but he was the one with the most sense.
On the road, they came upon the skeleton of a lion. "Let us bring this lion back to life," proposed the first. "Yes, this will bring us great fame," agreed the second and third. The fourth one said, "If you bring this lion back to life, he will attack and devour you."
"Don't interrupt!" cried the first, who already used his superior knowledge to put flesh on the bones. The second quickly introduced blood, and the third was about to breathe life into the lion.
"We should think of safety," said the fourth.
"Quiet!" said the third from the depths of his labor.
"Well, then, I shall go sit in this tree," said the fourth. "Just in case."
The lion came back to life and killed the wise men. The only one who survived was the man with common sense.
Courtesy: Link
Sunday, November 11, 2007
This Week Quotes
To be alive, to be able to see, to walk,...it's all a miracle.
-- Arthur Rubinstein (1887-1982) Polish Pianist
"The more you praise and celebrate your life, the more there is in life to celebrate."
-- Oprah Winfrey
People call me an optimist, but I'm really an appreciator....When I was six years old and had scarlet fever, the first of the miracle
drugs, sulfanilamide, saved my life. I'm grateful for computers and
photocopiers...I appreciate where we've come from.
-- Julian Simon (1933-1998) American Academic
"At the center of your being you have the answer; you know who you are and you know what you want."
-- Lao Tzu
A prudent man will think more important what fate has conceded to him, than what it has denied.
-- Baltasar Gracian (1601-1658) Spanish Philosopher
"Nothing is worth more than this day. You cannot relive yesterday. Tomorrow is still beyond your reach."
-- Johann Wolfgang Von Goethe
"A real decision is measured by the fact that you've taken a new action. If there's no action, you haven't truly decided."
-- Tony Robbins
-- Arthur Rubinstein (1887-1982) Polish Pianist
"The more you praise and celebrate your life, the more there is in life to celebrate."
-- Oprah Winfrey
People call me an optimist, but I'm really an appreciator....When I was six years old and had scarlet fever, the first of the miracle
drugs, sulfanilamide, saved my life. I'm grateful for computers and
photocopiers...I appreciate where we've come from.
-- Julian Simon (1933-1998) American Academic
"At the center of your being you have the answer; you know who you are and you know what you want."
-- Lao Tzu
A prudent man will think more important what fate has conceded to him, than what it has denied.
-- Baltasar Gracian (1601-1658) Spanish Philosopher
"Nothing is worth more than this day. You cannot relive yesterday. Tomorrow is still beyond your reach."
-- Johann Wolfgang Von Goethe
"A real decision is measured by the fact that you've taken a new action. If there's no action, you haven't truly decided."
-- Tony Robbins
Wednesday, November 07, 2007
Spiral Matrix Program
My Spiral Matrix Program
#include < stdio.h>
#define UP 0
#define LEFT 1
#define DOWN 2
#define RIGHT 3
int getele(int *arr, int x, int y, int size) {
int pos=(x*size)+y;
return arr[pos];
}
int setele(int *arr, int x, int y, int data, int size) {
int pos=(x*size)+y;
arr[pos]=data;
}
void setspiral_worker(int *arr, int x, int y, int data, int size, int dir) {
if(data==1)
setele(arr, x, y, data, size);
else {
setele(arr, x, y, data, size);
dir=check_change_dir(arr, x, y, size, dir);
if (dir == UP) {
x--;
} else if (dir == LEFT) {
y--;
} else if (dir == DOWN) {
x++;
} else if (dir == RIGHT) {
y++;
}
setspiral_worker(arr, x, y, data-1, size, dir);
}
}
void setspiral_driver(int *arr, int size) {
setspiral_worker(arr, size-1, size-1, size*size, size, UP);
}
int check_change_dir(int *arr, int x, int y, int size, int dir) {
if (dir == UP) {
x--;
} else if (dir == LEFT) {
y--;
} else if (dir == DOWN) {
x++;
} else if (dir == RIGHT) {
y++;
}
if (x>=0 && x<=size-1 && y>=0 && y<=size-1
&& getele(arr, x, y, size) == 0)
return dir;
else
return (dir+1)%4;
}
int main() {
int oper=UP;
int size;
int i,j;
int *matrix;
printf("Enter the size:");
scanf("%d", &size);
matrix=malloc(size*size);
for(i=0; i < size ;i++)
for(j=0; j < size;j++)
setele(matrix, i, j, 0, size);
setspiral_driver(matrix, size);
for(i=0; i < size;i++) {
for(j=0; j < size;j++)
printf("%4d\t",getele(matrix, i, j, size));
printf("\n");
}
return 0;
}
Subscribe to:
Posts (Atom)