in reply to Which Permute or other module can give me all possible subsets of 6 numbers out of 40?

#!/usr/bin/perl # http://perlmonks.org/?node_id=1212655 use strict; use warnings; my $draw = 2; my $from = 3; my $pattern = '(2+?)' x $draw; (2 x $from) =~ /^$pattern(??{print "@+[1..$draw]\n"})/;
  • Comment on Re: Which Permute or other module can give me all possible subsets of 6 numbers out of 40?
  • Download Code

Replies are listed 'Best First'.
Re^2: Which Permute or other module can give me all possible subsets of 6 numbers out of 40?
by choroba (Cardinal) on Apr 11, 2018 at 11:10 UTC
    Excuse my thickness, but why do we need 2 here? It works equally well with 0, 3, 4, etc., or with characters like a, b etc., but it doesn't work with 1. Why's that?

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

      Because the print returns 1, and we need the (??{...}) block to return something that does not match, to cause the regex engine to backtrack.

        Of course! I was blind. I solved a similar issue years ago, but I used the FAIL as I couldn't choose what characters would be involved. Here, it would be (note that (?{}) is used):
        ($digit x $from) =~ /^$pattern(?{print "@+[1 .. $draw]\n"})(?!)/;
        And it works for $digit = 1, too.

        ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,