Thursday, October 28, 2010

Binary Addition and Multiplication

void into2() // x 2
{
for(int i=len;i>0;i--) s[i]=s[i-1];
s[0]=0;
len++;
}

bool plus1() // + 1 : returns true on overflow

{
int i=0;
while(i
if(i==len) return true;
for(i=0;i
{
if(s[i]==0){ s[i]=1; break; }
s[i]=0;
}
return false;
}

Wednesday, October 27, 2010

next_permutation in Java

A few TopCoder SRM problems could be solved by using the next permutation function. Since the next_permutation() function is already available in the C++ library it becomes a sort of a disadvantage for the Java coders. Therefore most of the Java coders have this function in their templates. Here is the implementation in java

public static int[] nextperm(int[] vals) {
int i = vals.length-1;
while (true) {
int ii = i;
i--;
if (vals[i] <>
int j = vals.length;
while (vals[i] >= vals[--j]);
int temp = vals[i]; //Swap
vals[i] = vals[j];
vals[j] = temp;
int begin = ii, end = vals.length-1;
while (end>begin) {
int stemp = vals[end]; //Swap
vals[end] = vals[begin];
vals[begin] = stemp;
end--; begin++;
}
return vals;
} else if (vals[i] == vals[0]) {
int begin = 0, end = vals.length-1;
while (end>begin) {
int stemp = vals[end]; //Swap
vals[end] = vals[begin];
vals[begin] = stemp;
end--; begin++;
}
return vals;
}
}
}

Thursday, October 21, 2010

When I was in Bench!

I was in the bench at L&T Infotech during my first year there. And there were times when I felt really desperate and irritated, and that is when beautiful lines came out from my mind. Following is the transcript of a chat that I had with one of my friends -

Gopinath Mani/LNTINFOTECH (3:23 PM) life is running
Aathif Mohammed/LNTINFOTECH (3:24 PM) LIFE IS PAUSED
Gopinath Mani/LNTINFOTECH (3:24 PM) life is stopped n i wanna rewind
Aathif Mohammed/LNTINFOTECH (3:25 PM) life is stopped nd i wanna fast forward!
Gopinath Mani/LNTINFOTECH (3:25 PM) loose stopped then how u'll FF da... baekku
Aathif Mohammed/LNTINFOTECH (3:26 PM) start and fast forward
Gopinath Mani/LNTINFOTECH (3:26 PM) for that u can break that player itself..... lol
Aathif Mohammed/LNTINFOTECH (3:27 PM) the player is already broken..
Aathif Mohammed/LNTINFOTECH (3:27 PM) they're trying to fix it
Gopinath Mani/LNTINFOTECH (3:27 PM) he he he..........
Gopinath Mani/LNTINFOTECH (3:27 PM) life is funny finally
Gopinath Mani/LNTINFOTECH (3:27 PM) :P
Aathif Mohammed/LNTINFOTECH (3:28 PM) life is not funny ..
Gopinath Mani/LNTINFOTECH (3:28 PM) ur life is funny for me da..... so isnt it funny
Aathif Mohammed/LNTINFOTECH (3:28 PM) it is serious but with lots of fun
Gopinath Mani/LNTINFOTECH (3:28 PM) he he he... jus kidding
Aathif Mohammed/LNTINFOTECH (3:28 PM) ya thats not kidding ..
Aathif Mohammed/LNTINFOTECH (3:29 PM) it is true
Gopinath Mani/LNTINFOTECH (3:29 PM) he he he
Aathif Mohammed/LNTINFOTECH (3:29 PM) life is funny..
Gopinath Mani/LNTINFOTECH (3:29 PM) my life for u?
Aathif Mohammed/LNTINFOTECH (3:29 PM) if try not only to make money
Aathif Mohammed/LNTINFOTECH (3:29 PM) and become a coding bunny
Aathif Mohammed/LNTINFOTECH (3:30 PM) life is'nt only coding
Gopinath Mani/LNTINFOTECH (3:30 PM) dai bhai rapper aagitiya da
Aathif Mohammed/LNTINFOTECH (3:30 PM) maybe
Gopinath Mani/LNTINFOTECH (3:31 PM) funny money bunny kalakkara po :)
Aathif Mohammed/LNTINFOTECH (3:31 PM) :)
Aathif Mohammed/LNTINFOTECH (3:31 PM) FAST FORWARD MAMA
Aathif Mohammed/LNTINFOTECH (3:31 PM) FAST FORWARD
Gopinath Mani/LNTINFOTECH (3:31 PM) peelings ah da mama :P
Aathif Mohammed/LNTINFOTECH (3:31 PM) naa
Gopinath Mani/LNTINFOTECH (3:31 PM) :)
Aathif Mohammed/LNTINFOTECH (3:31 PM) i wont feel
Gopinath Mani/LNTINFOTECH (3:32 PM) but im not able to see thae josh in ur messages da :P
Aathif Mohammed/LNTINFOTECH (3:32 PM) okies then here it is
Aathif Mohammed/LNTINFOTECH (3:32 PM) wat is the value of (1 << n)??
Aathif Mohammed/LNTINFOTECH (3:33 PM) if u feel ur life is boring..
Aathif Mohammed/LNTINFOTECH (3:33 PM) then better start coding
Gopinath Mani/LNTINFOTECH (3:33 PM) sorry da bhai... im jus a tester n a small tym coder not a researcher da :P'
Aathif Mohammed/LNTINFOTECH (3:33 PM) cos it'll make ur life interesting
Aathif Mohammed/LNTINFOTECH (3:34 PM) and ull start contesting
Gopinath Mani/LNTINFOTECH (3:34 PM) bhai i think u r angry on some one
Gopinath Mani/LNTINFOTECH (3:34 PM) who is it
Aathif Mohammed/LNTINFOTECH (3:34 PM) naa
Aathif Mohammed/LNTINFOTECH (3:34 PM) if not for coding
Gopinath Mani/LNTINFOTECH (3:34 PM) u mouth is tellin not ur heart
Aathif Mohammed/LNTINFOTECH (3:34 PM) even if iam bad in it
Aathif Mohammed/LNTINFOTECH (3:34 PM) i wud've run away
Aathif Mohammed/LNTINFOTECH (3:34 PM) mama it is time to show-off
Gopinath Mani/LNTINFOTECH (3:35 PM) baga paandi
Gopinath Mani/LNTINFOTECH (3:35 PM) :P
Aathif Mohammed/LNTINFOTECH (3:35 PM) before the lay-off
Gopinath Mani/LNTINFOTECH (3:35 PM) show off wat
Gopinath Mani/LNTINFOTECH (3:35 PM) :)?
Gopinath Mani/LNTINFOTECH (3:35 PM) he he he
Aathif Mohammed/LNTINFOTECH (3:35 PM) from today i've decided
Aathif Mohammed/LNTINFOTECH (3:35 PM) that show-off does'nt hurt
Gopinath Mani/LNTINFOTECH (3:35 PM) is it
Gopinath Mani/LNTINFOTECH (3:36 PM) lets c
Gopinath Mani/LNTINFOTECH (3:36 PM) wat made u to take this decision
Aathif Mohammed/LNTINFOTECH (3:36 PM) so.....
Gopinath Mani/LNTINFOTECH (3:36 PM) wat hap today
Aathif Mohammed/LNTINFOTECH (3:36 PM) nothing
Gopinath Mani/LNTINFOTECH (3:36 PM) who showed off
Aathif Mohammed/LNTINFOTECH (3:36 PM) nobody
Aathif Mohammed/LNTINFOTECH (3:36 PM) nobody show-off
Gopinath Mani/LNTINFOTECH (3:36 PM) then wy this sudden change in u ?
Gopinath Mani/LNTINFOTECH (3:36 PM) :)'
Aathif Mohammed/LNTINFOTECH (3:36 PM) just to show ppl
Aathif Mohammed/LNTINFOTECH (3:36 PM) mama
Gopinath Mani/LNTINFOTECH (3:36 PM) show ppl wat
Gopinath Mani/LNTINFOTECH (3:37 PM) ur talent
Aathif Mohammed/LNTINFOTECH (3:37 PM) mmmm
Gopinath Mani/LNTINFOTECH (3:37 PM) ?
Gopinath Mani/LNTINFOTECH (3:37 PM) wy
Aathif Mohammed/LNTINFOTECH (3:37 PM) broken talent
Gopinath Mani/LNTINFOTECH (3:37 PM) u wanna show ur talent
Gopinath Mani/LNTINFOTECH (3:37 PM) ?
Aathif Mohammed/LNTINFOTECH (3:37 PM) i know my talent=(otherstalent) * .01
Gopinath Mani/LNTINFOTECH (3:37 PM) wy u wanna show ur talent
Gopinath Mani/LNTINFOTECH (3:38 PM) u missed *10000000 this
Aathif Mohammed/LNTINFOTECH (3:38 PM) i want to mak sure
Gopinath Mani/LNTINFOTECH (3:38 PM) make sure wat?
Aathif Mohammed/LNTINFOTECH (3:38 PM) that even if i die
Gopinath Mani/LNTINFOTECH (3:38 PM) die?
Gopinath Mani/LNTINFOTECH (3:38 PM) wat
Gopinath Mani/LNTINFOTECH (3:38 PM) ?
Gopinath Mani/LNTINFOTECH (3:38 PM) wen? die
Gopinath Mani/LNTINFOTECH (3:38 PM) ?
Aathif Mohammed/LNTINFOTECH (3:38 PM) my broken talent remains
Aathif Mohammed/LNTINFOTECH (3:38 PM) mama if u chkd my orkut profile
Gopinath Mani/LNTINFOTECH (3:38 PM) baga:P
Aathif Mohammed/LNTINFOTECH (3:38 PM) u wud've noticed
Gopinath Mani/LNTINFOTECH (3:39 PM) wat
Aathif Mohammed/LNTINFOTECH (3:39 PM) for(int age=0;age<(life.length);++age);
Aathif Mohammed/LNTINFOTECH (3:39 PM) sumtimes the loop may break
Gopinath Mani/LNTINFOTECH (3:39 PM) ya noticed
Aathif Mohammed/LNTINFOTECH (3:39 PM) if an exeption happens
Gopinath Mani/LNTINFOTECH (3:39 PM) bhai
Gopinath Mani/LNTINFOTECH (3:39 PM) baga bhai da
Gopinath Mani/LNTINFOTECH (3:40 PM) nee
Gopinath Mani/LNTINFOTECH (3:40 PM) put try catch n njoi the exceptions da
Aathif Mohammed/LNTINFOTECH (3:40 PM) if another running thread is interrupted
Aathif Mohammed/LNTINFOTECH (3:40 PM) if a running thread is interrupted
Aathif Mohammed/LNTINFOTECH (3:40 PM) the thread dies
Aathif Mohammed/LNTINFOTECH (3:40 PM) giving only a InterruptedException
Aathif Mohammed/LNTINFOTECH (3:41 PM) u can only know y it was interrupted
Aathif Mohammed/LNTINFOTECH (3:41 PM) u cannot restart the thread again
Gopinath Mani/LNTINFOTECH (3:41 PM) u can start a new action with that thrown exception da... :)
Aathif Mohammed/LNTINFOTECH (3:41 PM) bcos the running thread was LIFE
Gopinath Mani/LNTINFOTECH (3:41 PM) there uis something callled second lucky life :)
Aathif Mohammed/LNTINFOTECH (3:42 PM) that is only wen the Exception is anything other than InterruptedException
Aathif Mohammed/LNTINFOTECH (3:43 PM) Another Thread then waits for the dead Thread to recover...
Aathif Mohammed/LNTINFOTECH (3:43 PM) so that it cud continue
Aathif Mohammed/LNTINFOTECH (3:43 PM) but unfortunately it'll never happen
Aathif Mohammed/LNTINFOTECH (3:43 PM) And finally it is killed by some other process
Gopinath Mani/LNTINFOTECH (3:44 PM) bhai...... catching that interupted exception we can start the waiting thread la
Aathif Mohammed/LNTINFOTECH (3:44 PM) no no
Gopinath Mani/LNTINFOTECH (3:44 PM) wy is it so
Aathif Mohammed/LNTINFOTECH (3:44 PM) catch blocks (atleast in India) is used only for debugging
Aathif Mohammed/LNTINFOTECH (3:44 PM) only to see the stacktrace
Aathif Mohammed/LNTINFOTECH (3:44 PM) wat happened
Gopinath Mani/LNTINFOTECH (3:45 PM) u are a developer da researcher da... use it for this purpose :)
Aathif Mohammed/LNTINFOTECH (3:45 PM) why did the Thread of Life Die
Aathif Mohammed/LNTINFOTECH (3:45 PM) But debugging unfortunately is not possible for the Thread of Life
Gopinath Mani/LNTINFOTECH (3:45 PM) going to sleep mode...... willl come active wen awake
Gopinath Mani/LNTINFOTECH (3:45 PM) :)
Aathif Mohammed/LNTINFOTECH (3:45 PM) as it is run only Once
Gopinath Mani/LNTINFOTECH (3:45 PM) bye
Aathif Mohammed/LNTINFOTECH (3:45 PM) heh
Aathif Mohammed/LNTINFOTECH (3:45 PM) copy paste

Monday, August 17, 2009

August 21st 1986

The sound of a baby crying, relief from people all around, and love from the mother of the baby, all this happened on the 21st of August, the year being 1986, the clock had just struck 12:00 they say.The Azan was sounded on the ear of the 'cute' baby, the journey had started.Only Allah knew for how long the baby was going to live, all i could tell you is that the baby is grown up and living a peaceful life with his parents, what'll happen next that again only Allah(SWT) knows.Well i'am not asking you to guess who the baby is, for the baby 'was' me.
It's been a long journey really! 23 years of fun and peace i'd say.I've been blessed with a very peaceful life, Alhamdulillah(All praise be to Allah).I don't want to let all the beans out by telling what my life was all about till date. I've started to believe in this "Life cycle" thing, its mechanical!I was small, i grew up to my teenage, and im at the peak of my youth now. All normal.Nothing new.
I realize that 'Life' is one that has been defined in the Holy Qura'an and thought by Muhammed(PBUH).If one takes up what's been defined and what was taught i would guarantee that life would be really very peaceful.
I pray to Allah(SWT) that i live the life as it has been defined in the Holy Qur'aan.

Tuesday, June 9, 2009

I'm still Alive...

Yeah!I'm alive.My blog was kinda temporarily hibernating because....because?Answers? Ahh.I don't know.Maybe it was because i was into learning some new stuff.(By stuff i always mean Technology).Maybe because there were literally no visitors to the blog(the visitors that did visit were kinda forced to visit, unfortunately they did not re-visit).



Lot's of thing happened around me in this period.Around me - around the world.The Air France tragedy is one of those things which don't want to get off my mind.It was absolutely .... horrific?terrible?Well I don't know how to describe it, but I did try to imagine myself as one of those victims' kin, it is a horrible experience really.I'm sure that many of those would have had imagined their kins 'killed' coming back to them from nowhere. Nobody knows how it happened(at least till date). What we do know is that it crashed into the Atlantic. As I type in here i hear news that the planes tail fin has been found. Anyways I feel for the victims and their kins and hope and pray to Allah(SWT) that nobody ever gets to feel this experience.



While a section of the people of France mourned the victims, exactly a week later a section of them where hailing Federer's Slam.The French Open that had eluded him, was finally conquered by the charming guy from Swiss.He deserved it i think.He is such a humble person, whom many would love to replicate.



And what else?.....Yeah 'me',whatever did happen to me!As for me, nothing new happened. The same old things, TopCoder, office, etc.I've raised my bar in TopCoder.Was the runner up in one of those Test Scenarios competition.I've set a target for myself.What I can say though, is that my mind seems to be slowly shifting towards money,..and that's bad?Yeah, I think it is really bad.I don't want to lose my love towards my faith/religion and programming.

Wednesday, March 18, 2009

Ideas are many..but Incomplete

For a few days now, in fact I would say a few months, a lot of things have come in my mind. And 'things' in my world almost always means Softwares/Applications/Technologies, anything related to computers and programming. But alas! I've never been able to concentrate/work on any of my ideas.


It has always been my dream to work in a development of an application that would be innovative, creative, that would make me think, that would make me feel satisfied, that would really expose my strengths and weakness'.But one thing that I realize is that it is not possible for me to do so in a Indian-based service-based company. Most projects that are outsourced to the Indian IT world does not need the developer to push himself. It does not ask him to think more than what he has learnt. And it does not ask him to do not more than a copy-pate.But fortunately or unfortunately(Allah knows Best) Im now employed in one of those Indian based IT cos.


But this has not stopped me from thinking on different ideas. From the day I completed my training provided at my company where Im employed, lot of thoughts and ideas have crossed my mind. From Islamic applications that could be useful for the Islamic world to applications that could appeal to the general public, there have been may ideas that have crossed my mind. At this point I would like to say that not all(maybe even none), have been truly innovative. Most applications that I've thought were based on what I was trying to learn at that point.In general, just as Im not worried about how many of them would read my posts on this blog, when ideas come to my mind im not worried on how many users would use my application, let alone have a look at it!


A few months after my training I had ideas of building a "Masjid-Finder" application, that would allow people to search mosques located on different parts(of Chennai, and later across other cities).This was actually a good idea, and is still a good idea, if only I could try implementing it! Few days back as I was attracted towards WEB 2.0, RSS Reader was one thing that I thought of building(there are many of this kind, but one simple complete application built by me would make me feel...feel...!)


I stop here.. yes,yes I know that this post is incomplete,..but that's because my ideas are also INCOMPLETE!

Monday, March 9, 2009

Honesty, it still exists ...

Recently I started subscribing to Shariah Compliant group , and I keep receiving message digests from the group everyday. This is a unique group where people get to ask questions related to the shariath, which are answered promptly by the Ulema(Mufti Ebrahim Desai heading the group of Ulema).


Everyday I get to read questions that really stun me! I really did not think that people, in this modern world, would have such high Taqwa(fear of Allah). Most of these questions that are posted are related to business, riba(interest), zakath,.etc. I have come across a few questions(many, as a matter of fact), that I wouldn't have even bothered to think if it was right, leave alone clarifying with the Ulema. A few minutes back I received a question which has been answered by Moulana Abrar Mirza(a student of Mufti Ebrahim Desai). The question really stunned me. I'm really surprised that such honest people still exist in this world, really! May Allah make a honest person.I pray to Allah from the bottom of my heart that I die a honest man!Following is the question that has been posted by the brother followed by the answer from Moulana Abrar -


Question


I have been working in the present company for the past 6 years. This is also my first company after my education. In the Final semester of my M.asters Degree this company has came to our college to recruit the final year students and conducted an examination. I came to know the question paper from my friend of other college, and I was First in the exam. This company had used the same question paper what they used in my friends college before coming to my college. It is common that most of the times , companies use the same question paper in different colleges, and the students tries to find out the question papers from other colleges with the reasons like it could be the same paper or to know the model of the exam. In my case it was the same paper.

All along these 6 years, some where in my heart it was hurting. 6 months before I wrote everything in an email to the CEO of the company . In the email I also wrote that the only reason I am confessing now, with out thinking about the consequences ,is that I have to face God Almighty, even if I escape here.

I got a replay saying to meet him , when I have a chance. So I met him, he just asked how I came to know the question paper and other things, but he did said any other thing. Infront of him I treid to apologize verbally, but I could not able to do.

While writing the email with emotions I also mentioned that , I got 3 awards from the company for good work in this 5 year span , and also I was 2nd in the class, but later ,I realised that I was 4th or 5th in the class. It was a mistake but not my intention which I have not discussed again with CEO.

Now My question is a) Is what I am earning is Halal b) If I change to another company with current position and experience will it be still Halal c) what else I can do to earn in a halal way


Answer



In the name of Allah, Most Gracious, Most Merciful

Assalaamu `alaykum waRahmatullahi Wabarakatuh

At the outset, we commend you on your honesty and course of action in this day and age of corporate lies and moral degeneration.

It is known, normal, and accepted for students to prepare for such exams by seeking help from others who might have already taken them. Many times, one can find preparation books for these exams in the library with sample questions. For this reason, companies and examination boards generally have slightly different exam questions each time. Technically, your company should have also had a different exam for your college if they were concerned about students knowing the exact questions. Since they did not do this nor did you go against the normal preparation steps with an intention of cheating, your income is halāl. Furthermore, you even informed the CEO of the company and he did not object to that.

But as a matter of precaution, we advice you to also make tawbah and istighfār.

And Allah knows best

Wassalamu Alaikum

Ml. Abrar Mirza,
Student Darul Iftaa

Checked and Approved by:

Mufti Ebrahim Desai
Darul Iftaa, Madrassah In'aamiyyah


I think i'll be a thousand years behind these people in Jannath, if my current state of imaan is considered! But to reach these heights I need the towfik(grace) of Allah, for without Allah's help & will i'm nothing but a statuette made of mud.