Skip to main content

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
19 votes
10 answers
2k views

Search the deepest depths of an array

Given a ragged array, find the length of the largest subarray that contains the depth of that subarray. The base array layer has a depth of 0. Here is an example: ...
Larry Bagel's user avatar
  • 4,219
7 votes
5 answers
534 views

Multiply multivariate polynomials

We already have a challenge about multiplying multiply single-variable polynomials. This challenge is about multiply two polynomials with multiple variables Your task is given two multi-variable ...
bsoelch's user avatar
  • 6,035
14 votes
7 answers
1k views

Gödel encoding - Part II (decoding)

Part I Previous part was considered encoding of non-empty nested lists with a positive integer. Reminding the coding procedure \$G(x)\$: If \$x\$ is a number, \$G(x) = 2^x\$ If \$x\$ is a list \$[n_0,...
lesobrod's user avatar
  • 3,408
31 votes
18 answers
3k views

Gödel encoding - Part I

Related but different. Part II Taken from the book: Marvin Minsky 1967 – Computation: Finite and Infinite Machines, chapter 14. Background As the Gödel proved, it is possible to encode with a unique ...
lesobrod's user avatar
  • 3,408
4 votes
2 answers
201 views

Ragged list pattern matching, Part 2

This is a sequel to Ragged list pattern matching. In this challenge, the wildcard may match a sequence of items of any length instead of just a single item. Given a pattern and a ragged list of ...
alephalpha's user avatar
15 votes
9 answers
1k views

Zip ragged lists

In Haskell (and probably some other languages or something) zip is a function which takes two lists, and produces a list of tuples by pairing elements at the same ...
Wheat Wizard's user avatar
  • 100k
38 votes
11 answers
3k 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 ...
mousetail 'he-him''s user avatar
18 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 ...
Wheat Wizard's user avatar
  • 100k
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 ...
emanresu A's user avatar
  • 44.2k
8 votes
7 answers
745 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 ...
AnttiP's user avatar
  • 7,918
18 votes
26 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: ...
emanresu A's user avatar
  • 44.2k
22 votes
24 answers
3k 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 ...
emanresu A's user avatar
  • 44.2k
22 votes
30 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 ...
Amir reza Riahi's user avatar
14 votes
13 answers
784 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 ...
Wheat Wizard's user avatar
  • 100k
15 votes
14 answers
1k 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 ...
alephalpha's user avatar
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. ...
loopy walt's user avatar
  • 16.8k
21 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 ...
emanresu A's user avatar
  • 44.2k
15 votes
16 answers
778 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 ...
AnttiP's user avatar
  • 7,918
11 votes
4 answers
275 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 "...
AnttiP's user avatar
  • 7,918
3 votes
1 answer
338 views

Bracket Depth List

Challenge Your challenge is simple, calculate the depth of each matching brackets in the given input e.g. (()()(()))->...
DialFrost's user avatar
  • 5,107
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 ...
AnttiP's user avatar
  • 7,918
8 votes
14 answers
814 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 ...
DialFrost's user avatar
  • 5,107
16 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, ...
AZTECCO's user avatar
  • 10.9k
21 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 "...
Wheat Wizard's user avatar
  • 100k
13 votes
12 answers
359 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\...
Wheat Wizard's user avatar
  • 100k
15 votes
10 answers
986 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 ...
alephalpha's user avatar
18 votes
19 answers
764 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 ...
Wheat Wizard's user avatar
  • 100k
18 votes
8 answers
878 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 ...
Wheat Wizard's user avatar
  • 100k
14 votes
13 answers
991 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 ...
Wheat Wizard's user avatar
  • 100k
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 ...
Wheat Wizard's user avatar
  • 100k
23 votes
14 answers
1k 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 ...
Wheat Wizard's user avatar
  • 100k
21 votes
27 answers
2k 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 ...
caird coinheringaahin g's user avatar
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 ...
caird coinheringaahin g's user avatar
18 votes
20 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 ...
Wezl's user avatar
  • 1,486
27 votes
27 answers
3k 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 ...
pxeger's user avatar
  • 24.6k
23 votes
19 answers
2k views

Deep Search a List

For this challenge, a list is considered valid if and only if it consists entirely of integers and valid lists (recursive definitions \o/). For this challenge, given a valid list and an integer, ...
hyperneutrino's user avatar
  • 42.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 ...
Wheat Wizard's user avatar
  • 100k
42 votes
48 answers
6k 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 ...
Dennis's user avatar
  • 211k
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 ...
Jonathan Allan's user avatar
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 ...
ETHproductions's user avatar
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] ...
Arjun's user avatar
  • 5,084
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 ...
MrPublic's user avatar
  • 709
39 votes
54 answers
11k 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: ...
Martin Ender's user avatar
45 votes
23 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 ...
Martin Ender's user avatar