<$BlogRSDURL$>
My tweets

    Site Feed - Site Feed

    My other writings
    Cricket 24 x 7
    Jaagruthi
    Yahoo! 360
    Mayajaal
    My Bloglines
    My 43 things
    My LinkedIn
    My Facebook Profile On Orkut

    Mail me
    About me
    FlickrFlickr Feed

    Yahoo! Search



    Baakiyon ke blog
    Badri's Tamil thoughts
    Ganesh's Happily Haphazard
    Nitin's Acorn
    Prabhu's Pethals
    Raghu the reluctant Delhiite
    Samanth's blahg
    Sankhya the busy idler
    Srini the movie critic

    Creative Commons License
    Rabble Rousing Random Ramblings by S Jagadish is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License.

    January 07, 2005
     

    Optimizing spending on petrol

    As a followup to last month's rant on the way petrol is priced, I started wondering about how much quantity I should fill to ensure that I do not fork out any extra money and in fact the petrol pump dealer instead ends up paying the deficit. Through some trial and error, I hit upon the fact that currently, when petrol costs Rs. 44.21 per litre in Bangalore, I stand to gain 5 paise when I fill 3.1 litres since it would work out to Rs. 137.05. But really I'm never going to pay that .05 bit and neither does the dealer ask for it.

    So when I do it continously enough, I'm bound to recover my earlier losses (after a lot of petrol filling!). But the price of petrol is never going to be Rs. 44.21 forever. So I wrote some simple Perl code which lists out the quantity of petrol I need to fill to gain in the deal, assuming that the dealer doesnt bother about a deficit of upto 10 paise. Feel free to change the location of your Perl interpreter in the first line.

    #!/usr/local/bin/perl -w

    use Getopt::Long;
    use POSIX;

    my $usage="Usage: ".__FILE__." -rate [petrol price per litre] -maximum [amt. of money]\n";

    my ($rate,$maximum);

    GetOptions("rate|r=f" => \$rate,"maximum|m=i" => \$maximum);

    die $usage if (! defined $rate || ! defined $maximum);

    my $minpetrol=1;

    print "Money limit (max): $maximum\n";
    print "Petrol limit (min): $minpetrol\n";
    print "\n";
    print "Petrol\tAmount\tPotential Gain\n";
    for(my $i=$minpetrol;;$i=sprintf("%.1f",($i+.1)))
    {
    my $totalamt=sprintf("%2.2f",$i*$rate);
    my $flooramt=floor($totalamt);
    my $diff=sprintf("%.2f",($totalamt-$flooramt));

    last if ($totalamt > $maximum);
    print "$i\t$totalamt";
    print "\t$diff" if ($diff > 0 && $diff <= .1);
    print "\n";
    }

    Labels:



    Some of the sites linked in my rants may require registration/subscription. Links within my ramblings open in a new window.
    Some of the links may now be broken/not take you to the expected report since the original content providers may have archived/removed the contents.
    All opinions expressed are mine alone. My employers (past, present or future) are in no way connected to the opinions expressed here.
    All pictures, photographs used are copyrights of the original owners. I do not intend to infringe on any copyright.
    Pictures and photographs are used here to merely accentuate and enhance the content value to the readers.


    Previous Posts
    China, where are you?

    Are India's cyber-laws in the right hands?

    Big news in blogging world

    London 2012?

    Can I talk to a human please?

    Australia's new problem

    CEgO surfing

    What the tsunami affected really need

    Gopal Gandhi's tribute to JN Dixit

    George Monbiot compares the US and UK spending in ...

    This page is powered by Blogger.