The “FizzBuzz” problem

On September 22, 2015, in Code, Javascript, Work - out of office, by sailesh

In the FizzBuzz problem, we are printing a sequence of positive integers up to a limit given, replacing multiples of 3 with “Fizz”, multiples of 5 with “Buzz”, and replacing multiples of both 3 and 5 with “FizzBuzz”.

  • Enter an Upper Limit:
  • Generated Sequence:

Javascript Code:

function fizzBuzz(upperLimit) {
    var limit = upperLimit || 100; // Getting a limit or default value
    var str = "";
    for (var i = 1; i <= limit; i++) {
        str = str 
              + ((i % 3 == 0) 
                ? ((i % 5 == 0) ? "FizzBuzz" : "Fizz") 
                : ((i % 5 == 0) ? "Buzz" : i)) + ", ";
    }
    return (str + "...");
}

 

Fibonacci Sequence Generator

On September 22, 2015, in Code, Javascript, Work - out of office, by sailesh

Fibonacci Sequence Example: 0, 1, 1, 2, 3, 5, 8, ….

The first two numbers are 0,1. The next number is found by adding up the two numbers before it (0+1). Similarly, the next is found by adding the two numbers before it (1+2).

  • Enter an Upper Limit:
  • Generated Sequence:

Javascript Code:

function generateFib() {
    var limit = 100; // Change the value as you want
    var str = "";
    for (var i = 0, j = 1; i < limit; i = i + j, j = i + j) {
        str = str + (i + ", " + ((j < limit) ? (j + ", ") : ""));
    }
    return (str + "...");
}


 

తప్పుల డప్పుల గొప్పలు పలుకుతూ, కల్లల కృతుల కోకొల్లలు పాడుతూ,
నూతుల లోతుల గోతులు తవ్వుతూ, పరుల పాపాల కూడికలు కడుతూ,
కోతుల చేతల రీతులు పాటిస్తూ, లక్షల నీతుల బొధలు వల్లిస్తూ,
రోషాల పౌరుషాల తొడలు చరుస్తూ, స్వార్ధాల పెడర్ధాల భావాలు వెల్లడిస్తూ,
రేపుల ఎల్లుండ్ల భయాలు నిద్రపోతూ, అతుకుల బ్రతుకుల రోజులు గడుపుతూ,
ఆదాల వ్యయాల బంధాలు గణిస్తూ, అందాల ఆనందాల అర్ధాలు మరుస్తూ…

మొత్తం ఆర్జన: తర్జన భర్జన జీవన విసర్జన

 

Palindrome Check

On August 28, 2015, in Code, Javascript, Work - out of office, by sailesh

A palindrome is a string when reversed is the same as original.

Example:

  • String Input:
  • Is Input a Palindrome?:
  • All Distinct Palindrome Substrings:
  • No. of Distinct Palindrome Substrings:

Javascript code:

    function findAllDistinctPalindromes(str) {
        //if(str.length>5000)return "String too big";
        var strarr = [];
        for (var lenOfSubStr = 1; lenOfSubStr <= str.length; lenOfSubStr++) {
            for (var i = 0;
                (i + lenOfSubStr) <= str.length; i++) {
                var subString = str.substr(i, lenOfSubStr);
                if(strarr.indexOf(subString) < 0) {
                if(isPalindrome(subString))strarr.push(subString);
            }
            }
        }
        return strarr;
    }

    function allDistinctPalindromesCount(str) {
        return findAllDistinctPalindromes(str).length || 0;
    }

    function isPalindrome(inputStr) {
        return (inputStr == inputStr.split('').reverse().join(''));
    }


 

Chap. 3: Vegas fun amplified

On February 17, 2014, in Uncategorized, by sailesh

After a tiring drive the previous day, we took a lazy start for today. Walked to the car and remembered that we missed visiting Hoover dam the previous day. So we drove there and found ourselves at modern day man-made engineering marvel that lights up the vibrant Vegas.

Coming back to Vegas, we directly went to the Forum shops at the Ceasers palace. Pearl factory counter where we parented a couple pearls by taking them out of shells was fun. Played some vertical and regular Roulette on our way to Bellagio. What ever we gained in vertical lost in the regular.

The O show at Bellagio was costly. We choose almost the best seats in the  auditorium. The experience was enthralling. The stage set is extraordinary turning from floor to deep diving pool in front of our eyes. We loved the way the curtain rises and closes. The indoor boat ride in Venetian was quite interesting. The boat driver sang songs in Italian. They have really good vocals. In both the places, we had to buy those expensive photo prints by their photographers as they were to good.

As usual, the Bellagio dancing fountain and the Mirage volcano burst are worth the free watch. I would say these two make the Las Vegas strip Lively.

 

Chap. 2: Lord of the Landscapes

On February 10, 2014, in Uncategorized, by sailesh

Day 2 started with a funny story. 2 miles down the road from the Phoenix hotel we were in, is the Enterprise Rent-a-car of Scottsdale. I booked a car to be rented from them. They opened at 8 AM. I called them for pick up and told the guy on the line the hotel name. The response was that he cannot come and I cannot go as all the roads around their branch are closed due to a parade in their town. He told me that he will call me when he would be able to pickup. In the above story, there is a mistake by both of us which is I rented from the wrong Enterprise and he thought I am staying in Scottsdale hotel branch of the same name. Few minutes later, I got a call from him asking the exact address. Then he realized and said I don’t come into their “jurisdiction”.

Not knowing what to do, just opened Google maps on the phone and found that I was staying exactly 2 blocks from the nearest Enterprise that is on the same road and I could see it. So we walked. Had to wait for more than one hour as technically I don’t have a reservation, but walked out with a red and black leather interior sunroof Ford Focus.

Sedona:
Robert Soo is right. Never thought desert would be so beautiful. The red hills and formations were incredible. The following is the view of Sedona from Airport Drive.

image

Instructions to take a photo from the binoculars:

image

1. Put a quarter in the binoculars. Ha..ha … Obvious
2. Turn the binoculars to the right position. Hold it…. Don’t loose its position.
3. Open the camera app on phone and place the lens adjacent to one of the binocular lenses.
4. Click it before the binocular timer closes the lenses.

Result:

image

It was Lindsy from Oak Brook village tourism center that guided us through these desert jewels.

Red Rock Crossing is the most photographed spot in Sedona.

image

The route 89A between Sedona and Flagstaff is so magnificent both in beauty and size, it felt like sitting in the front rows of an IMAX theater watching a documentary on the area. No words can express the wonder or awe that opened our mouths wide open all along the curvy narrow steep road. The carved mountains, the rugged landscape are amazing art works of mother nature. The canvas was so huge covering all around, the camera couldn’t fit it.

From Flagstaff to Grand Canyon South Rim, the drive was pleasant. No traffic on the road and no living habitat in the nearby area including human race. So taking the advantage and with a target of reaching Grand Canyon before sunset, I drove fast…. A lonely mountain sitting in the vast lands looked like the one from the movie “The Hobbit”.

Grand Canyon is so big, it took time for me to find the bottom. The icing on the Canyon was a little snow that made the view even more Gorgeous. Photo will follow.

The stress of the drive left us with joy when we made it to the Bellagio’s dancing fountain in Las Vegas.

Good night… Long straight… Don’t let the gambling bugs bite

 

Chap. 1: A Running start

On February 10, 2014, in Uncategorized, by sailesh

Trip got exciting even before our first step got out of the house. The unplanned happenings during the planned schedules like the traffic gets us those bonus feelings of hurriedness, worriedness, and even buriedness and occasionally joyousness. It gets even better when we get all these feelings in a mixture. Some close family friends from India stopped by our house just before we started. Amid the preparations to start off on our week long trip and the hospitality to the friends, it was a Running start for us. Thanks to Suresh who dropped us at the airport promptly. On the way we discussed various mishaps from Spirit airlines in the past experiences of others. To summarize most of them were unpleasant like canceling of flights and common delays. Fortunately, our flight started with a minor delay.

image

At the airport during the journey, we meet an old friend from Madison whom I saw after 3 years. We were informed that he moved to Phoenix and was going back home for the weekend. He was kind enough to leave us at our hotel that late in the night. That was a double bonus as we saved some bucks off taxi and most importantly, got back in touch with an old friend with whom I played cricket in the same team.

 

అధికుల వైనం పట్టాలు కట్టిన వేళ
అధముల దైన్యం దిక్కులు చూసిన వేళ
సర్కారుల నైజం చట్టాలు చేసిన వేళ
ధిక్కారుల ధైర్యం కట్టలు తెంచిన వేళ
తిరిగి వస్తాయి స్వరాజ్య సమర రధాలు
తీసుకు వస్తాయి స్వాతంత్ర్య విమల సుమాలు

 

కులాల పేరిట కత్తులు దూశాం
జాతుల పేరిట జగడాలు సృష్టించాం
ప్రాంతాల పేరిట ప్రాణాలు పోగొట్టాం
రంగుల పేరిట రక్తపుటేరులు పారించాం
మతాల పేరిట మారణహోమాలు జరిపాం
ధర్మాల పేరిట యుద్ధాలు చేశాం

మనుగడ పేరిట ఇన్నాళ్ళూ ఏం నేర్చుకున్నాం?

 

నలుపైతేనేమి మా రూపం, సెలయేళ్ల కన్న మాలో సొంపులెక్కువని వంపులు తిరిగిన దారులు
వినీలాకాశపు నీలం విలీనం చేసుకుని గర్వాతిశయమున హొయలొలుకుతున్న సరస్సులు
నిప్పుల కొప్పులే ఐనా పచ్చని పచ్చిక బైళ్ళు కప్పుకొని ప్రశాంతత ప్రదర్శిస్తున్న పర్వతాలు
పొరలుగా పేరుకొని ధర విరుపుల్ని సౌమ్యంగా శాంతపరుస్తున్న తెల్లటి మంచు తెరలు
ఇంద్రధనస్సుని మ్రింగి అందాలు ఆరబోసి భగ్గు భగ్గున పొగలు గ్రక్కుతున్న నీటిబుగ్గలు
కాలాలన్నీ తనలో కలిపేసి జంతు నిలయమైన ఈ ప్రకృతి హంగులో ప్రతీ వర్ణం సువర్ణమే

If you didn’t understand what I said above, do an image search on Yellowstone.