Saturday, December 26, 2009

In the winter

So this is my first post after a lot of time. Time which changed me beyond anything. But that is talk for another time. For now, I am just enjoying my time in holidays. Yep, I am on holiday. So lets hope I get time to some time to get some pics in here and make this a proper blog.

Friday, July 31, 2009

Template Hell

Man, When I first saw pointers, referencing and de-referencing and all, I thought that I had seen the worst that C++ can throw at you. And now come and greet the new enemy that I found

TEMPLATES!!!

So you think you know what templates do ? Lets see, they are a type of metaprogramming right ? They allow you to use C++ compiler as an interpreter and write generic code with the use of which C++ compiler would generate specific code. So that is what templates does ? Nope. Sorry but I thought so too. But along comes this code snippet which supposedly implements a while loop. Go figure! And when you do please tell me too :D

template
class loop {
private: enum { go = (I-1) != 0 };
public: static inline void f() {
// Whatever needs to go here
loop::f(); }
};

class loop<0> {
public:
static inline void f()
{ }
};

loop::f();

Sunday, July 26, 2009

Jamming On

Well this time around I guess I might have some time to go after the code jam contest. Took some small steps in that way and here is the first result. Think I would use C++ for the contest. I would love to experiment with Python and use some C# or Java for this. I would love the java libraries in the more complex problems. But seems I can make do with C++ this while and this would be a good time as any to get those rusty C++ skills honed in. So here goes nothing. :D

This is my solution for the first practise problem. This is really cool, at least for me and I hope is good and correct C++. No C stdio, no c-strings and bettter still no mallocs. Take a look and see what comes.

/*
* main.cpp
*
* Created on: 27 Jul 2009
* Author: Osada
*/

#include
#include
#include
#include "math.h"

using namespace std;

void process(fstream *input_file, fstream *output_file, int line_no)
{
string num_str;
string source_lang;
string target_lang;
string convert_num_str;
char input_char = '\0';

(*input_file) >> num_str >> source_lang >> target_lang;

cout << "The number string is " <<>
cout <<>
cout <<>

/* Data processing variables set */
long target_lang_dim = target_lang.size();
long source_lang_dim = source_lang.size();
long source_lang_value = 0;
long pos_value = 0;
long convert_residue = 0;

std::reverse(num_str.begin(), num_str.end());
for(int i =0; i <>
{
pos_value = source_lang.find(num_str.at(i), 0);
source_lang_value += pos_value * powl(source_lang_dim, i);
}

convert_residue = source_lang_value;
ldiv_t div_result;
while(convert_residue != 0)
{
div_result = div(convert_residue, target_lang_dim);
convert_residue = div_result.quot;
convert_num_str.push_back(target_lang.at(div_result.rem));
}
std::reverse(convert_num_str.begin(), convert_num_str.end());
(*output_file) << "Case #" <<>
}

int main (int argc, char **argv)
{
/* File input variables */
fstream input_file("A-large-practice.in", fstream::in);
fstream output_file("output.txt", fstream::out);
int no_of_lines = 0;
input_file >> no_of_lines;
for(int i = 0; i
{
process(&input_file, &output_file, (i + 1));
}
input_file.close();
output_file.close();
}


Wednesday, June 24, 2009

Last post at office

Here I am writing my last post from the zone24x7. I wish I could write lots and lots on this post. But I cant. I just cant. It is all blank. And gloom. And Lonely. Maybe I will write something later. May be I miss you all. Love you all.

Monday, February 16, 2009

What can you achieve ?

What can you achieve ? This is a question that you get asked each day. And there is a evasive almost invisible question bubbling in the other person's mind just below the surface. What are you willing to sacrifice for it ? These are not questions with hard and fast answers. No textbook can ever make you understand how to answer these questions. No university can ever teach you this save for Gorki's "My University". No one defines rules for playing this game. So just how do you answer these questions ? Just how do we play this game ? I dont really know. But I am going to find out. By god, I am going to. And I am going to let you know when I do.