How to resolve the algorithm Mayan numerals step by step in the Amazing Hopper programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Mayan numerals step by step in the Amazing Hopper programming language

Table of Contents

Problem Statement

Present numbers using the Mayan numbering system   (displaying the Mayan numerals in a cartouche).

Normally, Mayan numbers are written vertically   (top─to─bottom)   with the most significant numeral at the top   (in the sense that decimal numbers are written left─to─right with the most significant digit at the left).   This task will be using a left─to─right (horizontal) format,   mostly for familiarity and readability,   and to conserve screen space (when showing the output) on this task page.

Mayan numerals   (a base─20 "digit" or glyph)   are written in two orientations,   this task will be using the "vertical" format   (as displayed below).   Using the vertical format makes it much easier to draw/construct the Mayan numerals (glyphs) with simple dots (.) and hyphen (-);     (however, round bullets (•) and long dashes (─) make a better presentation on Rosetta Code).

Furthermore, each Mayan numeral   (for this task)   is to be displayed as a cartouche   (enclosed in a box)   to make it easier to parse (read);   the box may be drawn with any suitable (ASCII or Unicode) characters that are presentable/visible in all web browsers.

Mayan numerals (glyphs) were added to the Unicode Standard in June of 2018   (this corresponds with version 11.0).   But since most web browsers don't support them at this time,   this Rosetta Code task will be constructing the glyphs with "simple" characters and/or ASCII art.

The Mayan numbering system has the concept of   zero,   and should be shown by a glyph that represents an upside─down (sea) shell,   or an egg.   The Greek letter theta   (Θ)   can be used   (which more─or─less, looks like an egg).   A   commercial at   symbol   (@)   could make a poor substitute.

The Mayan numbering system is a   [vigesimal (base 20)]   positional numeral system.

Note that the Mayan numeral   13   in   horizontal   format would be shown as:

Other forms of cartouches (boxes) can be used for this task.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Mayan numerals step by step in the Amazing Hopper programming language

Source code in the amazing programming language

#include 

algoritmo
    
    muestra=""
    obtener total argumentos
    cuando ' sea distinto a( 2 ) '{ terminar }
    obtener parámetro alfanumérico (2), guardar en 'muestra'

    lsimb={}, '"    "," .  "," .. ","... ","...."'#(utf8("────")), enlistar en 'lsimb'

    largo=0, #( largo = len(muestra))
    sdígitos={}, separar( muestra, sdígitos, "")
    ndígitos=0, #( ndígitos = number(sdígitos) )

    m=0, t=0
    #( m = largo-1)

   // convertir dígitos a base 20,la base de los mayas:
    iterar para( j=m, #(j>=1), --j )
         iterar para( i=1, #(i<=j), ++i )
              bit.and( #(ndígitos[i]), 1 ), por '10',
              guardar en 't'
              #( ndígitos[i+1] += t ) 
              #( ndígitos[i] = int(ndígitos[i]/2) )
         siguiente
    siguiente

    s=1
    iterar mientras ( #( ndígitos[s]==0 && s
        ++s
    reiterar
    
    
   // armar los cartuchos: 
    imprimir ( #(utf8("╔═════")),#(replicate( utf8("═════"), largo-s) ), #(utf8("═╗")), NL,\
               #(utf8("║┌────")),#(replicate( utf8("┬────"), largo-s) ), #(utf8("┐║")), NL )
    
    n=0
    iterar para ( l=3, #(l>=0), --l )

        imprimir (#(utf8("║")))
        iterar para ( i=s, #(i<=largo), ++i )
             si ( bit.or ( #(ndígitos[i]), l ), es igual a '0' )
                 imprimir ( #(utf8("│ Θ  ")) )
                 
             sino
                 guardar ' #(ndígitos[i]-5*l) ' en 'n'
                 si ( #(n>5) )
                     n=5
                 sino si ( n, es negativo? )
                     n=0
                 fin si
                 imprimir( #(utf8("│")), #(lsimb[n+1]) )
                 
             fin si
        siguiente
        imprimir (#(utf8("│║")),NL)
        
    siguiente

    imprimir ( #(utf8("║└────")),#(replicate( utf8("┴────"), largo-s) ), #(utf8("┘║")), NL,\ 
               #(utf8("╚═════")),#(replicate( utf8("═════"), largo-s) ), #(utf8("═╝")), NL )
    saltar

terminar


  

You may also check:How to resolve the algorithm Narcissistic decimal number step by step in the EasyLang programming language
You may also check:How to resolve the algorithm Even or odd step by step in the ALGOL W programming language
You may also check:How to resolve the algorithm Operator precedence step by step in the Haskell programming language
You may also check:How to resolve the algorithm Loops/For with a specified step step by step in the VBA programming language
You may also check:How to resolve the algorithm Harshad or Niven series step by step in the BASIC programming language