Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by Anonymous Monk
on Mar 11, 2018 at 13:35 UTC ( #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
Node Status?
node history
Node Type: note [id://1210657]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2018-06-18 23:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (111 votes). Check out past polls.

    Notices?