5 kyu

[Code Golf] Fill matrix with a zigzag

Description:

About

In this task, you will write a "determinateValue" function that will determine the value of an element in a matrix. The matrix should be filled with a zigzag, example matrix 5x5:

  [
    [ 1,  2,  6,  7, 15],
    [ 3,  5,  8, 14, 16],
    [ 4,  9, 13, 17, 22],
    [10, 12, 18, 21, 23],
    [11, 19, 20, 24, 25]
  ]

In example above if x = 2, y = 1 and n = 5, result should be 9 ( matrix[2][1] = 9 )

The function "determinateValue" will be called to determine the value of each element in the matrix, it is passed three parameters:

  • x - index of array position (vertical index).
  • y - index of element position in array (horizontal index).
  • n - Matrix size.

Simple "code golf" conditions:

  • C# - 250 chars limit.
  • JS - 150 chars limit.
  • Python - 160 chars limit.

Note

  • Matrices can be very large.
  • Values must not go beyond the matrix (filling in the form of a big triangle will not work).

The direction of filling, for clarity.

co-author

Matrix
Algorithms
Restricted

Similar Kata:

Stats:

CreatedMay 24, 2022
PublishedMay 24, 2022
Warriors Trained323
Total Skips14
Total Code Submissions1008
Total Times Completed56
C# Completions11
Python Completions34
JavaScript Completions24
Total Stars28
% of votes with a positive feedback rating93% of 20
Total "Very Satisfied" Votes17
Total "Somewhat Satisfied" Votes3
Total "Not Satisfied" Votes0
Total Rank Assessments9
Average Assessed Rank
5 kyu
Highest Assessed Rank
3 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • AndreyMaksimov Avatar
  • hobovsky Avatar
  • dfhwze Avatar
Ad