7 kyu

The 'spiraling' box

775 of 1,795brodiemark

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

Similar Kata:

More By Author:

Check out these other kata created by brodiemark

Stats:

CreatedJan 6, 2023
PublishedJan 6, 2023
Warriors Trained6779
Total Skips224
Total Code Submissions6538
Total Times Completed1795
Python Completions775
C Completions114
Java Completions276
C# Completions143
Swift Completions90
Go Completions116
Kotlin Completions87
Rust Completions51
JavaScript Completions198
C++ Completions48
Haskell Completions10
Total Stars130
% of votes with a positive feedback rating91% of 274
Total "Very Satisfied" Votes233
Total "Somewhat Satisfied" Votes30
Total "Not Satisfied" Votes11
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