Questions tagged [ragged-list]

A ragged list, also called a jagged list, is a list where each element can either be some terminal type (e.g. an integer) or another ragged list.

Filter by
Sorted by
Tagged with
34 votes
10 answers
2k views

Re-name all identifiers to a single letter

Imagine a very simple language. It has just 2 syntax features: () indicates a block scope, and any word consisting only of 1 or more lower case ASCII letters, which ...
  • 2,833
17 votes
25 answers
2k views

Is it a properly tiered list?

A ragged list is a (finite depth) list where each element is either a positive integer or a ragged list. A ragged list is properly tiered if it contains either all positive integers or all properly ...
  • 90k
19 votes
21 answers
2k views

Multiply numbers by their depth

Given a ragged list, we can define an element's depth as the number of arrays above it, or the amount that it is nested. For example, with the list ...
  • 31.9k
8 votes
7 answers
668 views

Is it an ordinal?

Background (feel free to skip) Ordinals are the abstract representation of well-orders. A well-order of a set is a total order, which basically means that every element in the set can be compared ...
  • 6,775
18 votes
25 answers
2k views

Is it a valid list?

Given a string like [[[],[[]]],[]], made of only commas and square brackets, your challenge is to determine whether it represents a list. A list is either: ...
  • 31.9k
22 votes
23 answers
2k views

Iteratively delete a list

Say I have a ragged list, like: [ [1, 2], [3, [4, 5] ] ] And I want to iterate over each item and delete it one-by-one. However, I don't know the ...
  • 31.9k
20 votes
21 answers
3k views

Make a list flat

Lists can contain lists and we have nested lists. But we don't like nested lists and want to flatten them. By flattening I mean create a list which does not contain any list, but elements of lists it ...
14 votes
13 answers
751 views

Find the dimensions of a ragged list

For any ragged list its dimensions will be a list of non-negative integers defined as follows: Elements that are not a list will have dimensions \$\textbf{[}\,\,\textbf{]}\$. An empty list has ...
  • 90k
14 votes
13 answers
992 views

Ragged list pattern matching

Given a pattern and a ragged list of positive integers, your task is to decide whether the pattern matches the ragged list. The pattern is also represented by a ragged list. But in addition to ...
  • 37.4k
15 votes
13 answers
1k views

Recursively rotate a ragged list

Given a ragged list of positive integers return a full cycle of recursive rotations starting with the unchanged input and ending with the state immediately before revisiting the initial state. ...
  • 9,238
22 votes
14 answers
2k views

Sort numbers in a ragged list

Given a ragged list, e.g. [[4, 7], [5, 3, [], [6, [2]]]] Your challenge is to sort only the numbers in it. For example, with the above, the result would be ...
  • 31.9k
16 votes
16 answers
755 views

Ragged index of

Your input is a ragged list of positive integers and a positive integer. Your task is to find that positive integer and return it's index, or if the positive integer doesn't exist, indicate it's ...
  • 6,775
11 votes
4 answers
264 views

Decompress a ragged list

Your input is a ragged list of possibly empty lists of non-negative integers. For example, [[2,0],[[]],[[[],[1],[]],[]]] is a valid input. This input is a "...
  • 6,775
3 votes
1 answer
302 views

Bracket Depth List

Challenge Your challenge is simple, calculate the depth of each matching brackets in the given input e.g. (()()(()))->...
  • 3,049
22 votes
12 answers
1k views

Inverted ragged list

Given a ragged list of positive integers, where the maximum depth is \$d_\text{max}\$, return the same list, except for every element \$e\$, its depth is \$d_\text{max}+1-d_e\$ (where \$d_e\$ is the ...
  • 6,775
7 votes
12 answers
702 views

Ragged Matrix Indexing

A ragged matrix, is a matrix that has a different number of elements in each row. Your challenge is to write a program in any favorable language to find the indices of all occurrences of target in the ...
  • 3,049
15 votes
14 answers
1k views

Count count count

Description You have a list of integers and start counting from the first term to the next and continue from that to the next and so on.. How many times have you counted? For example given [ 2, 5, 3, ...
  • 9,806
20 votes
14 answers
1k views

Build a list from a depth map

You will be given as input a non-empty list of positive integers. For example: [1,2,2,2,1] You want to produce a ragged list as output which has this as its "...
  • 90k
8 votes
8 answers
277 views

Products all the way down

You are probably familiar with the Cartesian product. It takes two lists and creates a list of all pairs that can be made from an element of the first and an element from the second: \$ \left[1,2\...
  • 90k
15 votes
9 answers
754 views

Array depth of a ragged list

This is not a duplicate of this challenge. Here by an array, I mean a nested list that is "not ragged", i.e., it is either a list of elements, or a list of arrays of the same shape. For ...
  • 37.4k
18 votes
19 answers
742 views

Minimum depth of a ragged list

As input you will be given a ragged list of positive integers containing at least one integer at some level. For example: [[],[[1,2,[3]]],[]] You should output ...
  • 90k
18 votes
8 answers
855 views

Make every fixed list

We are to define the idea of a fixed list as follows: A fixed list is a list of fixed lists. This definition is recursive so it's useful to look at some examples. The empty list ...
  • 90k
15 votes
13 answers
957 views

Compare shapeless lists

Let's have a ragged list containing no values, only more lists. For example: [[[],[[]],[],[]],[],[[],[],[]],[]] And the list will be finite, meaning that ...
  • 90k
22 votes
22 answers
1k views

Find the maximum length in a ragged list

Given a ragged list of positive integers find the size of the largest list contained somewhere in it. For example: [1,[1,[8,2,[1,2],5,4,9]],2,[],3] Here the answer ...
  • 90k
18 votes
13 answers
992 views

Scan a ragged list

hgl has a "scan" function called sc. What it does in general is a little bit abstract, so we will just talk about one specific way you can use it. If we ...
  • 90k
22 votes
24 answers
1k views

Collect the elements of an array

Add++, the Language of the Month, has the "collect" builtin as BC. Your task is to implement this builtin. Consider a non-empty array, where each element ...
23 votes
17 answers
2k views

Reconstruct a recursively prime-encoded integer

Recursively prime-encoded integers Consider \$11681169775023850 = 2 \times 5 \times 5 \times 42239 \times 5530987843\$. This isn't a nice prime factorisation, as \$42239\$ and \$5530987843\$ make it ...
18 votes
19 answers
3k views

cadaddadadaddddaddddddr - linked list accessing

Create a function (or closest equivalent, or full program) that takes an list of some datatype (your choice) that may be nested and a string (in either order), and generalizes the lisp c[ad]+r ...
  • 1,450
27 votes
26 answers
2k views

Pad a jagged array to be square

Given a 2-dimensional jagged array and a fill value, pad the array in both dimensions with the fill value to ensure that it is square and not jagged (i.e., all rows are the same length, and that ...
  • 22.6k
26 votes
7 answers
1k views

Decode the Void

A void list is a list that at no level contains any non-list objects. Or if you prefer a recursive definition The empty list is void A list containing only other void lists is void All void lists ...
  • 90k
36 votes
41 answers
5k views

Is it true? Ask Jelly!

Background Inspired by Octave's (and, by extension, MATL's) very convenient interpretation of truthy/falsy matrices, Jelly got the Ȧ (Octave-style all) atom. Ȧ takes an array as input and returns 1 ...
  • 207k
22 votes
20 answers
2k views

Find the "Recursive Size" of a List

Inspired by Find the “unwrapped size” of a list. Define the Recursive Size, RS, of a list containing no lists as its length (number of items contained) and the ...
33 votes
10 answers
2k views

B​u​i​l​d a n​e​s​t

The challenge is simple: write a program or function that, when given a finite non-negative integer, outputs a nested array. The rules Your code must produce a unique valid nested array for every ...
36 votes
36 answers
8k views

Flatten the Array! [duplicate]

In this challenge, your task is to create a program which takes in a nested array and returns a single-dimensional flattened array. For Example [10,20,[30,[40]],50] ...
  • 4,978
15 votes
17 answers
2k views

Reverse an N-Dimensional array

Details Write a function or program that, given an array (or list), containing only integers, returns or output an array with all sub-elements reversed. That is, reverse all elements of the deepest ...
  • 709
38 votes
51 answers
10k views

Determine the depth of an array

A simple challenge for your Monday evening (well, or Tuesday morning in the other half of the world...) You're given as input a nested, potentially ragged array of positive integers: ...
44 votes
21 answers
7k views

Unflatten an Array

This challenge was inspired by a question on Mathematica.SE. Say you've got a nested list/array of some arbitrary structure (the lists at each level don't necessarily have the same length). For ...