Tuesday, December 18, 2012

A program to calculate factorial for big numbers

C++ Program to calculate Factorial for big numbers : One fine day I was trying to get factorial of some number ( >300) and couldn't find it on any tool . Most of the open tools had some limitations, so I decided to write my own program and thought of sharing it :)  Of course this is a program written in less than half an hour or so, hence don't expect it to be most efficient OR wonderfully written wrt language constructs. It did what I wanted at that moment and fulfilled its purpose :)
------------ code starts here -------------

#include < iostream >

#ifndef ARRAY  
#include < vector >
#endif

/*  @author : Manish Baphna < manish.baphna@gmail.com >
 *  @brief  : This program calculates factorial of given number. There are already available tools for that
 *            but most of them have some limitations like upper limit on number (e.g. google online calculator
 *            doesn't calculate factorial for numbers bigger than 170 : type 171! on google and search!! )
 *            This program is just an effort to give better results. Use this @your own risk :)
 *
 *  @warning :I am sharing this program ONLY because I think its better to share it instead of just keeping in
 *            my drive. This code is written in haste and NOT WRITTEN to explain things. So if you are looking
 *            for too many comments and nice formatting, please excuse me. How ever , constrcutive suggestions
 *            are most welcome. BUGS are most most most welcome !
 */

//! This is the main sizing factor here. Using SIZE = 10K , I can find max fact of 3249 ( 10,000 digits ) .
//! If you have bigger number than 3249 then increase SIZE to few ZEROs :) How much, that you have to try and learn
//! If you get glibc error for a number , it means you need bigger SIZE.
#define SIZE 10000

using namespace std  ;

/*!
 * @brief  This is the main function which does all calculation. This function has two implementation , default is
 *         vector based , other is ARRAY based. What essentially is done here is the alternate storage mechanism
 *         for results. For big factorials , int / long are insufficient so this method stores them in a BIG variable
 *         called 'array' which is actually sequence of integers . (Note: ARRAY is compile time switch)
 * @param  N the number for which you want to find factorial
 */
void myfact(int N){
#ifdef ARRAY  
   cout << " \n Array Form \n------------------------------\n" ;
   int array[SIZE] ;
   memset(array,0x0,SIZE) ;
   array[0] = 1 ;
#else
   cout << " \n Vector Form \n------------------------------\n" ;
   vector array(SIZE,0) ; 
   array[0] = 1 ;
#endif
   
   int count = 1 ;
   int xcount = 1 ;
   int temp = 0 , carry = 0 ;
   int num = 2;
   while(num <= N){
      carry = 0 ;
      count = xcount  ;
      for(int i=0; i< count; i++){
         temp = array[i] * num +  carry  ;  
         if(temp>= 10) {
           array[i] = temp % 10 ;
           carry  = temp / 10 ;
           xcount = i+1+1 ;
         }else{
        array[i] = temp ;
        carry = 0;
         }
      }
      while(carry>0){
         array[count++] = carry%10 ;
      carry = carry/10 ;
        if(carry) xcount++ ;
      }
      num++ ;
   }
 
   for(int j=0; j< xcount ; j++){
      cout << array[xcount -1 - j ] ;
   }
   cout << "\n digits required  " << xcount-1 << endl ;
}

int main(int argc, char *argv[]){
if(argc !=2 ){
cout << "pgm " << endl << " e.g. : pgm 200 " << endl ;
exit(1) ;
}
int num = (atoi)(argv[1]) ;
cout << " returning factorial of " << num << endl ;
        myfact(num) ;
   return 1;
}


Wednesday, February 16, 2011

Grievance Registration and Follow Up

Here is some quick info if you have some grievance you want to be addressed

1.
Against any Govt department, state Govt , ministries etc , this is the place
site > http://pgportal.gov.in/
Tips > Ensure while you type in the problem , don't use special characters like *, ? ,#. Infact when you type your problem first time, copy it in some file as well , because if it finds some unacceptable character like ? , * it would reset the form and then you might need to retype again. Instead, start typing in wordpad/notepad and then copy from here to the site form.

2.
Against private brands who are not meeting the commitments or any other similar issues. Note brands can be any company , banks , organizations anything .
site> http://www.ccccore.co.in/

3.
PF issue, like your pf is not transferred to your a/c even all formalities are done
site> http://epfigms.gov.in/
Tips> You need to upload a single PDF of all your proofs/documents required. I have a detailed blog on how I handled my PF transfer issue . You can read it here to know more about the process.
For PF related issue you might also lodge a complain on (1) above against Ministry of Labor , but I have experience (3) myself and this alone is satisfactory. If (3) doesn't work for some reason for you , then you can report to (1) as well.

I will keep adding more details here as and when I find it. If you have some experience then share with me. Don't send me a URL only , unless you or your friend has tried and tested it ( even I can do google and get those URLs :) ).

Tuesday, July 06, 2010

My experiments with PF Transfer Problem

Many of us would (have) face this situation some time which I faced last year. It was PF transfer from one place to another. I am briefing about my experience here , in case some one might get benefited.
What was the case : I shifted from company B Bangalore to another company in Noida called N. Once I joined here in late 2006 , I asked them to transfer my PF a/c from Bangalore to here. ‘N’ has PF a/c with RPFC, Delhi. We started the process. Jan 2007 end I got mail from my ex-employer that my PF money has been sent to RPFC Delhi. Now , I waited for my next PF statement to see if money has really been transferred or not. Year 2007 we didn’t get PF statement , and same with 2008. Financial management firm who manages these affair for ‘N’ ( let’s call them ‘F’ ) said they haven’t got it from RPFC. 2008 end we got statements for 2006-07 and 2007-08 and I was shocked to see my money wasn’t transferred.
I immediately contacted my ex-employer for this, they promptly send me bank proofs that cheque has been en-cashed . Cheque was a/c payee in name of RPFC , Delhi , so there is no way it might have lost and some one else would have taken it. That means , cheque has been encashed but not came to my a/c. From some study I came to know that the process here is like this, they encash the cheque and once that is done , some one has to manually add this figure to your a/c. What If those PF people lose your transfer documents ??? Your money has gone and no one gives you credit !!! That’s what happen to most of the cases . I told ‘F’ to follow on this , July 2009 they started doing this and till 2010 they had almost zero progress , saying again and again “RPFC is like this, they are not doing it , this is govt department and they work like this …..”. At this time I realized , its not gonna to work this way . I should try on my side as well. And all search starts with google  so did here. Found out PF department has a site http://www.epfindia.com/. I found out few emails from there and mailed to them. No response for long. Then I tried this Govt of India , grievance site http://pgportal.gov.in/. I registered and there was few updates like matter is under investigation , gone to Bangalore for further work etc etc, but after few months , no updates . Sent reminders but nothing happened. Then went to Ministry of Labor (RPFC comes under it ) site http://labour.nic.in . There found a grievance email id pglabour@nic.in . Mailed there and promptly got a reply., Only thing that it was bounding mail , saying this eMail doesn’t exist . Great, This is Govt of India Labor Department. Got frustrated , caught another few eMails from site of various secretaries , sent a mail to them telling this bl**** grievance mail id is not working . Few days later , that email id was working. Sent my grievance again there CCing one of the secretary. At the same time couriered all documents to both MoL and RPFC . After few days got a letter from RPFC that they have registered my grievance and gave me a number. Sigh..what a relief , at least they acknowledge my grievance. Around 4 months passed in all this.
Then what happened ?
Well ,then for one of re-re-reminder mails to PF Office I got an automated reply that they have launched a new website for Grievance. I thought let me try this one too. < http://epfigms.gov.in/ > . I posted grievance there. You have to upload relevant documents also , that also in PDF format. I scanned docs ,created a single pdf and did that. I checked status after 2 months , and realized the ticket was closed. I panicked. How come they close it without informing me . But the realized there was another status button . I checked there and to my relief, I came to know they have put final action there. They have realized that money was actually transferred and they added into my account with due interest . ahhh,, what a relief.
Though it was a battle of claiming my own money which was not given to me without any fault of mine , but still, at the end it felt good. Patience and continuous follow up did resulted in my favor.
I also realized in this whole process that every government department does have few good guys , even in most corrupt and inefficient govt offices. These good folks are trying to improve system internally but they can't succeed unless we, common citizen help them . System change requires both internal and external help , so let's do our bit every time whenever possible. Let's learn to complain , follow process , read and understand rules and do give feedback whenever possible in right method. This is certainly one step better than just cribbing about 'corruption and lack of apathy' in govt bodies.

Wednesday, January 06, 2010

Visiting Goa : Some non-trivial information

I assume you have visited few sites already before coming here so I am putting information which I think is non-trivial and not available on other places ,
but is quite useful ,specially if you are having a packed schedule and want to save as much money as possible.

Goa is actually a state and not a city. Its got two districts, North Goa and South Goa. River Mandovi does the bifurcation.
South goa is more for family and leisure kind of place like temples, churches, ancient and historical buildings(Old Goa), museums etc though its got beaches also like Colva ( Kind of beaches in Goa ). Panjim which is capital of Goa is also part of south Goa though its almost at boundary of it.Major casinos of Goa are in Panjim. Main city of south goa is Madgaon which has got railway and bus
stations. If you are reaching Goa by train or bus, mostly you will land to Madgaon .
North Goa is more youth and happenig with beaches like Baga, Chandolim , Calangatge( queen of beaches ). Most of the night clubs are near Baga beach.

Goa Bus Services:
--------------------------
Taxis in Goa are NOT cheap, and in peak season they are quite costly. I was there for xMas and from Colva beach (south goa) if I had to go to Baga beach(north goa), they would charge me minimum 1600 to 1800 Rs. Return fare would be 2000 to 2500 Rs.
Because its ~60 KMs. Easier approach is to take city buses. Few facts about them
1. they operate till 8 pm only.
2. From south goa , you have to go to Madgaon bus Station to catch bus.
3. From north goa , you can catch bus on major roads, near beaches. Ask any shopkeeper/police man there and they would tell you. There are NO dedicated bus stops as such. Just raise your hand and they would stop the bus.
4. There are NO buses directly from North to South goa or Vice versa. You have to go to Panjim and change there.
5. If you are in South Goa , go to Madgaon by Auto/Taxi or Local Bus , go to counter which says NonStop buses to Panjim. Take a ticket and reach Panjim in 30-40 mins .From Panjim , take bus going to Calangate beach , chandolim beach would come on the way. Last stop is Calangate and Baga beach.
6. If you are in North Goa , catch a Bus going to Panjim from the road, reach Panjim bus stop in 20 mins time. From there go counter which says non-stop service tp Madgaon , grab a ticket ( ~22 Rs) and reach Madgaon. From there , ask for local buses at enquiry to go to place of interest.

Buses are cheap and quite fast.

Saturday, July 18, 2009

Movie Time : Newyork

Newyork : I couldn’t get Harry Potter tickets and as we were out in multiplex, we thought of trying Newyork. Another hidden reason to try this movie was that recently me and Shailja were in New york. Movie started with quite fast pace, some good camera moves and Hollywood action movie cuts helped this movie get more attention than we had reserved. And then movie started taking turns. Music was decent, background scores were good. Refreshing change was that there were no forced songs or item numbers or ‘need’ songs. ( Had it been KJ pic, he would have shown us few discs and clubs of NYC by interval for sure with SRK throwins his hands wide.) Till interval movie caught everyone’s attention. Script was nicely woven around turns. After interval, there were high expectations. But climax was total disappointment. Most of Indian movies fail here and this movie too didn’t prove exception. I don’t know but good and technically sound movies like Aks, RDB, Summer 2006 , they all had disaster endings. Its not about negative ending , but its illogical less-sensical ending which I am talking here.
Nevertheless, Kabir Khan deserve applauds for brilliant direction. Camera and scripts were major contributors for the success of this movie. After Kabul Express, this was his second main stream bollywood movie and he generates respect and attention. He in in my ‘to-watch’ directors list. Acting wise John, Irfan and Karina did good job but Neil Nitin Mukesh was the show stealer. He got looks and talent. Overall this movie can be seen in theatre.
This movie is about life of Muslims in US after 9/11 where lots of youth muslims were detained for no-reasons and kept in in-human conditions for long. There were few dialogues which were quite catchy , I liked this one “No one was wrong , its’ the time which was wrong and when time is wrong, people make wrong decisions, countries make wrong decisions.” Alas, people who are at the receiving ends of such wrong decisions are highly traumatized to take essence of this statement so sanely.

Tuesday, January 06, 2009

Jim Corbett !

Some quick tips and infos , description you must have read already , if not google it !
I visited it from Jan 2- Jan 5th ( 2009 )

How to reach there - Catch train from delhi to Ramnagar or go via taxi ( in winter) . When temperature is OK you can also try BUSes.
Good time to visit is from September till April , best time is Sept-Oct OR Feb-March when its pleasant in temperature.

Where to stay :
option1 : Inside jungle , Govt rest houses are there but you need to book 1 months in advance as they are in huge demand.
Also they are quite reasonable in cost as well . Dhikala is the best one. You can book through Uttaranchal tourism office in delhi http://www.kmvn.org/contactus.aspx

option2 : resorts , there are a lot of river side resorts in national park area but they are outside jungle. They are good if you want to relax with food and camp fire along with river views. Feel free to negotiate as much as you want. Typically they offer you price inclusive of all meals. If not , A typical breakfast in such resorts would cost you 150 Rs , lunch 200 Rs and Dinner 300 Rs. Negotiation is allowed and recommended for tarrif.

What to do :
1.Take a safari inside dhikala forest area. There are regualr Govt tours ( private tours are not allowed inside Dhikala). Seats can be booked
in advance from Ramnagar Forest Area Reservation ( near bus stand). First tour starts at 6 in the morning for which booking start at
3 pm of previous day. Next safari is at 11 am for which booking starts at 8 am , same day.
2. Do visit Girja temple. Its very very beautifully located on top of a tall hill which itself is in middle of Koshi river.
3. Adventure activities like river crossing , rappling .
4. Drive around , visit Corbette 'waterfall .
5. Elephant Safari. ( 2000 Rs for 4 people )

Some Tips
1. Take a printout of corbett. A good map is here
http://www.corbett-national-park.com/corbett-map.html#
2. All resorts have their sites , call them upfront for availability and rates.
3. In winter , its too chilly in jungle. Carry thermal wears , they prove very very useful. Cap, Muffler are needed during morning safari
4. Try local buses, They take you around for 5-10 Rs. Autos are bit costly ,Ramnagar Rlyway Station to Dhikuli Area , they will charge you 100-150 Rs.

Sunday, December 07, 2008

Why we don't join politics ..

We have been seeing a lot of well-justified outrage against politicians these days. They have proven themselves less-competent than some of the lowest performing employees of public/private sectors. People want to replace them, but then replace with what? Another ‘lesser‘ less competent politician or some one who is slightly better ? There are not very exciting options here. And why? In India, who joins politics? ‘Most of them’ are left over guys who couldn’t do well in studies like their mates in becoming MBA/Techie or other professional or who gets it in VIRASAT. Yes , quite a lot with hard life and dedication as well , but what percentage ? Probably less than 1 %. India delivers best engineers, managers to the world but not best politicians, why ? When I started thinking about it , I thought of starting from people around me (who are well off in their fields) and asked them why they didn’t join politics.
1. To start with they never never considered politics as a profession or career path.
2. No well wisher/teacher/elder person asked them to go into it.
3. we saw and developed the impression that politics is not for elite-educated people and certainly not for youth. Its either for dirty people or for old generation.
4. Most of the Politicians are gundas/mawalis (goons/thugs).We can't deal with/against them.

Isn’t it irony that politics is perhaps the easiest job one can get into. You need no qualifications, you need no decent background. You just need to start with publicity ( good or bad doesn’t matter … or wait … bad one would help more perhaps).
You are ex-criminal and wanna have change, join politics.
You are corrupt and have taken bribes, still you can be CM and minister.
You lost elections , don't worry, you can still be Minister in central govt as Rajya sabha Member.

No surprise, this has led us to the present situation when country and its security are handled by some of the worst eligible people.


Then what we should so? Simply join the politics?
If I join politics today, most probably I would be no-where in few years unless I get support for people who are ‘like me’ which are already very rare in politics. Probably, to start with , it should be started with political reforms. We need to work to make politics as a ‘career’ or rather ‘profession’. People need to get feeling that they have to have certain qualities to get into it, be it educational or social ones. Strict rules should be enforced to keep anti-social elements out of politics. Politicians should be given high salaries and perks at the same time corruption for them should be trialed against a dedicated stringent law ( like POTA for terrorism ). This would help in creating clean system to right people to stay on. Highlight good work by politicians to increase their visibility and to improve public attitude towards politicians.
One big questions , above and more changes, who’ll do that ?
I think , this is the direction ( one of the directions ) we should channelize our current zeal and anger into, Media, celebrities and Social Groups should drive this for execution. At present I am not able to think of an concrete plan, do you have one for this ?