# Questions tagged [array]

A competition to solve a particular problem through the usage and manipulation of arrays.

262 questions
Filter by
Sorted by
Tagged with
7k views

### Random Golf of the Day #1: Shuffle an Array

About the Series I will be running a little series of code-golf challenges revolving around the theme of randomness. This will basically be a 9-Hole Golf Course, but spread out over several questions....
• 196k
4k views

### Boustrophedonise

Related but very different. A boustrophedon is a text where every other line of writing is flipped or reversed, with reversed letters. In this challenge, we will just reverse every other line, but ...
• 30.1k
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: ...
• 196k
7k views

### N-dimensional N^N array filled with N

In: Enough memory and a positive integer N Out: N-dimensional N^N array filled with N, where N^N means N terms of N-by-N-by-N-by... Examples: 1: [1] ...
• 30.1k
3k views

### Different Way Forward

Given a list of integers produce a Forward Difference at a specified order/depth. For the list of integers: (10, 18, -12, 4, 8, -3, -5, 67, 9, 14) The Forward ...
• 12.2k
6k views

### Zigzagify a Matrix

As part of its compression algorithm, the JPEG standard unrolls a matrix into a vector along antidiagonals of alternating direction: Your task is to take a matrix (not necessarily square) and return ...
• 196k
4k views

### Determinant of an Integer Matrix

Given a square integer matrix as input, output the determinant of the matrix. Rules You may assume that all elements in the matrix, the determinant of the matrix, and the total number of elements in ...
4k views

### Shortest power set implementation

Problem definition Print out the powerset of a given set. For example: [1, 2, 3] => [[], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]] Each element is to ...
• 381
721 views

### Advent Challenge 1: Help Santa unlock his present vault!

Next >> Descriptive Keywords (for searching): Make Two Matrices Equivalent, Overlap, Array, Find Challenge Santa has had a history of elves stealing presents from his vault in the past, so this ...
• 41.4k
3k views

### Cartesian product of a list with itself n times

When given a a list of values and a positive integer n, your code should output the cartesian product of the list with itself n ...
• 447
4k views

### Count trailing truths

Inspired by, and in memory of, my dear friend and colleague, Dan Baronet, 1956 – 2016. R.I.P. He found the shortest possible APL solution to this task: Task Given a Boolean list, count the number of ...
• 30.1k
8k views

### Mode (most common element) of a list

Write a snippet to calculate the mode (most common number) of a list of positive integers. For example, the mode of d = [4,3,1,0,6,1,6,4,4,0,3,1,7,7,3,4,1,1,2,8] ...
• 709
3k views

### Diamondize a Matrix

Given a matrix, output a representation of the matrix where the top left element is on top, the anti-diagonal is the central row and the bottom right element is at the bottom. For example, consider ...
• 38.5k
2k views

### Discrete Convolution or Polynomial Multiplication

Given two non empty lists of integers, your submission should calculate and return the discrete convolution of the two. Interestingly, if you consider the list elements as coefficients of polynomials, ...
• 43.8k
8k views

### Turn an integer n into a list containing it n times [closed]

Given an integer n as input, return a list containing n, repeated n times. For example, the ...
• 425
4k views

### Skip like a rabbit!

Given a list of non-negative integers in any reasonable format, iterate over it, skipping as many elements as every integer you step on says. Here is a worked example: ...
• 40.5k
3k views

### Rotate the anti-diagonals

Background In most reasonable programming languages, it's very easy to rotate the rows or columns of a 2D array. In this challenge, your task is to rotate the anti-diagonals instead. Recall that the ...
• 42.6k
4k views

### Bit-Reversal Permutations

Your goal is to create a function or a program to reverse the bits in a range of integers given an integer $n$. In other words, you want to find the bit-reversal permutation of a range of $2^n$ ...
• 16.9k
4k views

### Non-Unique/Duplicate Elements

Write a program which finds the non-unique elements of an array of signed integers. The resulting array can be in any order. Your answer may be a snippet which assumes the input to be stored in a ...
• 709
1k views

### Fluctuating ranges

Given a list with number, output the ranges like this: Input: [0, 5, 0] would become [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0]. This ...
• 949
10k views

### Lossy Sorting (Implement Dropsort)

Dropsort, designed by David Morgan-Mar, is an example of a linear-time "sorting algorithm" that produces a list that is, in fact, sorted, but contains only some of the original elements. Any ...
• 11.9k
3k views

### Fold a List in Half

We are going to fold a list of integers. The procedure to do so is as follows, If the list is of even length, make a list of half of its length where the nth item of the new list is the sum of the ...
• 97.8k
5k views

### Index of a multidimensional array

Lower level languages, such as C and C++ actually have no concept of multidimensional arrays. (Other than vectors and dynamic arrays) When you create a multidimensional array with ...
• 59k
2k views

### Ordering a list

Summary Given a list of integers, return the index each integer would end up at when sorted. For example, if the list was [0,8,-1,5,8], you should return ...
• 14.4k
970 views

### Reconstruct a zigzagified matrix

As part of its compression algorithm, the JPEG standard unrolls a matrix into a vector along antidiagonals of alternating direction: Your task is to take the unrolled vector along with the matrix ...
• 196k
2k views

### Counting in bijective base 62

The task is to generate all the strings from 'a' to '999' including upper case characters like so: ...
• 441
2k views

### We do tower hopping

Task Given an array of non-negative integers a, determine the minimum number of rightward jumps required to jump "outside" the array, starting at position ...
• 800
3k views

### Flood-fill a 2D grid

Challenge description Let's call a two-dimentional, rectangular array (meaning its every subarray has the same length), a grid. Every unit of a grid is either an empty space or a border. In a grid of ...
• 5,642
2k views

### How to swap elements in a vector using an anonymous function in Octave?

Swapping two elements in a vector/matrix is very simple in Octave: x='abcde'; x([4,1])=x([1,4]) x = dbcae Unfortunately, I have yet to find a way to do this ...
• 46.2k
1k views

### Operations with Lists

Inspired by this question. Given a list containing numbers, print: The sum and product of the numbers in the list The average and median The differences between each term in the list (e.g. ...
• 4,310
3k views

### Cover up zeroes in a list

Inspired by this SO question As input you will be given a non-empty list of integers, where the first value is guaranteed to be non-zero. To construct the output, walk from the start of the list, ...
• 17.5k
6k views

### First code golf decathlon [closed]

Tasks All competitors try to solve the following list of 10 tasks: math Read a positive integer n from input and return the sum of the cubes of the first n non-negative integers. For input ...
• 210k
13k views

### Cheating a multiple choice test

Introduction While studying, I tried to come up with several ways to cheat a multiple choice test. It basically is a compressed version of the multiple choice answers. The method goes as following: ...
• 44.3k
4k views

### Hollow out an array

The task This challenge is very simple. Your input is a rectangular 2D array of integers, sized at least 1×1. It can be taken in any reasonable format. Your output shall be the input array, but ...
• 42.6k
3k views

### Swap the two given indices [duplicate]

Given an array of positive integers and two distinct valid indices, return the array with the two elements corresponding to the two indices swapped. You may choose to use 0-indexing or 1-indexing, ...
• 49.7k
3k views

### Iterated partial sums

The partial sums of a list of integers [a1, a2, a3, ..., an] are s1 = a1 s2 = a1 + a2 s3 = a1 + a2 + a3 ... sn = a1 + a2 + ... + an We can then take the list of partial sums [s1, s2, s3, ..., sn] ...
• 145k
3k views

### Print a Block-Diagonal Matrix

Here is a simple, bite-sized (byte-sized?) code golf: given a non-empty list of positive integers less than 10, print a block-diagonal matrix, where the list specifies the size of the blocks, in order....
• 196k
3k views

### Swap Two Values in a List

Introduction: Although we have a lot of challenges where swapping two items in a list is a subtask, like Single swaps of an array; Swap to Sort an Array; $n$ swaps into a nop; etc., we don't have ...
• 125k
3k views

### Find the unique twins

You will be given two Arrays / Lists / Vectors of non-negative integers A and B. Your task is to output the highest integer N that appears in both A and B, and is also unique in both A and B. You ...
• 42.4k
5k views

Terms A worm is any list of nonnegative integers, and its rightmost (i.e., last) element is called the head. If the head is not 0, the worm has an active segment consisting of the longest contiguous ...
• 3,112
3k views

### All the single eights

Given a non-empty rectangular array of integers from 0 to 9, output the amount of cells that are ...
• 104k
2k views

### Is it a tower permutation?

A tower is made out of layers, each one being one unit shorter than the one below it. Every layer is completely on top of the previous layer. For example, here is a tower along with it's height map: <...
• 7,848
984 views

### Rank a list of scores with "skips"

Given a list of scores (non-negative integers) pre-sorted from greatest to least: [ 10, 10, 6, 6, 4, 0] Assign each score an integer rank, beginning with 1 ...
• 9,864
6k views

### Xorting an array

Conceptually, this challenge is really simple. You're given a list of non-negative integers ai. If possible, find a non-negative integer ...
• 196k
8k views

### 2048-like array shift

Assume we want to shift an array like it is done in the 2048 game: if we have two equal consecutive elements in array, merge them into twice the value element. Shift must return a new array, where ...
• 1,051
6k views

### The shortest way to find one unique value when all other values are the same

In this question at Code Review they tried to find the fastest way to return the unique element in an array where all the elements are the same except one. But what is the shortest code that ...
• 12.9k
8k views

### Am I an insignificant array?

An insignificant array is an array of positive integers, where the absolute differences between consecutive elements are all smaller than or equal to 1. For example, the following array is ...
4k views

### An Array of Challenges #1: Alternating Arrays

Alternating Arrays An alternating array is a list of any length in which two (not necessarily different) values are alternating. That is to say, all even-indexed items are equal, and all odd-indexed ...
• 14.6k
9k views

### Remove leading and trailing zeroes

Given a non-empty list/array containing only non-negative integers like this: [0, 0, 0, 8, 1, 4, 3, 5, 6, 4, 1, 2, 0, 0, 0, 0] Output the list with trailing and ...
• 949