in reply to Obfu/golf Contest

Let's start with regular compaction.

Is it ok with you to use commandline options in the #! line? (like -l etc)

If so:

#!/usr/bin/perl -l print "Please enter the string to be searched for the string 'monkey': +"; print "String 'monkey' was ",<>!~/monkey/&&'not ',"found in the input +string.";

else:

#!/usr/bin/perl print "Please enter the string to be searched for the string 'monkey': +\n"; print "String 'monkey' was ",<>!~/monkey/&&'not ',"found in the input +string.\n";

Replies are listed 'Best First'.
Re: Re: Obfu/golf Contest
by tall_man (Parson) on Feb 19, 2003 at 16:36 UTC
    Here's one reducing the redundancy in the strings:
    $s="string";$m="monkey";print "Please enter the $s to be searched for +the $s '$m':\n";print "\u$s '$m' was ",<>!~/$m/&&'not ',"found in the + input $s.\n";
    154 characters (but no perl shebang -- is that required for the golf stroke count?)

    Update:170 with the shebang.

Re: Re: Obfu/golf Contest
by xmath (Hermit) on Feb 19, 2003 at 16:53 UTC
    I just realized something to hide&reduce those strings: You use exactly 32 different characters (excluding newline), so you might be able to encode them with 5-bit codes and pack them tightly into a bitstring which you put as raw binary data into the file. This will make all strings almost twice as short and totally unreadable.

    •Update: sorry, mind blurp.. I was already thinking a bit ahead. You use less than 32 chars, but if you take a..z and add the remaining ones you use ('P', 'S', ' ', '.', "'", ':') it adds up to 32. Using a..z is useful since it's more compact than explicitly listing all chars you really use.

    The issue is how to compactly write the decoding logic. You'll have to play with unpack 'B*' etc. Also use barewords when possible (unpack B99, or if you need a list of chars for the logic you can do a..z)

    I don't have time to try this myself right now, maybe someone else can figure it out from here