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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Mayan numerals step by step in the AutoHotkey 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 AutoHotkey programming language

Source code in the autohotkey programming language

MayanNumerals(num){
	pwr:=1, obj:=[], grid:=[]
	while (num // 20**pwr)
		pwr++	
	while --pwr
	{
		obj.Push(num // 20**pwr)
		num := Mod(num, 20**pwr)
	}
	obj.Push(num)
	cols := obj.count()
	loop % cols
	{
		c := A_Index
		loop 4
			grid[c, A_Index] := "    "
		grid[c, 4] := " Θ  "
	}
	
	for i, v in obj
	{
		j := 5
		loop % v//5
		{
			j := 5 - A_Index
			grid[i, j] := "————"
		}
		rem := ""
		loop % Mod(v, 5)
			rem .= "●"
		rem := rem = "●" ? " ●  " : rem = "●●" ? " ●● " : rem = "●●●" ? "●●● " : rem
		if Mod(v, 5)
			grid[i, j-1] := rem
	}
	return grid2table(grid, cols)
}

grid2table(grid, cols){
	loop, % cols-1
		topRow .= "════╦", bottomRow .= "════╩"
	topRow := "╔" topRow "════╗"
	bottomRow := "╚" bottomRow "════╝"
	loop % 4
	{
		r := A_Index
		loop % cols
			result .= "║" grid[A_Index, r]
		result .= "║`n"
	}
	result := topRow "`n" result . bottomRow
	return % result
}


for i, n in [4005, 8017, 326205, 886205, 194481]
{
	x := MayanNumerals(n)
	Gui, Font, S12, Consolas
	Gui, Add, Text, , % n
	Gui, Add, Text, y+0, % x
	Gui, Show, y100
	MsgBox, 262180, , continue with next number?
	IfMsgBox, No
		ExitApp
	Gui, Destroy
}


  

You may also check:How to resolve the algorithm Shell one-liner step by step in the min programming language
You may also check:How to resolve the algorithm Seven-sided dice from five-sided dice step by step in the Ruby programming language
You may also check:How to resolve the algorithm Metallic ratios step by step in the Java programming language
You may also check:How to resolve the algorithm Input loop step by step in the C programming language
You may also check:How to resolve the algorithm Smith numbers step by step in the Cowgol programming language