Monday, November 18, 2013

An interesting Recursion Problem

While I was refreshing some of my java concepts I came across this site with an interesting problem to be solved using recursion. To brush up i quickly wrote three basic programs, viz, sum to given input, product to given input and value of 2^(given number).

Here's the problem statement:

Write a method that accepts an integer parameter n and returns a string of stars (asterisks) 2n long (i.e., 2 to the nth power).
For example:

CallOutputReason
stringRec(0);"*"20 = 1
stringRec(1);"**"21 = 2
stringRec(2);"****"22 = 4
stringRec(3);"********"23 = 8
stringRec(4);"****************"24 = 16

Here is what I came up with:

private static void stringRec(int i) {
    if (i == -1) {
        System.out.print("*");
    }
    else {
        for (int j = i; j >= 0; j--) {
            stringRec(j - 1);
        }
    }
}

Monday, July 22, 2013

How to install xampp server on ubuntu -12.04

XAMPP is an Acronym for X(to be read as Cross for cross platform), Apache HTTP server, MySQL, PHP and Perl. It is a free open source cross platform web server solution stack package.

From XMAPP version 1.8.2 for linux, the installation process had changed. Previously it was extraction of the tar file to any desired location but now it is by running an executable which pops up a gui window for selecting the components you want to install giving it a windows like feel.

Follow below steps to install XAMPP:
  1. Download the latest version from Apache Friends
  2. Once the download is complete open the terminal and login as root using the command
    su
  3. If this is the first time that you are using the su command then you will have to first set it using the command
    sudo passwd root
  4. Goto the directory in which the installer file was downloaded
  5. Change the permissions to the installer using the command
    chmod 755 xampp-linux-version-installer.run
  6. Run the installer using the command
    ./xampp-linux-version-installer.run
    This will install the xampp server in the /opt/lampp directory
  7. Modify permissions of htdocs folder using the command
    sudo chmod 777 -R /opt/lampp/htdocs/
  8. Start server using command
    sudo /opt/lampp/lampp start
  9. To test if the server is installed type localhost in the browser, the xampp welcome page must be displayed.
The various start-stop parameters of lampp are:

ParameterFunctionality
startStart XAMPP (Apache, MySQL and eventually others)
startapacheStart only Apache
startmysqlStart only MySQL
startftpStart only ProFTPD
startwebminStart only Webmin
stopStop XAMPP (Apache, MySQL and eventually others)
stopapacheStop only Apache
stopmysqlStop only MySQL
stopftpStop only ProFTPD
stopwebminStop only Webmin
reloadReload XAMPP (Apache, MySQL and eventually others)
reloadapacheReload only Apache
reloadmysqlReload only MySQL
reloadftpReload only ProFTPD
restartStop and start XAMPP
securityCheck XAMPP's security
enablesslEnable SSL support for Apache
disablesslDisable SSL support for Apache
backupMake backup file of your XAMPP config, log and data files
oci8Enable the oci8 extenssion

To uninstall XAMPP use the command
sudo rm -rf /opt/lampp

Wednesday, February 20, 2013

A Humble Return...

This is a difficult one to write for a couple of reasons. Firstly its been ages since I even thought about writing anything and secondly it has been an disappointing few days in terms of the football club I support, Arsenal. Losing out to Blackburn Rovers in the FA Cup and the losing to the German side Bayern Munich 1-3 at home in the Champions League leaving themselves almost no chance to qualify for the quarter finals exiting the competition at this stage for the third season running.

Arsenal had lost just one Champions League match after moving to the Emirates Stadium in the 06-07 season and have lost 2 matches in this very season and both to German opposition. After losing the semi-final of the 08-09 season against Manchester United, we managed to go unbeaten against the best of Europe facing the likes of Barcelona, Real Madrid, AC Milan, Internazionale and Juventus for 19 games. The run came to an end against Schalke on 24th October 2012 in the group stage of the competition.

Overall it has been a poor season so far with a lot of excellent records coming to an end. The loss to Blackburn Rovers in the FA Cup a first home loss in the competition since 1977, ending a run of 35 unbeaten home games. Losing to Bradford who were about 65 places below them on penalties (3-2) in the Capital One Cup was another embarrassment mainly because it was a strong side put to do the job but they never took their chances and 3 players missed their spot kicks.  

The wait for silverware has been too long and it looks like it'll be another year without anything going in the cabinet. For all the past seasons there has been one thing Arsenal have consistently done and that is to finish in the top 4 in the Premiere League which is also looking doubtful this year because of the inconsistent form throughout the season.

Unlike most fans I do not want Arsene to go as he has genuinely done a wonderful job at the club and am in complete support of his self sustaining model for the club and when the UEFA's Fair Play rules are implemented it is going to leave us in a very strong position. The rules which were agreed in principle in 2009  and some part of the rules have been implemented at the start of last season, the major rule regarding player transfers which would have ensured that we hold onto our best players was shelved.

I sincerely  hope that Arsene will not lose faith in the players he has because they indeed are a skillful and strong group, unfortunately all most all of them have gone through carer threatening injuries and are taking time to regain their confidence back. Also I hope that the team are going to pull themselves up and repay the faith their manager has in them with quality performances. I see a bright future for Arsenal with the current bunch of youngsters, hopefully they will realise their potential and return Arsenal and Arsene to their Glorious days.

Monday, June 15, 2009

Did India Crumble under "Pressure" or were they just "Tactically Outsmartened ?"

Well I never thought that the Indian team would not even be able to make it through to the semi-finals of the second edition of the T20 Worldcup! What surprised me most were the tactics that the Indian thinktank came up with. To start it all they replaced an opening batsman(V. Sehwag) with a middle order wicket keeper batsman ( D. Karthik), then they made a very good middle order batsman(R. Sharma) open the innings even though he failed to give a good start to the team throughout the practise matches and the group stages. This though seems to have been done because there was no other alternative available to the management and probably can be accepted, but one must point out to some of the very baffling decisions that were taken by the skipper(M.S. Dhoni) in the field. For example in the game against the West Indies Irfan Pathan had bowled two very good overs giving away just 9 runs and he strangely was not handed the ball to bowl a third, and was dropped for the next match too. In the game against England RP Singh bowled 3 overs for 13 runs but was not given the ball to complete his quota of overs.

Dhoni has come out and blamed the batsmen for the defending champions for not having qualified even for the semi-finals, but don't the tactics and startegies of the team management also play a part in the champions being "Bounced" out of the competition, in both the super8 matches so far the Indian batsmen were danced to the old tunes of Chin music. Though one must ask the logic behind pushing the best player of short ball in the Indian team(Y. Singh) down the order and making all the players whose weakness is the short one up the order, while the only ball that the Englishmen seem to have in their arsenal, was the short ball.

Can the downfall of the Indian team be blamed on the IPL, where the interaction of the players with overseas players has led to them giving away their weaknesses more easily than previously? Also taking out the the surprise element of the young guns as their entire games is revealed through technology to all competitors! Or does this give the youngsters of India a platform to develop faster than their shortcomings ?

Well, all that the fan of Indian Cricket can do, is to pray that India does not become the England of Football(Soccer), Home to the best league in the world but unable to replicate its success into the success of the National Team.