21
1
Write a program or function which, given a positive integer as input, outputs the representation of that integer in Maya numerals.
Maya numerals
Maya numerals is a vigesimal system (base 20) using only 3 symbols :
< >
for Zero (The correct symbol is some sort of shell that can't easily be represented using ASCII)..
for One----
for Five
Numbers are written vertically in powers of 20, and numbers between 0 and 19 are written as stacks of fives and ones. You shall refer to the Wikipedia article for more details.
As an example, here are the numbers between 0 and 25, separated by commas:
. .. ... ....
. .. ... .... ---- ---- ---- ---- ---- . . . . . .
. .. ... .... ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
< >, . , .. ,... ,....,----,----,----,----,----,----,----,----,----,----,----,----,----,----,----,< >, . , .. ,... ,....,----
Inputs
- Inputs always are positive integers between 0 and 2147483647 (2^31 - 1).
- You may take the input from STDIN, as a command line argument, function parameter or anything similar.
Outputs
- Each line is at most 4 characters long.
< >
and----
should always be printed as given here (4 characters long each). - Ones(
.
) must be centered on the line. If there are 1 or 3.
, since perfect horizontal alignment is impossible, it does not matter whether they are one column to the left or one column to the right or the center. There must be exactly one empty line between different powers of 20, regardless of the height of the stacks in the power of 20s. For example, the correct output for 25 and 30 are :
. . ---- ---- ----
No leading or trailing lines allowed.
Outputs must be printed exactly like they are in the examples given.
Test cases
Each individual number between 0 and 25 given as example above.
Input:
42
Output:
..
..
- Input:
8000
Output:
.
< >
< >
< >
- Input:
8080
Output:
.
< >
....
< >
- input:
123456789
Output:
.
...
----
----
----
.
----
----
..
----
----
.
....
----
----
----
....
----
- Input:
31415
Output:
...
...
----
----
----
----
----
----
----
----
- Input:
2147483647
Output:
.
...
----
----
.
----
----
.
----
----
----
....
----
..
..
----
Scoring
This is code-golf, so the shortest code in bytes wins.
15 and 20 appear to be identical. – isaacg – 2015-08-04T16:16:24.793
@isaacg Thanks, I actually had 15 appearing both at the right spot and also between 19 and 20. Fixed. – Fatalize – 2015-08-04T16:19:09.707
@Fatalize Does the output need to be printed (i.e. STDOUT) or can my function just return the output? – rink.attendant.6 – 2015-08-04T17:52:33.010
@rink.attendant.6 Must be printed exactly like they are in the post. – Fatalize – 2015-08-04T18:23:12.980
Is it ok if 1 is one column to the right, but 3 is one column to the left? – aragaer – 2015-08-06T16:45:58.063
@aragaer yes it's fine – Fatalize – 2015-08-06T16:51:44.947
And another one - is it ok to have a trailing newline? Basically we're operating lines here, so it would make sense if the last line was actually a line. – aragaer – 2015-08-06T17:18:08.827
@aragaer The "No trailing or leading lines" rule has been included since the beginning of the challenge, so to be fair to other participants I can't remove it. So no – Fatalize – 2015-08-06T17:22:17.207
For "digits" that are multiples of 5, I'm assuming that an extra blank line isn't acceptable: That is, for the number 35, there must be exactly one blank line between the line with the single dot, and the first of the three lines of dashes. Correct? – MtnViewMark – 2015-08-10T01:03:36.057
@MtnViewMark correct – Fatalize – 2015-08-10T05:50:00.423
Is it possible to return a 2D list of lines? (Jelly solution) – user202729 – 2018-04-06T02:45:19.593