in reply to Re^6: Words in Words (Updated)
in thread Words in Words
I slightly modified my script:
I used english.0 from this archive as words.txt: http://downloads.sourceforge.net/wordlist/ispell-enwl-3.1.20.zip. Your script took 58s, whilest mine only 6s (on Pentium 4, 2.8 GHz). The results were different, though: your output contains the word indistinguishableness that mine does not; my list contained 911 more words than yours (e.g. you, wraps or tribe's).#!/usr/bin/perl use feature 'say'; use warnings; use strict; my $file = 'words.txt'; open my $IN, '<', $file or die "$!"; my %words; while (my $word = <$IN>) { chomp $word; undef $words{$word}; } my %reported; for my $word (keys %words) { my $length = length $word; for my $pos (0 .. $length - 1) { my $skip_itself = ! $pos; for my $len (1 .. $length - $pos - $skip_itself) { my $subword = substr($word, $pos, $len); next if exists $reported{$subword}; next if $word eq $subword . q{s} or $word eq $subword . q{'s}; if (exists $words{$subword}) { say "$subword"; undef $reported{$subword}; } } } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^8: Words in Words
by BrowserUk (Patriarch) on Oct 01, 2011 at 19:01 UTC | |
Re^8: Words in Words
by BrowserUk (Patriarch) on Oct 01, 2011 at 14:55 UTC | |
by choroba (Cardinal) on Oct 01, 2011 at 19:09 UTC | |
by BrowserUk (Patriarch) on Oct 02, 2011 at 02:47 UTC | |
by choroba (Cardinal) on Oct 02, 2011 at 08:45 UTC | |
Re^8: Words in Words
by sarchasm (Acolyte) on Oct 02, 2011 at 20:28 UTC | |
by choroba (Cardinal) on Oct 02, 2011 at 20:55 UTC | |
by sarchasm (Acolyte) on Oct 03, 2011 at 00:06 UTC | |
by Anonymous Monk on Oct 03, 2011 at 00:16 UTC | |
by sarchasm (Acolyte) on Oct 03, 2011 at 04:10 UTC |
In Section
Seekers of Perl Wisdom