Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Transposer

by eric256 (Parson)
on Jul 14, 2005 at 15:12 UTC ( #474911=note: print w/replies, xml ) Need Help??


in reply to Transposer

A pugs version of transpose..

use v6; my $matrix = [ [85,34,15,38,53,80], [73,38,31,92,17,96], [89,10,31,96,35,60], [45,68,23,90,33,12], [99,100,27,52,25,28], [85,50,75,28,73,4], [45,8,45,48,55,66], [57,10,5,4,43,20], [61,36,1,22,7,74], [37,16,71,32,81,42], ]; sub print_matrix ($matrix) { for ($matrix) -> $row { say $row.join(" "); } } sub transpose ($matrix) { my $new_matrix; my $width = $matrix[0].elems - 1; my $height = $matrix.elems - 1; for (0 .. $width) -> $y { for (0 .. $height) -> $x { $new_matrix[$y][$x] = $matrix[$x][$y]; } } return $new_matrix; } say "before"; print_matrix($matrix); say "after"; print_matrix( transpose $matrix );

___________
Eric Hodges

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2020-09-29 04:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (145 votes). Check out past polls.

    Notices?