Questions tagged [array-manipulation]

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

Filter by
Sorted by
Tagged with
7
votes
4answers
388 views

Sort a list, poorly

Don't you hate it when you're trying to roughly sort a list based on user data, but you have to poll the user for thousands of comparisons? Hate no more, because the answers to this challenge are (...
1
vote
9answers
286 views

Finding the period of a recurring element in an array [closed]

Given an array A of integers, there exists at least one positive integer p such that A[i] == A[j] for all ...
9
votes
1answer
270 views

Dyadic Transpose

As with most APL symbols, has different meanings when called with one argument (transpose) versus two arguments (dyadic transpose / reorder dimensions). This ...
24
votes
15answers
2k views

All the single eights

Given a non-empty rectangular array of integers from 0 to 9, output the amount of cells that are ...
12
votes
6answers
650 views

Determine the Widest Valley

Imagine we get a slice of some mountainous region, this would result in a shape similar to this: ...
19
votes
3answers
364 views

Count cyclically self-describing lists

Cyclically self-describing lists A list \$L\$ of positive integers is cyclically self-describing, if the following conditions hold. \$L\$ is nonempty. The first and last elements of \$L\$ are ...
19
votes
10answers
2k views

Repeat this GCD operation

Problem A3 from the 2008 Putnam competition says: Start with a finite sequence \$a_1, a_2, \dots, a_n\$ of positive integers. If possible, choose two indices \$j < k\$ such that \$a_j\$ does not ...
21
votes
15answers
4k views

My array should equal this, but it doesn't!

Given an array of integers a which contains n integers, and a single integer x; remove the fewest amount of elements from ...
13
votes
16answers
2k views

Trim that distracting background off!

Isn't it annoying when you're taking a picture, but the background detracts from the actual substance of the image? I'd say it is. I need to know how much I should crop so that I get rid of this ...
4
votes
10answers
477 views

Smoothing a pair of arrays

Input Two lists with binary values (list_a, list_b) of equal length=>3. Output Two lists with binary values ...
-4
votes
20answers
403 views

Array indexes to number and number reversed

Given an input array having minimum length 2 and maximum length 9 having any initial values output an array having length ...
18
votes
7answers
825 views

Find an array that fits a set of sums

Consider an array A of length n. The array contains only positive integers. For example ...
9
votes
24answers
952 views

Multiplicative undelta

Let us define the "multiplicative deltas" of values \$[\; a_0, \cdots a_N, \;]\$ as: $$ [\; a_1 / a_0, \cdots, a_{i+1} / a_i, \cdots, a_N / a_{N-1} \;] $$ The reverse operation - namely "...
15
votes
9answers
613 views

Stagger, stack, sum

Inspired by this Stack Overflow question. The challenge Input An array of square matrices containing non-negative integers. Output A square matrix built from the input matrices as follows. Let \$...
26
votes
23answers
2k views

Equalize the array

Challenge You are given an array \$a\$ of integers. With a move you can increase or decrease an element of the array by 1. Your task is to equalize the array, that is make all the elements of the ...
16
votes
2answers
507 views

Rubik-sorting a matrix (a.k.a. the torus puzzle)

The idea for this code-challenge is simple: given a matrix of integers, let's sort it by applying Rubik-style movements. This means that you can select a single row or column and rotate its elements ...
10
votes
7answers
651 views

Whose neighbours are hostile?

Introduction For the purposes of this challenge, we will define the neighbours of an element \$E\$ in a square matrix \$A\$ (such that \$E=A_{i,j}\$) as all the entries of \$A\$ that are immediately ...
15
votes
22answers
1k views

Block-sorting rows and columns in a 2D array

Given a 2D array of integers, let's sort its rows and columns in blocks. This means that you only have to sort a given row or column, but applying the transformations needed for sorting it to every ...
21
votes
14answers
2k views

Chop off the matrix to get the desired sum

Definition Given a matrix \$M\$ of non-negative integers and a non-negative integer \$k\$, we define \$F_k\$ as the "chop-off" function that removes all rows and all columns in \$M\$ that contain \$k\...
16
votes
24answers
2k views

Check my tunneling arrays

Imagine you have an array of integers, whose non-negative values are pointers to other positions in the same array, only that those values represent tunnels, so if the value in position A is positive ...
23
votes
15answers
2k views

Multi-dimensional reversal

Given an N-dimensional orthogonal (non-ragged) array of non-negative integers, and an indication of which dimensions to reverse, return the array but reversed along those dimensions. The indication ...
14
votes
16answers
1k views

Find Array Runs

Find the runs inside an array A run is defined as three or more numbers that increment from the previous with a constant step. For example [1,2,3] would be a run with step 1, [1,3,5,7] would be a run ...
9
votes
6answers
477 views

Codegolf Rainbow : Sorting Colors with Reflection

Introduction: After I posted two rainbow-related challenges: Codegolf Rainbow : Fun with Integer-Arrays 1 and Codegolf Rainbow : Draw in Black-and-White 2, the following comment was made by @ChrisM ...
15
votes
21answers
1k views

Fill up to duplicate ranges

Let \$L\$ be a list of positive integers with no particular ordering, and which can contain duplicates. Write a program or function which outputs a list of positive integers \$M\$ (whose ordering is ...
20
votes
11answers
2k views

A knight's graph on an N-by-N board

In chess, a knight can only move to the positions marked with X relative to its current position, marked with ♞: A Knight's Graph is a graph that represents all legal moves of the knight chess piece ...
8
votes
15answers
798 views

Scoring 6,5,4 (AKA Ship, Captain, and Crew)

Inspired and looted from this dice challenge by Arnauld Input You are given a 5x1 or 1x5 (your choice) dice matrix which consist of binary 3x3 sub-matrices. Goal Given a valid dice matrix, you are ...
28
votes
29answers
3k views

Most Common Multiple

Not to be confused with Least Common Multiple. Given a list of positive integers with more than one element, return the most common product of two elements in the array. For example, the MCM of the ...
11
votes
5answers
328 views

Minimal Centrosymmetrization

Topically related. Objective: Given a matrix of positive integers \$M\$, output the smallest centrosymmetric matrix which contains \$M\$ (this matrix may contain non-positive integers as well). A ...
6
votes
1answer
102 views

Make the super number hyper-pyramid [duplicate]

Challenge Given a positive integer \$n\$, output the \$n\$-dimensional pyramidal list. Example \$n = 1\$: Objects arranged in a 1D pyramid (line) with side length 1 is just by itself. So, the ...
14
votes
5answers
308 views

Optimal Caching

You will be given a sequence of memory requests and a cache size. You must return the least possible number of cache misses under any cache replacement strategy. An optimal strategy is Belady's ...
21
votes
9answers
2k views

How much is my dice matrix worth?

Input A non-empty binary matrix consisting of 3x3 sub-matrices put side by side. Task Your task is to identify valid dice patterns (as described below) among the 3x3 sub-matrices. Each valid ...
40
votes
32answers
3k views

Remove surrounding zeroes of a 2d array

This is a 2-dimensional version of this question. Given a non-empty 2-dimensional array/matrix containing only non-negative integers: $$ \begin{bmatrix} {\color{Red}0} & {\color{Red}0} & {\...
44
votes
76answers
8k views

Implementing a stack

I can't believe we don't have this already.. It's one of the most important data-structures in programming, yet still simple enough to implement it in a code-golf: Challenge Your task is to ...
5
votes
4answers
382 views

Einstein's Sorter

Challenge Given a list of integers and a velocity, \$v\$, implement a sorting algorithm which simulates a program sorting the list from smallest to biggest at the given velocity. Einstein's Theory ...
14
votes
3answers
494 views

Multi-level free parking space finder

Kids-related intro Whenever I take my kids to an amusement park, the kids get more nervous the closer we are to the park, with the nerve peak when we are in the parking lot and find no place to park. ...
37
votes
28answers
4k views

Is the matrix centrosymmetric… and so is the code?

Defintion A centrosymmetric matrix is a square matrix that is symmetric about its center. More rigorously, a matrix \$A\$ of size \$n \times n\$ is centrosymmetric if, for any \$i,\: j \in ([1, n] \...
9
votes
10answers
600 views

Tuples by sequentially stepping through entries in list of lists

Challenge: Given a list of nonempty lists of integers, return a list of tuples of the following form: First list tuples starting with each element of the first list followed by the first element of ...
11
votes
13answers
1k views

First Last Last First

Challenge The task is simple. Given an array and a first and last value: Return the first of the last after the first, and the last of the first before the last. Or simply: Given an array, var1, ...
12
votes
11answers
716 views

Find the minimum cost matching between arrays of integers

Consider two sorted arrays of integers \$X\$ and \$Y\$ of size \$m\$ and \$n\$ respectively with \$m < n\$. For example \$ X = (1,4)\$, \$Y = (2,10,11)\$. We say that a matching is some way of ...
12
votes
3answers
286 views

Optimize my Nullifiers

I am a big fan of the game Creeper World, and especially the sequel. You don't need to know how this game works to answer the question, I just wanted to mention where my question originated from. In ...
13
votes
1answer
300 views

FIFO cache anomalies

This is the followup challenge from this one, if you're confused please check that one out first. First, let \$m(s, k)\$ be the number of cache misses a sequence \$s\$ of resource accesses would have ...
17
votes
3answers
457 views

Dead Frog Walking

Introduction Jonny wants to play Frogger. However, he's not very good. In fact, he will only try to move forward, and only after the platforms have moved. Find out if Jonny's frog manages to reach ...
24
votes
29answers
2k views

Replace me by the sum of my cyclic successors!

I have a simple challenge for you this time. Given an array of positive integers A (or the equivalent in your language), replace each entry Ai with the sum of the next Ai elements of A, cycling back ...
1
vote
0answers
72 views

Finding Fastest Frog's Frolicks [duplicate]

A frog sits on a lily pad wishing it were on the other side of the river. There are some lily pads of varying sizes between the frog and the other side of the river. Larger lily pads allow the frog ...
35
votes
22answers
3k views

Number of FIFO cache misses

This challenge is really simple (and a precursor to a more difficult one!). Given an array of resource accesses (simply denoted by nonnegative integers) and a parameter ...
1
vote
5answers
330 views

String Array to JSON String

Introduction I've seen throughout the code-golf challenges several simple tasks involving JSON, such as interpreting JSON strings with RegExs, and almost every other manipulation I could think of. ...
8
votes
25answers
701 views

Find unique elements based on a given key

Input Take a list of values xi each paired with a key yi. [(x1, y1), (x2, y2), ...] Output Return a list L containing only values from the set {xi}. The ...
17
votes
24answers
1k views

Get the sequence steps

Challenge Given a sequence of numbers, create a function which returns the sequence steps. Assume a sequence will be N >= 3 Sequence will repeat it steps at ...
16
votes
26answers
936 views

Equal numbers in sub-array

Given an array of numbers with length >=3 and length % 3 == 0 [1, 2, 3, 4, ...] You ...
16
votes
8answers
654 views

Classify a region by its slope

Definitions The kth ring of a square matrix of size N, where 1 ≤ k ≤ ceiling(N/2) is the list formed by the elements of the kth and (N-k+1)th rows and columns, but without the first and last k-1 ...