Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,053 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,591 people online right now. Registration is fast and FREE... Join Now!




all possibile singular permutations in perl

 
Reply to this topicStart new topic

all possibile singular permutations in perl, in 9,999,999,999 there are 3,628,800

Rating  2
evolivid
25 Jul, 2008 - 02:20 PM
Post #1

New D.I.C Head
*

Joined: 24 Jul, 2008
Posts: 28


My Contributions


here s all possibile singular permutations in perl


Programming it`s a Hobby

CODE

for (0..9) {
$a = $_;

for (0..9) {
$b = $_;

for (0..9) {
$c = $_;

for (0..9) {
$d = $_;

for (0..9) {
$e = $_;

for (0..9) {
$f = $_;

for (0..9) {
$g = $_;

for (0..9) {
$h = $_;

for (0..9) {
$i = $_;

for (0..9) {
$j = $_;

if ($a != $b & $a != $c & $a != $d & $a != $e & $a != $f & $a != $g & $a != $h & $a != $i & $a != $j) {
if ($b != $a & $b != $c & $b != $d & $b != $e & $b != $f & $b != $g & $b != $h & $b != $i & $b != $j) {
if ($c != $a & $c != $b & $c != $d & $c != $e & $c != $f & $c != $g & $c != $h & $c != $i & $c != $j) {
if ($d != $a & $d != $b & $d != $c & $d != $e & $d != $f & $d != $g & $d != $h & $d != $i & $d != $j) {
if ($e != $a & $e != $b & $e != $c & $e != $d & $e != $f & $e != $g & $e != $h & $e != $i & $e != $j) {
if ($f != $a & $f != $b & $f != $c & $f != $d & $f != $e & $f != $g & $f != $h & $f != $i & $f != $j) {
if ($g != $a & $g != $b & $g != $c & $g != $d & $g != $e & $g != $f & $g != $h & $g != $i & $g != $j) {
if ($h != $a & $h != $b & $h != $c & $h != $d & $h != $e & $h != $f & $h != $g & $h != $i & $h != $j) {
if ($i != $a & $i != $b & $i != $c & $i != $d & $i != $e & $i != $f & $i != $g & $i != $h & $i != $j) {
if ($j != $a & $j != $b & $j != $c & $j != $d & $j != $e & $j != $f & $j != $g & $j != $h & $j != $i) {



print $a,$b,$c,$d,$e,$f,$g,$h,$i,$j,;
print "\n";
}}}}}}}}}}}}}}}}}}}}



User is offlineProfile CardPM
+Quote Post

AdamSpeight2008
RE: All Possibile Singular Permutations In Perl
25 Jul, 2008 - 02:33 PM
Post #2

LINQ D.I.C.
Group Icon

Joined: 29 May, 2008
Posts: 797



Thanked: 51 times
Dream Kudos: 2175
My Contributions
I know this snippet isn't perl but another way of getting combinations
M out of N
User is offlineProfile CardPM
+Quote Post

linuxunil
RE: All Possibile Singular Permutations In Perl
25 Jul, 2008 - 06:31 PM
Post #3

New D.I.C Head
Group Icon

Joined: 7 Mar, 2006
Posts: 46



Thanked: 2 times
Dream Kudos: 125
My Contributions
Instead of posting snippets in the forum they would be better off in the snippets area. The link is at the top of the page.
User is offlineProfile CardPM
+Quote Post

KevinADC
RE: All Possibile Singular Permutations In Perl
25 Jul, 2008 - 09:48 PM
Post #4

D.I.C Head
Group Icon

Joined: 23 Jan, 2007
Posts: 214



Thanked: 3 times
Dream Kudos: 50
My Contributions
There is a module that does permutations way more efficiently than this convoluted code does. List::Permutor
User is offlineProfile CardPM
+Quote Post

evolivid
RE: All Possibile Singular Permutations In Perl
27 Jul, 2008 - 08:14 PM
Post #5

New D.I.C Head
*

Joined: 24 Jul, 2008
Posts: 28


My Contributions
QUOTE(KevinADC @ 25 Jul, 2008 - 10:48 PM) *

There is a module that does permutations way more efficiently than this convoluted code does. List::Permutor


hey thankx do you happen to know where i can get a list of modules

i optimized my convoluted code
now its kinda faster




CODE


for (0..9) {
$a = $_;

for (0..9) {
$b = $_;

for (0..9) {
$c = $_;

for (0..9) {
$d = $_;

for (0..9) {
$e = $_;

for (0..9) {
$f = $_;

for (0..9) {
$g = $_;

for (0..9) {
$h = $_;

for (0..9) {
$i = $_;

for (0..9) {
$j = $_;

if ($a != $b & $a != $c & $a != $d & $a != $e & $a != $f & $a != $g & $a != $h & $a != $i & $a != $j) {
if ($b != $c & $b != $d & $b != $e & $b != $f & $b != $g & $b != $h & $b != $i & $b != $j) {
if ($c != $d & $c != $e & $c != $f & $c != $g & $c != $h & $c != $i & $c != $j) {
if ($d != $e & $d != $f & $d != $g & $d != $h & $d != $i & $d != $j) {
if ($e != $f & $e != $g & $e != $h & $e != $i & $e != $j) {
if ($f != $g & $f != $h & $f != $i & $f != $j) {
if ($g != $h & $g != $i & $g != $j) {
if ($h != $i & $h != $j) {
if ($i != $j) {



print $a,$b,$c,$d,$e,$f,$g,$h,$i,$j,;
print "\n";
}}}}}}}}}}}}}}}}}}}




User is offlineProfile CardPM
+Quote Post

evolivid
RE: All Possibile Singular Permutations In Perl
2 Aug, 2008 - 09:59 PM
Post #6

New D.I.C Head
*

Joined: 24 Jul, 2008
Posts: 28


My Contributions
ok now i optimized this again and now it is even faster this is just as fast as m base patterns code

CODE



for (0..9) {
$j = $_;

for (0..9) {
$i = $_;
if ($i != $j) {

for (0..9) {
$h = $_;
if ($h != $i & $h != $j) {

for (0..9) {
$g = $_;
if ($g != $h & $g != $i & $g != $j) {

for (0..9) {
$f = $_;
if ($f != $g & $f != $h & $f != $i & $f != $j) {

for (0..9) {
$e = $_;
if ($e != $f & $e != $g & $e != $h & $e != $i & $e != $j) {

for (0..9) {
$d = $_;
if ($d != $e & $d != $f & $d != $g & $d != $h & $d != $i & $d != $j) {

for (0..9) {
$c = $_;
if ($c != $d & $c != $e & $c != $f & $c != $g & $c != $h & $c != $i & $c != $j) {

for (0..9) {
$b = $_;
if ($b != $c & $b != $d & $b != $e & $b != $f & $b != $g & $b != $h & $b != $i & $b != $j) {

for (0..9) {
$a = $_;
if ($a != $b & $a != $c & $a != $d & $a != $e & $a != $f & $a != $g & $a != $h & $a != $i & $a != $j) {











print $j,$i,$h,$g,$f,$e,$d,$c,$b,$a,;
print "\n";
}}}}}}}}}}}}}}}}}}}



User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 05:49PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month