Skip to content

Instantly share code, notes, and snippets.

@davorg
Created August 3, 2015 09:56
Show Gist options
  • Save davorg/8504dc3b36f5984bf797 to your computer and use it in GitHub Desktop.
Save davorg/8504dc3b36f5984bf797 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
my %letter;
@letter{'a' .. 'z'} = reverse 'a' .. 'z';
open my $word_fh, '<', '/usr/share/dict/words' or die $!;
while (<$word_fh>) {
chomp;
next if /[^a-z]/;
if (check_word($_)) {
say length $_, " : $_";
}
}
sub check_word {
my $word = shift;
my @letters = split //, $word;
for my $x (0 .. $#letters) {
return if $letters[$x] ne $letter{$letters[-1 - $x]};
}
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment