Create a two-dimensional array at runtime

AUTHOR

TimToady

Get two integers from the user, then create a two-dimensional array where the two dimensions have the sizes given by those numbers, and which can be accessed in the most natural way possible. Write some element of that array, and then output that element. Finally destroy the array if not done by the language itself.

More

http://rosettacode.org/wiki/Create_a_two-dimensional_array_at_runtime#Raku

use v6;




my ($major, $minor) = prompt("Dimensions? ").comb(/\d+/);
die "Please enter two dimensions" unless $major && $minor;

my @array := [ for ^$major { [ for ^$minor { '@' } ] } ];

@array[ (^$major).pick  ][ (^$minor).pick ] = ' ';

.Str.say for @array;


# vim: expandtab shiftwidth=4 ft=perl6

See Also

100-doors.raku

100 Doors

24-game.raku

24 game

accumulator-factory.raku

Accumulator factory

ackermann-function.raku

Ackermann function

arbitrary-precision-integers.raku

Arbitrary-precision integers (included)

balanced-brackets.raku

Balanced brackets

binomial-coefficient.raku

Binomial Coefficient

copy-a-string.raku

Copy a string

hailstone-sequence.raku

Hailstone sequence

last-fridays-of-year.raku

Last fridays of the year

prime-decomposition.raku

Prime decomposition

README.md

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.

Built with Podlite — the markup and publishing tools behind this site.