9
2
Groups are a widely used structure in Mathematics, and have applications in Computer Science. This code challenge is about the fewest # of characters to create a group table for the additive group Zn.
How the table is constructed: For Zn, the elements are {0, 1, 2, ..., n-1}. The table will have n rows and n columns. For the ij-th entry of the table, the value is i+j mod n. For example, in Z3, the 1-2nd entry (2nd row, 3rd column if you count the starting row/column as 1) is (1+2)%3 = 0 (see sample output).
Input: a positive integer, n
Output: a table that is a textual presentation of Zn, constructed as described above, and displayed as shown below in the sample outputs. Spaces are optional
Sample input: 3
Sample output:
0 1 2
1 2 0
2 0 1
Sample input: 5
Sample output:
0 1 2 3 4
1 2 3 4 0
2 3 4 0 1
3 4 0 1 2
4 0 1 2 3
3Since the separator is optional, will there be an input above 10? – Jo King – 2019-01-13T03:51:51.147
@JoKing based on https://codegolf.stackexchange.com/questions/35038/generate-the-group-table-for-z-n#comment75701_35039 I guess yes
– qwr – 2019-01-14T18:22:46.500