Velocity Reviews > Perl > a homework need help

a homework need help

David Combs
Guest
Posts: n/a

 12-15-2008
In article <ghb7vq\$u21\$(E-Mail Removed)-siemens.com>,
Josef Moellers <(E-Mail Removed)> wrote:
>Camel wrote:
>> I have no clue with my homework, can anyone help me?
>>
>> Three digits "1,2,3", how many 3-digit numbers can be made? print all the
>> numbers
>>
>> I know how to calculate the total numbers and using loop to print all the
>> numbers. The problem is how to write a generic program that takes any number
>> of digits. For example, if given "1,2,3,4,5" digits, you still can use your
>> program to print all the combinations of 5-digit numbers without modifing
>> it.

>
>The answer is: as many as there are permutations of the <n> digits.
>

Followed by stripping out any leftmost zeros.

David

skeldoy
Guest
Posts: n/a

 12-17-2008
On Dec 5, 1:38*am, "Camel" <(E-Mail Removed)> wrote:
> Three digits "1,2,3", how many 3-digit numbers can be made? print all the
> numbers

Found what you're looking for in the obfuscation-contests archives:

#!/usr/bin/perl
G: *S=sub{goto shift};*T=sub{exit shift};*U=sub{print shift};
H: my \$A="";my \$C=0;my \$D=0;my \$E=0;my \$F=0;my \$G=0;my \$H=0;my @I;
I: if(!defined(\$A=\$ARGV[0])){U(qw(ARGV[0]?));U("\n");T(1)}\$C=length
(\$A);
U("-\$A-\n");\$D=0;
J: \$F=0;\$I[\$D]=0;if(\$D!=\$C){S(K)}for(\$G=0;\$G<\$C;\$G++){U(substr(\$ A,\$I
[\$G],1))
}\$H++;U("\t");\$H%8||U("\n");S(M);
K: \$F=\$D;if(\$F!=0){S(N)}\$E=\$I[0];if(\$E==\$C){U("\n---\n\$H\n");T(0)}
L: \$D++;S(J);
M: \$D--;\$I[\$D]++;S(K);
N: \$F=\$I[\$D];if(\$F==\$C){S(M)}\$E=\$D-1;
O: if(\$F==\$I[\$E]){S(P)}\$E--;if(\$E!=-1){S(O)}S(L);
P: \$I[\$D]++;S(N);

Hand that in

Sverre

Pilcrow
Guest
Posts: n/a

 01-10-2009
On Thu, 4 Dec 2008 16:38:52 -0800, "Camel" <(E-Mail Removed)>
wrote:

>I have no clue with my homework, can anyone help me?
>
>Three digits "1,2,3", how many 3-digit numbers can be made? print all the
>numbers
>
>I know how to calculate the total numbers and using loop to print all the
>numbers. The problem is how to write a generic program that takes any number
>of digits. For example, if given "1,2,3,4,5" digits, you still can use your
>program to print all the combinations of 5-digit numbers without modifing
>it.
>
>

perldoc -q permute

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Karl Heinz Buchegger C++ 1 11-23-2004 05:06 PM Mike C++ 1 11-23-2004 04:05 AM Perl 0 02-25-2004 01:45 AM Rhino Java 1 11-16-2003 06:52 PM Allens Mail C++ 1 07-14-2003 05:52 AM