Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: How to convert a script from C to Perl?

by Anonymous Monk
on Mar 11, 2018 at 13:35 UTC ( [id://1210657]=note: print w/replies, xml ) Need Help??


in reply to How to convert a script from C to Perl?

void swap(char *x, char *y) { char temp; temp = *x; *x = *y; *y = temp; } void permute(char *a, int l, int r) { int i; if (l == r) printf("%s\n", a); else { for (i = l; i <= r; i++) { swap((a+l), (a+i)); permute(a, l+1, r); swap((a+l), (a+i)); //backtrack } } }

2018-03-11 Athanasius added code tags

Replies are listed 'Best First'.
Re^2: How to convert a script from C to Perl?
by Anonymous Monk on Mar 11, 2018 at 17:22 UTC

    Here's one possible solution. No attempt was made to match the order in the generated sequence.

    use Algorithm::Combinatorics qw( permutations ); my $iter = permutations( [split //, shift // q(how do you do)] ); while (my $p = $iter->next) { print join q(), @$p, "\n"; }

    See Algorithm::Combinatorics for more info and examples.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1210657]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-19 19:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found