language-agnosticrosetta-stone

Code Golf: Decision Tree


In Google Code Jam 2009, Round 1B, there is a problem called Decision Tree that lent itself to rather creative solutions.

Post your shortest solution; I'll update the Accepted Answer to the current shortest entry on a semi-frequent basis, assuming you didn't just create a new language just to solve this problem. :-P

Current rankings:


Solution

  • Perl in 107 characters

    say("Case #$_:"),
    $_=eval"''".'.<>'x<>,
    s:[a-z]+:*(/ $&\\s/?:g,s/\)\s*\(/):/g,
    eval"\$_=<>;say$_;"x<>for 1..<>
    

    Newlines for legibility; none of them is necessary or counted in.

    It uses features found only in the latest versions of Perl, so run with perl -M5.010 or later.

    I used to be a Perl noob too, so this works almost the same as the ruby one. Original version 126 chars, optimizations by peutri.

    Backlinks:

    Word Aligned - Power Programming