Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Timezone Puzzle

2
Working in a global environment for many (not putting a number is intentional ;) years now, I would expect myself to be an expert in timezones. But sadly, that has never been the case. At times, the differences are not clear. Sometimes when the differences are clear, like in case of NY (9.5 now), the math is just too tough to do again and again. After downloading timezone converters, using websites etc, here is the 'tool' that I found most useful.

Line to the excel

PS1: I did use outlook for some time showing two zones, but doesn't help beyond that.
PS2: The AM/PM thing is a little mixed up (can change in your sheet if you want to), but works just fine for me.

Re: Combination Generator

0
Related to my post on Combination Generator, I received some email requests for some other variations. While answering one such request for generating nCr combinations, I did some search. As expected Perl did not disappoint me and I got to know of the awesome perl module for Combinatorics. To give an idea of how simple it is to use, here is the code for nCr generation.

use Math::Combinatorics;
my @n = qw(1 2 3 4 5 6 7 8 9 10 11 12 13 14);
my $combinat = Math::Combinatorics->new(count => 8, => [@n],);
while(my @combo = $combinat->next_combination){
print join(' ', @combo)."\n";
}
output:

MP3 Manager in Perl

0
I am not a really great fan of music, much less a fan of organizing music on my computer. A recent encounter with a friend who uses an mp3 player that displays only "titles" (and not file names) gave me a chance to do a bit of coding. I don't remember the last time I did it and yes, I am a software developer ;-)

It isn't something totally new and not something that can't be found anywhere else. However, just for the kicks, ended up writing this Perl code to traverse a music directory recursively, list down the song details (meta data details like album, artist, track etc) and copy the file names to the title if you want to. Also, as was the need of the hour, I added a part that lists down empty directories in the tree as well.

Here is the code, check it out. To run it on your machine, you will need a Perl interpreter and MP3:Tag module along with it. Any constructive feedback is welcome, any snide remarks will be summarily ignored deleted.

PS: The information is written as a pipe delimited file to facilitate easy transformation to an excel

Buffett, Compounding and The Rule of 72

27

"The most powerful force in the universe is compound interest"

This is allegedly a statement made by Albert Einstein. Many people argue if those were the exact words, but almost all agree that he said something to that effect. However, there shouldn't be an iota of doubt in anyone's mind about the truth in what is being said.

Warren Buffett and Peter Lynch, two legendary money makers, who made tons of money without making stuff, but by making deals/decisions; both of them have emphasized the power of compounding in their businesses and are reaping the benefits. It would be way too naive to say that compounding was the biggest reason of their success; however, it would be fair to say it had a crucial role to play.

Buffett owned his first stock at the age of 11, but says,
"I don't know why I wasted time before that stock…I got started late."

For quite some time I used to think this statement as plain rhetoric, but now having read a book about his investment philosophy I realise how serious he was and I have no doubt in my mind that he truly believed what he said.

Investing is a complex thing, and it involves among lot other things, the risk of losing your capital. But there are many investment vehicles (like PPF) that are safe and most of us invest in them, but generally that happens after gaining some financial wisdom but losing a considerable amount of time in the process. For all of us, all we had [have to, if you are still young :-)] to do was [is] invest early and forget.

To give an idea, 1 Lac invested at a rate of 12% for 30 years will become approximately 30 lacs. If you are lucky and could earn a 20%, that would be 2.4 crores!

If you think these numbers are high, think again. Historically, Sensex has returned more than 18% to date.

Here is a sheet that shows the results of compounding a sum of money at a certain rate for certain years. Have a look and you will realize that over a long period, how money transforms itself. The sheet contains three tabs:
1. SIP - calculations for a systematic investment plan (for fixed rate of interest)
2. Summary Amounts - compounded amounts for a principal, rate of interest, duration.
3. Summary of growth - growth of money as a factor of the principal amount.

The intensity of Buffett's love for compounding can only be matched by his hate for taxes. He considers tax to be one of the biggest holes in your pocket. Not surprisingly, he tries every trick in the book to save tax. There was a news story about him paying less tax than his secretary (in terms of %). He was taxed at 17% while his secretary paid @ 30%. http://business.timesonline.co.uk/tol/business/money/tax/article1996735.ece

He considers the money lost in tax to be a double loss because not only you lose some of your earnings, you lose the amount you could have made using it. If a company is doing well, he would prefer the company to not pay a dividend and keep growing.

Before I close this post, here is a 'nifty' tip for your compound interest calculations.

The Rule 0f 72:
The number of years you need to double your money = 72/ (rate of interest in %). For mathematically inclined, here is how/why it works. http://www.moneychimp.com/features/rule72_why.htm

Link to the excel sheet for compound interest and SIP calculations


Lottery - *Jai Veeru revisited

0
***Context Filter***

Bollywood context required to read the post (excel can be used regardless)

Long before I saw Sholay I have been a fan of using coin to make decisions for me. Recently I found another situation which needed guidance from the coin, and I couldn't find one. So, I decided to write an e-coin. It's a little more flexible than the physical one, so it can be tossed once or 10000 times as the need may be. And it is a multidimensional coin which has any number of choices you want as opposed to the traditional two.

Try it if you want to. Get a copy here.

All disclaimers possible go with it (Not responsible for any wrong decision or a machine crash blah blah blah...)

*Jai and Veeru are the main characters of Sholay

Sudoku Solver

0
I wrote this one around 2.5 years back. I wasn't clogging then. It follows a brute force approach to solve a sudoku and hence may take substantial amount of time (15+ minutes in some cases) and processing power for tough ones. It first fills all the straight forward ones, fixes those values and then goes on to check all the possible combinations for remaining values.

The algorithm can be improved by widening the scope of the "straight forward fills". However, I haven't done anything more on it than what I did the first time (doesn't that always happen?)

Link

Combination Generator

12
This started with identifying possible scenarios for something that we needed to test. Here is the gist of the problem.

There are 5 parameters and each parameter has a list of possible values. Generate all the possible cases. Plain old combination.

The first solution that someone followed was to generate the list manually :-). So, I tried and improved it by hardcoding a fixed number of "for" loops for the number of possible values(number of values were fixed too). But then I decided I will roll it out to others and thats when I thought of all the questions that people might ask. So, I realized, not making it general is too lame a solution. So, here it is, a general solution for generating combinations, of course there are upper limits to the number of combinations it can handle due to the limit excel has for data.

Please read the disclaimer before using it. Any constructive comments are welcome!

Link to the excel

RE:ziuq a si siht

0
The subject reads - "This is a quiz" reversed. Steven Kryskalla got 3 (and almost got the 4th) and jsn got all of them with few insights on the questions as well :-).
Here is the deciphered post with comments inline in italics and clues in bold.

If you got the subject of this post and if you are able to read this then you would have guessed what this post is going to be about. Well, to clarify just in case, this is going to be a ciphered quiz. The cipher can be different for all the questions. So make no assumptions. Here you go starting with the rotten one

1. What does PDF stand for? If you could read the specific one, get ready for a more general one, key lies in my name
Answer is "Portable Document Format" and the next cipher is Caesar's cipher with Key D (4)

2.Who said this - give me a lever large enough, and I will move the earth? If you could read this your TRAIN is on track for the THIRD one.
Answer is Archimedes (jsn made a comment though about this not being true). The next cipher is Rail Fence Cipher with 3 rails

3.Which animal is the vehicle of lord kamadeva (God of love in Hindu mythology)? The last one is a trip back to where we started.
Parrot. The last question is just reversed

4. What is the name of Stephen Hawking's medical condition
amyotrophic lateral sclerosis

ziuq a si siht

5
Ifay ouyay otgay ethay ubjectsay ofay isthay ostpay, anday ifay ouyay areay ableay otay eadray isthay enthay ouyay ouldway avehay uessedgay atwhay isthay ostpay isay oinggay otay ebay aboutay. ellWay, otay arifyclay ustjay inay asecay, isthay isay oinggay otay ebay aay ipheredcay uizqay. eThay iphercay ancay ebay ifferentday orfay allay ethay uestionsqay. oSay, akemay onay assumptionsay. ereHay ouyay ogay artingstay ithway ethay ottenray oneay

1.Jung qbrf CQS fgnaq sbe? Vs lbh pbhyq ernq gur fcrpvsvp bar, trg ernql sbe n zber trareny bar, xrl yvrf va zl anzr

2. Tel pxfa qefp - dfsb jb x ibsbo ixodb bklrde, xka f tfii jlsb qeb bxoqe? Fc vlr zlria obxa qefp vlro QOXFK fp lk qoxzh clo qeb QEFOA lkb.

3. wcnas ehlfr adaof vnnmh o)hao itpco ewtth hiltv ieldm e(dle hdyog ?esns rbkwr eaeia mihec ookav gooii utlyt lteai athes rd

4. noitidnoc lacidem s'gnikwah nehpets fo eman eht si tahw