7 kyu

The 'spiraling' box

825 of 1,964brodiemark

Description:

Task

Given two positive integers m (width) and n (height), fill a two-dimensional list (or array) of size m-by-n in the following way:

  • (1) All the elements in the first and last row and column are 1.

  • (2) All the elements in the second and second-last row and column are 2, excluding the elements from step 1.

  • (3) All the elements in the third and third-last row and column are 3, excluding the elements from the previous steps.

  • And so on ...

Examples

Given m = 5, n = 8, your function should return

[[1, 1, 1, 1, 1],
 [1, 2, 2, 2, 1],
 [1, 2, 3, 2, 1],
 [1, 2, 3, 2, 1],
 [1, 2, 3, 2, 1], 
 [1, 2, 3, 2, 1],
 [1, 2, 2, 2, 1],
 [1, 1, 1, 1, 1]]

Given m = 10, n = 9, your function should return

[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
 [1, 2, 2, 2, 2, 2, 2, 2, 2, 1],
 [1, 2, 3, 3, 3, 3, 3, 3, 2, 1], 
 [1, 2, 3, 4, 4, 4, 4, 3, 2, 1], 
 [1, 2, 3, 4, 5, 5, 4, 3, 2, 1], 
 [1, 2, 3, 4, 4, 4, 4, 3, 2, 1], 
 [1, 2, 3, 3, 3, 3, 3, 3, 2, 1], 
 [1, 2, 2, 2, 2, 2, 2, 2, 2, 1], 
 [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]

Bird mountain generalizes this kata in a fun way.

Arrays
Fundamentals

More By Author:

Check out these other kata created by brodiemark

Stats:

CreatedJan 6, 2023
PublishedJan 6, 2023
Warriors Trained7342
Total Skips241
Total Code Submissions7177
Total Times Completed1964
Python Completions825
C Completions115
Java Completions295
C# Completions148
Swift Completions98
Go Completions128
Kotlin Completions91
Rust Completions58
JavaScript Completions244
C++ Completions71
Haskell Completions10
Scala Completions5
Total Stars136
% of votes with a positive feedback rating90% of 287
Total "Very Satisfied" Votes243
Total "Somewhat Satisfied" Votes32
Total "Not Satisfied" Votes12
Total Rank Assessments12
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • brodiemark Avatar
  • JohanWiltink Avatar
  • hobovsky Avatar
  • trashy_incel Avatar
  • akar-0 Avatar
  • dfhwze Avatar
  • tobeannouncd Avatar
  • dnskkv Avatar
Ad