in reply to Re: All possible number combinations in perl
in thread All possible number combinations in perl
prints: 1 12 123 1234 12345 2 23 234 2345 3 34 345 4 45 5#!/usr/local/bin/perl-5.10.1 -w use strict; my $var = 5; my @list = 1..$var; my @combos; foreach ( 0..($var-1) ){ my @temp_array; push(@temp_array , "$list[$_]"); if($list[$_+1]){push(@temp_array , "$list[$_]$list[$_+1]")} if($list[$_+2]){push(@temp_array , "$list[$_]$list[$_+1]$list[$_+2 +]")} if($list[$_+3]){push(@temp_array , "$list[$_]$list[$_+1]$list[$_+2 +]$list[$_+3]")} if($list[$_+4]){push(@temp_array , "$list[$_]$list[$_+1]$list[$_+2 +]$list[$_+3]$list[$_+4]")} push(@combos, @temp_array); } print "@combos\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: All possible number combinations in perl
by BrowserUk (Patriarch) on Jun 07, 2012 at 21:30 UTC | |
|
Re^3: All possible number combinations in perl
by rovf (Priest) on Jun 08, 2012 at 09:27 UTC |