How to resolve the algorithm Create a two-dimensional array at runtime step by step in the Quackery 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 Quackery 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 Quackery programming language

Source code in the quackery programming language

  [ witheach peek ]         is {peek}        (   { p --> x     )

  [ dip dup
      witheach [ peek dup ]
    drop ]                  is depack        (   { p --> *     )

  [ reverse
    witheach
      [ dip swap poke ] ]   is repack        (   * p --> {     )

  [ dup dip
      [ rot dip
        [ depack drop ] ]
    repack ]                is {poke}        ( x { p --> {     )

  [ 0 swap of 
    nested swap of ]        is  2array       (   n n --> [     )

  
  $ "Array width  (at least 2): " input $->n drop
  $ "Array length (at least 5): " input $->n drop
 
  say "Creating " over echo say " by " 
  dup echo say " array." cr
  
  2array
  
  say "Writing 12345 to element {1,4} of array." cr
   
  12345 swap ' [ 1 4 ] {poke}
  
  say "Reading element {1,4} of array: "
  
  ' [ 1 4 ] {peek} echo

  

You may also check:How to resolve the algorithm Word ladder step by step in the jq programming language
You may also check:How to resolve the algorithm 24 game step by step in the CoffeeScript programming language
You may also check:How to resolve the algorithm Fibonacci word step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Averages/Arithmetic mean step by step in the 6502 Assembly programming language
You may also check:How to resolve the algorithm Palindrome detection step by step in the CLU programming language