Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

bacek (8813)

bacek
  (email not shown publicly)

Journal of bacek (8813)

Wednesday December 24, 2008
02:01 AM

Scripting Games, part 2

[ #38147 ]

Beginner's events are way too easy. Let's take a look at "advanced".

http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/aevent1.mspx

        # First thing first: build letters-to-digits map
        my $pos = 2;
        my %l2d;
        map { %l2d{$^a} = $pos; %l2d{$^b} = $pos; %l2d{$^c} = $pos++ }, 'a'..'p', 'r'..'y';

        # Calculate number representation of word
        sub read_word($word) {
        # join digit for given letters
                [~] map { %l2d{ lc $^a } }, $word.split('');
        };

        # Read wordlist and returns hash (number => word).
        # Also skips all non-7 chars words
        sub read_wordlist($filename) {
                my $fh = open($filename) or die;
                map { read_word($^a) => $^a }, grep { $^a.chars == 7 }, =$fh;
        };

        # Read wordlist file.
        my %words = read_wordlist('wordlist.txt');

        # And say word corresponded to number.
        for =$*IN {
                say uc %words{$_};
        }

Funny note: there is no 'scripts' in wordlist.txt :)

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.