in reply to What does your old Perl code look like?
#!/usr/bin/perl -w # use integer; sub swap { $_[0]=$_[0] ^ $_[1]; $_[1]=$_[0] ^ $_[1]; $_[0]=$_[0] ^ $_[1]; } sub nsd { my ($a,$b)=@_; do { if ($a<$b) {$b-=$a} elsif ($b<$a) {$a-=$b} } until ($a==$b); return($a) } # main print ("Array size: "); chomp($n=<stdin>); print ("Shift: "); chomp($d=<stdin>); print("NSD:",nsd($n,$d),"\n"); for ($i=0;$i++<$n;$array[$i]=$i){} # for ($j=0;$j<nsd($n,$d);$j++) { $i=$n-$j; $aux=$array[$i]; unless ($next=($i+$d)%$n) {$next=$n} do { for($k=0;$k++<$n;printf("%2.0d",$array[$k]),print(",")){} print("\n"); $array[$i]=$array[$next]; $array[$next]=$aux; $i=$next; $aux=$array[$i]; unless ($next=($i+$d)%$n) {$next=$n} } until ($next==$n-$j); } for($k=0;$k++<$n;print($array[$k],",")){}
I was probably experimenting with the programming language that was new to me. For some reason, I disliked whitespace. Is this some kind of self-embarassment contest? ;-)
|
|---|