How to resolve the algorithm Create a two-dimensional array at runtime step by step in the Factor programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Create a two-dimensional array at runtime step by step in the Factor programming language

Table of Contents

Problem Statement

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.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Create a two-dimensional array at runtime step by step in the Factor programming language

Source code in the factor programming language

USING: io kernel math.matrices math.parser prettyprint
sequences ;
IN: rosettacode.runtime2darray

: set-Mi,j ( elt {i,j} matrix -- )
[ first2 swap ] dip nth set-nth ;
: Mi,j ( {i,j} matrix -- elt ) 
[ first2 swap ] dip nth nth ;

: example ( -- ) 
readln readln [ string>number ] bi@ zero-matrix ! create the array
[ [ 42 { 0 0 } ] dip set-Mi,j ] ! set the { 0 0 } element to 42
[ [ { 0 0 } ] dip Mi,j . ] ! read the { 0 0 } element
bi ;


  

You may also check:How to resolve the algorithm Factors of an integer step by step in the Pascal programming language
You may also check:How to resolve the algorithm Runtime evaluation/In an environment step by step in the Nim programming language
You may also check:How to resolve the algorithm Compile-time calculation step by step in the 8086 Assembly programming language
You may also check:How to resolve the algorithm Doubly-linked list/Definition step by step in the Haskell programming language
You may also check:How to resolve the algorithm Metronome step by step in the EchoLisp programming language