A Modern Word Problem.

Pepsi is currently running a promotion with the caps of its 20oz bottled sodas. They are giving away free songs on iTunes. So I came up with a word problem. I’ll post the solution tomorrow:

Under each cap you can get one of three things: “Free Song” [FS], “Try Again” [TA], “Buy One Get One Free” [BOGO]. Pepsi (as required by law) gives you the odds of winning. You get a FS 1/3 of the time and BOGO 1/6 of the time.

So the question is, given $100 (and assuming that each bottle costs only $1), how many Free Songs can you win? And what algorithm would you follow to maximize your return?

Extra Credit: How many iPod Mini’s will you have won when you run out of money?

iTunes Music Store and RSS

Apple has a RSS feed generator for iTMS. Pick your genre, pick what kind of things you want included (new releases, new tracks add to iTMS, top songs, etc.), and it will give you a URL to add to your News Aggregator of choice.

Link

Developing for ITunes under Windows with Python

When running ITunes under Mac OSX, you can use AppleScript to do all kinds of neat things. Under Windows you don’t have AppleScript, so Apple created a series of COM interfaces to allow programmatic access to ITunes and you music library (Microsoft has done the same things with Windows Media Player).

The nice thing about the COM solution is that you aren’t tied to any specific programming language (like AppleScript, for example). Of course the language that people use most for COM is C++, but there are COM bindings for VB, JavaScript (this is what the ITunes SDK examples are done in), Java, C#, Perl, and Python. Since my office has made the decision that all scripts are to be done in Python, I’ve been trying to do the same for any scripts that I write in my free time.

Back on topic. I’ve started to do some development with using the ITunes COM interface under Python. Having done my share of COM for C++, I was expecting the worst. But the Python COM bindings are really well done. If the COM object has a property, it appears in Python as a class member variable. If the COM object has a function, just call it like you would any Python function.

But not all is wine and roses… COM uses Unicode strings for all of its communications. Not a problem for Python as it is very happy with Unicode. But a problem when you try to print un-printable characters on the console. The offender in question: the single right quote. Not the apostrophe, but the single right quote. Subte difference. I tried many different ways to try and convert this extended character to something I could print (encoders, etc.) but ended up giving up. The only way I could get it to work was to go through every string I wanted to print and when it found a single right quote and replace it with the apostrophe.

The other problem that I ran into was how COM represents DATE objects. I wanted to compare two DATE objects to see which one was the most recent, but the obvious solution:

if (date1 > date2):
    do_something()

didn’t work. It turns out that you have to coerce each object into a float (the native COM representation for a DATE object) before you can compare them.

if (float(date1) > float(date2)):
    do_something()

Once I figured that out, things were pretty simple.

You can check out my scripts at my Wiki.

iTunes Music Store: Deliciously Evil

I had my first real experience with the iTunes Music Store (IMS) this week. I got some gift certificates to it for Christmas, so I decided to use them. I also found out that if I sign up to pay with PayPal, I get 5 free songs to download. So I signed up.

After some fumbling with the Gift Cerificates (you have to scratch off the stuff on the back to reveal the code. Nowhere could I find the instructions to do this, instead I kept entering the code at the bottom…). So I shopped around for some singles (for my free songs) and some albums (for my certificates). And guess what: I enjoyed my experience.

So why “Deliciously Evil”? Because all the features of IMS make it too easy for people to buy new music. I was thinking of setting up an allowance for my account so I don’t go crazy. Just a couple of clicks and a password entry and you have new music which will get pushed down to your iPod. Couple the ease of use with the “Consumer Friendly” Copy Protection features (ie. my wife and I can share music with each other) and you have something that is almost too easy to use to be good for you.