in reply to Re: Puzzle Regex: Letter Frequency Arithmetic Sequence
in thread Puzzle Regex: Letter Frequency Arithmetic Sequence

Too much cheating?

#!/usr/bin/perl # http://perlmonks.org/?node_id=1201500 use strict; use warnings; my $file = '/usr/share/dict/words'; open my $fh, '<', $file or die "$! opening $file"; chomp( my @words = grep /^[a-z]{5,}$/, <$fh>); my @good = grep frequencysequence($_), @words; print "@good\n\n" . @good . "\n"; sub frequencysequence { for my $n ( 1 .. ((-1 + sqrt 1 + 8 * length) / 2) =~ s/^(\d+)\..*/$1 + + 1/er ) { "@_\n@_" =~ / (.).* \n (?: (?:(?!\1).)* \1 ){$n} (?:(?!\1).)* $ /x or return 0; } return 1; }

On my system outputs:

acacia allele assays banana baobab bedded bonobo bowwow cocoon deadhea +ded deemed doodad eddied eerier effete fesses heeded horror hubbub in +ning lessee lollop mammal manana messes needed papaya peeped peeper p +epped pepper pippin powwow reefer revere rococo salsas seeded senses +sereneness settee sleeveless tattoo teeter teethe wedded weeded xxvii +i xxxvii 49

Replies are listed 'Best First'.
Re^3: Puzzle Regex: Letter Frequency Arithmetic Sequence (UPDATED)
by LanX (Saint) on Oct 20, 2017 at 18:20 UTC
    Nice solution of the "variable length lookbehind" not allowed problem!

    But why \n instead of $ ? *

    edit

    I suppose it's necessary because the following assertion wouldn't be executed?

    update

    *) well, I just noticed the "@_\n@_" part where you are doubling the input, which explains the "\n" and some other confusion about pos.

    I agree, "too much cheating!" ;-p

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!