Archive for the ‘Uncategorized’ Category

New Post in 2 years from same location

Tuesday, August 13th, 2013

Its been so long that I have lost count. All I remember is writing my last post when I was here in San Francisco 2 years back. I am planning to use this blog to Motivate me more and keep track of my goals. I’ll be back. More posts on algorithms and game programming to come soon.

Halfway across the world.

Sunday, July 24th, 2011

After a long time I have some time to update my blog. I am currently in San Francisco. And arriving here just before the weekend have the next 2 days to myself. I like this place so far. SO I will keep updating this post with my experiences here.

So far I am not really impressed by the shopping mall or other modern places. What I really like is the natural beauty of this place. It is absolutely stunning and unspoiled. I will update more later.

Went to Half-moon bay and drove down highway one to santa-cruz. the beaches were awesome. more to come.

Tags:

Simple TRIE implementation

Tuesday, February 8th, 2011

Its been a long time since my last post. But I finally have some free time at least till march begins. Here is a simple implementation of the TRIE Data structure. Its not the compressed TRIE, but the real simple one (using arrays instead of lists). I have done some very simple tests on it. I am more curious to know what is the memory charge for this implementation on a really large DB of words maybe 3,00,000 or so. My next target will be to implement a compressed version of it and see the difference.

Meanwhile feel free to use this copy.

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
26
27
28
29
30
31
32
33
34
35
36
/*
 * Trie.h
 *
 *  Created on: Feb 8, 2011
 *      Author: sameekbanerjee
 */
 
#ifndef TRIE_H_
#define TRIE_H_
 
struct trienode
{
	char value;
	trienode* children[26];
	bool end;
	trienode();
	trienode(char value_);
	virtual ~trienode();
};
/*
 * Really inefficient Implementation of Trie
 * But easy to use and understand
 */
class Trie
{
public:
	Trie();
	virtual ~Trie();
	void addword(const char* word);
	bool search(const char* word);
private:
	bool validate(const char* word);
	trienode root;
};
 
#endif /* TRIE_H_ */

The implementation follows:

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
 * Trie.cpp
 *
 *  Created on: Feb 8, 2011
 *      Author: sameekbanerjee
 */
 
#include "Trie.h"
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cassert>
const unsigned int MAXLEN = 12;
/*
 * Implementation of trienode
 */
trienode::~trienode()
{
	for(int i=0; i<26;i++)
		delete children[i];
}
 
trienode::trienode():value(0),end(false)
{
	std::memset(children,0,sizeof(trienode*) * 26);
}
 
trienode::trienode(char value_):value(value_),end(false)
{
	std::memset(children,0,sizeof(trienode*) * 26);
}
 
/*
 * Implementation of TRIE
 */
Trie::Trie()
{
}
 
Trie::~Trie()
{
}
/*
 * Takes a word and adds it to the dictionary
 */
void Trie::addword(const char *word)
{
	if(!validate(word))
		return;
	const char *p=word;
	trienode *current=&root;
	while(*p)
	{
		char c=tolower(*p);
		unsigned int pos=c-'a';
		assert(pos<26);
		if(current->children[pos]==0)
		{
			current->children[pos]=new trienode(c);
		}
		current=current->children[pos];
		p++;
	}
	current->end=true;
}
/*
 * Take a word and searches in the dictionary
 * Returns true if it exists false otherwise
 */
bool Trie::search(const char *word)
{
	if(!validate(word))
		return false;
	bool flag=true;
	const char *p=word;
	trienode *current=&root;
	while(*p)
	{
		char c=tolower(*p);
		unsigned int pos=c-'a';
		assert (pos<26);
		if(current->children[pos]==0)
		{
			flag = false;
			break;
		}
		current=current->children[pos];
		p++;
	}
	if(flag)
	{
		if(current->end)
			return true;
	}
	return false;
}
 
bool Trie::validate(const char *word)
{
	if(strlen(word)>MAXLEN)
	{
		std::fprintf(stderr,"Maximum length of Word exceeds %d\n",MAXLEN);
		return false;
	}
	const char *p=word;
	while(*p)
	{
		if(!isalpha(*p))
		{
			std::fprintf(stderr,"Words should only contain alphabets\n");
			return false;
		}
		p++;
	}
	return true;
}

Or Download the project here. TRIE

A word of caution: This is only tested on GNU C++ compiler for mac. This should compile on all other GNU versions, but may require minor changes if you try to compile it on Visual studio.

Also I tried the new wp-syntax plug-in. It is supposed to be cool but I don’t see any syntax highlighting, only line numbers. It may be clashing with my theme. I have to dig in to it.

Tags: , , ,

Huffman Coding

Saturday, August 21st, 2010

Just got into coding in DS and Algorithms again. Here is my implementation of the huffman coding in C++. Pretty simple stuff if you make use of STL extensively. There are no comments and the classes are not properly written. If you want to learn more about Huffman Coding, visit here.

Download source code from here huffman.tar.gz.

Tags: , , ,

Overdose of IPL!

Sunday, April 4th, 2010

I just wanted to pitch a crazy idea. I am SICK or IPL. But I hate myself even more because in-spite of my predicament, I am still watching it. Here are are a few things i hate about it. The list may not contain a round number:

  1. Strategic timeout: I mean seriously. I will have a little less problem with it if it was renamed “time to bombard you with commercials while we rake in the moolah”
  2. The between over advertisements: Another reason for my high BP.
  3. The lame commentators: With all the money, can’t you guyz hire some decent commentators. Danny Morrison! Seriously? I thought Sidhu was the limit.
  4. The mongoose Bat: That’s not a bat. I don’t care what the rule book says. I remember when I was a kid, we used to watch Mahabharat. I still remember the scene when Bheem and Duryodhan were fighting with Mongoose bats.
  5. The pathetic fielding: I have seen better fielding in gully cricket.
  6. The Cheer-leaders: I mean, i really don’t have a problem with it. But I would like some Indian faces in them. The foreign beauties[using the term liberally]…Not working for me.
  7. The blue colored uniforms: 5 out of 8 teams wearing blue uniforms. Are we as a nation becoming color-blind?
  8. Sania Mirza hooking up with Shoaib Malik. I know this has nothing to do with IPL. But the news came out during the IPL and it is seriously pissing me off.
  9. The smirk on Mr. Modi’s face.
  10. The fact that from next year, we will have 2 more teams. That means. Its going to suck even more.

Huh! That actually turned out to be a round number. Some personal trivia, People always say that I am a very negative person. And One way to improve myself will be find out positive things about things i don’t like. So in an uncharacteristic way, I am actually going to try some self improvement. Well since I have bad-mouthed the IPL so much, I am going to find some good things about this year’s IPL. So here it goes.

  1. Good entertainment: Gives something to look forward to in my otherwise boring and non-existential life.
  2. Preity Jumping up and down: I have made that my new screen-saver. I think Kings XI are being distracted because of that. I am not complaining.
  3. A little less of SRK: I thought that was never possible.
  4. KKR is not last anymore. Haha. Miracles are possible.
  5. Sachin in awesome form.

I guess that’s it. Self-Improvement takes time. At least I am trying. Until next time.

In Kolkata!!

Wednesday, September 23rd, 2009

Its been a few days since I reached here. And boy, It feels so good. Sometimes its difficult to believe that I missed the heat, humidity, insane crowds, bad roads and incessant rain but its true. As a true calcuttan, I am proud to say that I missed Kolkata more than I realised. Even though I was over the last year had my share of dissapointments with the city of joy [Ironic]. I am willing to overlook all these things as Kolkata will always welcome me with open arms no matter what. Whenever I talk to people about Kolkata, they always try to bring out the flaws. And even though I want them to go away, I have to be true and admit that Kolkata will not be kolkata if all the things with which it annoys everyone goes away. But enough negativity. All people are excited about Pujo. So am I. Wishing everone a SHUBHO SHARODIYA!

And for all the people inclined to read a little more, here is something interesting.

wifi – its bad for ya!

Friday, May 15th, 2009

Readers be warned. This is not an article about the health hazards of wifi. No, I dont know or care about the lasting effects of long term exposure to 2.4 GHz readio waves. So why am i writing this entry? Well I almost became institutionalized because of it. Let me start from the beginning.

Last week I bought a wifi router (EDIMAX). it was cheaper than the D-Link one so i thought what the hell…everybody is getting D-Link. Plus the one i bought was white in color and will match my motif. What a gay thing to do!I will soon regret it.

I came home. Connected it and within 10 mins had setup my home network. Yippie! Everything thing was working fine. Videos from youtube was streaming properly. Downloaded a file about 17 Mb, which took normal time. Then started browsing. I noticed that it was taking a long time to render the pages. Especially those pages which are heavy on the pics. Like the one on the menus etc. Why was this happening? Tried tweaking the settings. changed channel. nothing worked. This kept tormenting me for a week. Like something inside my brain trying to gnaw the inside of my skull. I couldn’t take it anymore. I tried everything. The only option that was left was….that’s right…a “Firmware Upgrade“. However I had put it off since now a days there are a lot of power cuts happening in my area and if the power goes off while the firmware upgrade is happening, I am in deep deep trouble. But now desperation had set in. I was 2 minutes away from taking a stick and pummeling the damn thing.

So I said my prayers….first time in 6 months. And upgraded it in the middle of the night. Viola! It worked. And everything was back to normal in little world of Sameek. And everybody lived happily ever after.

THE END…Or is it?

Tags: , ,

The Straight Dope!

Friday, April 24th, 2009

Found a great site. The Straight Dope. Its great and addictive. Can’t believe some of the posts.

India at 61. My thoughts!! WHAT IS GOING ON IN THIS COUNTRY??

Saturday, August 16th, 2008

india_flag.gifFirst of all a very HAPPY INDEPENDENCE DAY to all my fellow Indians. Today, being a national holiday, I was in home all day. Well, I wanted to go out but I guess nowadays 15th august means…”Terrorists’ Independence Day”. Every body started telling me…”NO way! Don’t go out. Stay indoors. These days are pretty unsafe”. Is this what our freedom fighters gave their lives for? To see their country being mauled by a pack of rabid dogs? This will open up a lot of old wounds, so people shy away from this topic. Its like that elephant in the living room that no one talks about. Good honest people (even though their numbers are shrinking faster than cheetahs) are still going about as if all these communal tensions and religious hatred will magically disappear if we stay quiet. Thats right! Communal and religious hatred is the biggest threat to our country. It is as if one day we will wake up from a long nightmare and realize that all that was just a bad dream and we are living in harmony now. That is just stupid. We have all built a wall around ourselves. By ourselves, I mean our communities. We have also unknowingly stereotyped other groups. “Muslims hate us!” , “Hindus hate us!”, “Bengali’s are selfish”, “Cannot trust a Gujarati”, “People from NorthEast are vulgar”, “South Indians only care about themselves”. I have had the privilege of hearing these things. This gives an Idea that as Indians we don’t really think properly. Somewhere in the line we have lost our way. The only way to tear these bigotries is to talk about it. And be frank.

All I can think of is that Hindus and Muslims are stuck at some point in History. “Kisne danda pehle mara??” (Who hit first?). This is still the main reason behind all the quarrels. Its high time we get over it. What can we do by going back to 1 moment in history? Nothing. Both are to blame. Accept this. Move on. We are here today. Lets make our Mother India proud. Lets not fight anymore. We always fear what we don’t know. Tear down those walls around us. Walls are a bad Idea. They never work and they will all fall one day or tear us apart. Jai Hind!!

Tags: , ,

City Infoline Up Again!

Tuesday, June 17th, 2008

The Ultimate Infoline To Everything Localâ„¢. Visit http://www.cityinfoline.in/

Keept it going Guyz!