logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

[SPOILER] Quiz #8 solution: msg#00280

Subject: [SPOILER] Quiz #8 solution
Here's my solution.  Nice and short.  I had also forgotten about sequences
which appear twice in the same word.  $seq{$1} ne $_ was a quick fix for
that bug.

Ronald


#!/usr/local/bin/perl -w

use strict;

my %seq;

open Q, ">questions" or die "Can't open 'questions': $!\n";
open A, ">answers" or die "Can't open 'answers': $!\n";

while (<>) {
  chomp;
  while (/(?=(.{4}))/g) {
    if (exists $seq{$1} and $seq{$1} ne $_) {
      $seq{$1} = 1;
    } else {
      $seq{$1} = $_;
    }
  }
}

for (sort (grep {$seq{$_} ne '1'} keys %seq)) {
  print Q "$_\n";
  print A "$seq{$_}\n";
}

__END__



<Prev in Thread] Current Thread [Next in Thread>