Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

80%
+6 −0
Challenges Shape of an array

Given a non-ragged array (an array where all sub-arrays at a particular level have the same length) of non-negative integers, answer its shape, that is, the length along every dimension. You may as...

6 answers  ·  posted 4y ago by Adám‭  ·  last activity 2y ago by south‭

Question code-golf
#2: Post edited by user avatar Adám‭ · 2020-11-22T15:28:35Z (almost 4 years ago)
  • Given a non-ragged array (an array where all sub-arrays at a particular level have the same length), answer its shape, that is, the length along every dimension. You may assume that the given array has at least one empty dimension, and that only the trailing dimension can have length 0.
  • ### Test cases
  • `[]` → `[0]`
  • `[0]` → `[1]`
  • `[[]]` → `[1,0]`
  • `[[],[]]` → `[2,0]`
  • `[[4,4],[0,3]]` → `[2,2]`
  • `[[[4],[6]]]` → `[1,2,1]`
  • `[[[[7],[0]]]]` → `[1,1,2,1]`
  • Given a non-ragged array (an array where all sub-arrays at a particular level have the same length) of non-negative integers, answer its shape, that is, the length along every dimension. You may assume that the given array has at least one empty dimension, and that only the trailing dimension can have length 0.
  • ### Test cases
  • `[]` → `[0]`
  • `[0]` → `[1]`
  • `[[]]` → `[1,0]`
  • `[[],[]]` → `[2,0]`
  • `[[4,4],[0,3]]` → `[2,2]`
  • `[[[4],[6]]]` → `[1,2,1]`
  • `[[[[7],[0]]]]` → `[1,1,2,1]`
#1: Initial revision by user avatar Adám‭ · 2020-11-22T13:11:48Z (almost 4 years ago)
Shape of an array
Given a non-ragged array (an array where all sub-arrays at a particular level have the same length), answer its shape, that is, the length along every dimension. You may assume that the given array has at least one empty dimension, and that only the trailing dimension can have length 0.

### Test cases

`[]` → `[0]`

`[0]` → `[1]`

`[[]]` → `[1,0]`

`[[],[]]` → `[2,0]`

`[[4,4],[0,3]]` → `[2,2]`

`[[[4],[6]]]` → `[1,2,1]`

`[[[[7],[0]]]]` → `[1,1,2,1]`