Things are slow here today. Even for the Chum-Bucket!
So here's a Perl script and a shell script that solves jumbles.
#!/usr/bin/perl -wT
$ENV{'PATH'} = "";
use strict;
my $word = defined($_=shift) ? $_ : die "usage: $0 <word>\n";
chomp($word);
($word) = $word =~ /^(\w+)$/ or die 'Bad User!';
my @chars = split //, $word;
my $speller ="spelled";
sub spelled {
my $word = shift;
my $out=`$speller $word`;
chomp($out);
if ( length($out) > 0 ) {
print "[$out]\n";
}
}
sub swap {
my $i = shift;
my $j = shift;
my $A = shift; # ref to array
my $tmp = @{$A}[$i];
@{$A}[$i] = @{$A}[$j];
@{$A}[$j] = $tmp;
}
sub permute {
my $i = shift;
my $n = shift;
my $T = shift; #ref to array
if ( $i == $n ) {
my $word = join( "", @{$T} );
spelled( $word );
} else {
for my $j ( $i..$n) {
swap( $i-1, $j-1, $T );
permute( $i+1, $n, $T );
swap( $i-1, $j-1, $T );
}
}
}
permute (1,$#chars+1,\@chars);
The above script use this shell script.
$ cat spelled
#!/bin/sh
ASPELL=/usr/bin/aspell
GREP=/usr/bin/grep
EGREP=/usr/bin/egrep
for i in $*
do
correct=`echo $i | $ASPELL -a | $GREP -v '^@' | $GREP -v '^&'
+| $EGREP -v '^$'`
if [ ! -z "$correct" ]
then
echo "$i"
fi
done
Here's some sample output:
$ jumble.pl cat
[cat]
[act]
| Plankton: 1% Evil, 99% Hot Gas. |
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.