# Questions tagged [array-manipulation]

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

536 questions
Filter by
Sorted by
Tagged with
2k views

### Get the indices of an array after sorting

Your challenge today is to write a program or function which takes a list l and gives the positions in l at which each ...
774 views

### Compute the Matrix-Vector

Given an integer array of at least two elements, output the Matrix-Vector (defined below) of the array. To compute the Matrix-Vector, first rotate through the size-...
3k 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: ...
592 views

### Risk Battle: Going Down

Given two lists of dice rolls for a battle in Risk, your program or function must output how many troops each player loses. Background You do not have to read this, for it is merely background. ...
4k views

### Reverse Array Sum

Your program should take an array as input. The array: Will always be 1 dimensional Will only contain integers Can be empty The program should reverse the array, and then add up the elements to ...
2k views

### Apply a wave to an array

Your task today is to apply a wave to an array of numbers. A wave looks like this: [1, 0, -1, 0, 1, 0, -1, 0, 1...] Applying it to a given array means adding ...
962 views

Challenge Given a list of integers, return the list of these integers after repeatedly removing all pairs of adjacent equal items. Note that if you have an odd-length run of equal numbers, one of ...
585 views

### Old Cordless Phone

I need to call my friends but the buttons of my cordless phone are not working properly. The only buttons I can press are [Up], [Down] and [Call]. [Up] and [Down] can be used to navigate in my recent ...
7k views

### Find the Missing Letter

Guidelines Task Write a method that takes an array of consecutive (increasing) letters as input and that returns the missing letter in the array (lists in some languages). Rules This is code golf ...
1k views

### remove duplicates from array [closed]

You have given an array from which we need to remove duplicates. Rules: First or immediate duplicates gets removed first. Array contains natural numbers ...
1k views

### Extract Local Maxima

Given an array of positive integers, output an array of all the elements that are greater than or equal to the adjacent ones. Most elements will have two adjacent elements; the first and last element ...
4k views

### Help me do my washing

Help! My Completely Automated Lights From Darks Separator V3001.01 broke! :( Guidelines Task Write a program that will take an input of an array (or a list in some languages) of any amount of ...
373 views

### Conways's Game of Life: Most newborn generating starting pattern

General rules The universe of the Game of Life is an infinite two-dimensional orthogonal grid of square cells, each of which is in one of two possible states, alive or dead. Every cell interacts with ...
989 views

### Reduce the list to a final number

Inputs A list (array) of numbers, or numerical strings if that makes it easier. You can assume there will always be at least two elements in the list and every element will be a natural number (...
4k views

### Reverse a Rubik's Cube Algorithm

Whenever you make a move on a Rubik's Cube, there is a reverse move which undoes the first move. Because of this, every algorithm (set of moves) has a reverse algorithm which undoes the first ...
2k views

### Compare the averages of my lists

Getting the average of a list (e.g [2,6,7]) Get the length of the list: [2,6,7] -> 3 Sum the numbers in the list: ...
2k views

### Compress a sparse matrix

Compress a sparse matrix using Compressed sparse row (CSR, CRS or Yale format). These are all the same form of compression (ignore new Yale). Input may be any 2d data structure (list of lists, etc): ...
1k views

### Pad a matrix with its sums

Challenge: Given a square input matrix A, pad the matrix with one row and one column on all four sides. The value of each element in the top and bottom row should be the sum of the elements in each ...
3k views

### Trim the array!

Given an integer array and two numbers as input, remove a certain amount of the first and last elements, specified by the numbers. The input can be in any order you want. You should remove the first ...
1k views

### Parse a list of lists into a Sad-List

In this challenge, you must parse a list of lists, into a simpler list format. This challenge is based on my sadflak parser. In my sadflak parser, it has all the () removed, replaced with the sum of ...
2k views

### N-dimensional identity “matrix”

Given a positive integer n, output the N-dimensional identity "matrix", which is the N^N ...
256 views

### Counting Gems on the Ground

Counting Gems Background My jewel box just fell down! There're too many gems of different shape on the ground. And your task is to count number of a certain type of gem. I/O Your code should take ...
3k views

### Swap the two given indices

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, ...
860 views

### All non-ordered pairs between the elements of an array

Task: Return an array with all possible pairs between the elements of an array. Example From a=["a", "b", "c", "d"]; return ...
464 views

### Compute OEIS A005434

The task is to compute OEIS A005434 as quickly as possible. Consider a binary string S of length n. Indexing from ...
4k views

### Implement the “Lazy Sort”

I'm supposed to sort a list of numbers, but I'm super lazy. It's really hard to figure how to swap all the numbers around until all of them are in increasing order, so I came up with my own algorithm ...
1k views

### Group a List by Frequency

Given a list of integers, group the elements which occur most first, then group the next most and so on until each unique element in the list has been grouped once. Examples: Input: ...
393 views

### Rate my sorting

Introduction So my boss is making me do some manual labor...urgh...I have to take a part out a box of parts, process it and put it back in the box. To make this more interesting I try to sort the ...
325 views

### Minecraft Pumpkin / Melon overload [closed]

DONT EVALUATE YET, ALMOST FINISHED, NEED A CLEAR WINNING CRITERION Make me rich in minecraft Minecraft is a 3D game made of blocks that you can destroy and place. There are some interesting farms ...
625 views

### Fix my notation for lists of matrices, part 1

Sometimes, I have lists of constant matrices in my code: [ [[1, 0], [0, 1]], [[1, 0], [0,-1]], [[0, 1], [1, 0]], [[0,-1], [1, 0]] ] That's a ...
991 views

### Generate all Sublist Partitions

Given a non-empty list of integers, output every possible partitioning of the list where each partition is a non-empty sublist. So for the list [1, 2, 3, 4] the ...
946 views

### Does the sum of 2 numbers in the list equal the desired sum? [duplicate]

The Task This is my first challenge so apologies if it is very simple! In this challenge, your task is to write a program or function which takes in a list of integers and a desired sum and outputs ...
662 views

### Squaring Off (fit to smallest possible square)

Intro More complex than A square of text since this requires padding and input has unknown data type. Every year, Dyalog Ltd. holds a student competition. The challenge there is to write good APL ...
1k views

### Random Golf of the Day #8: Shuffle an infinite list

About the Series First off, you may treat this like any other code golf challenge, and answer it without worrying about the series at all. However, there is a leaderboard across all challenges. You ...
2k views

### Determine if an Array contains something other than 2

Take an array which consists of numbers or arrays, output if it only contains 2s. Output should be a truthy or falsey value (Sorry if this destroys answers) ...
296 views

### Average an array until all numbers are (almost) equal

Given an array of numbers, find out how many iterations of averaging* it takes for the average of every element to be no more than 1 higher or lower than the first element (absolute difference between ...
860 views

### Expand Kirkman's Schoolgirl Problem

For those of you who are unfamiliar, Kirkman's Schoolgirl Problem goes as follows: Fifteen young ladies in a school walk out three abreast for seven days in succession: it is required to arrange ...
1k views

### Swap indices and values

The task Write a program or function whose input is a list/array X of integers, and whose output is a list of sets of integers Y, such that for each element e in each set Y[i], X[e] = i, and such ...
197 views

### K-Means Clustered Golf

K-Means Clustering (Wikipedia) The task here is rather simple, perform a single iteration of a k-means clustering algorithm on a binary matrix. This is essentially the setup task for the main k-means ...
6k views

### The forbidden built-in

In the standard loopholes, the following is forbidden: Claiming that your answer is written in "MyOwnLanguage", where the command x means "read a sequence of ...
4k views

### Be the First 1 (leave only the first Truthy)

Intro Every year, Dyalog Ltd. holds a student competition. The challenge there is to write good APL code. This is a language agnostic code-golf edition of this year's eighth problem. I have explicit ...
301 views

### Evaluate Index of Multidimensional Coordinates

A collection of N dimensional coordinates are provided. An example is below: {2,3,4} This can be thought of as a 3 dimensional array with 2x's, 3y's and 4z's; ...
2k views

### Find the nearest greater number

The task Given any array of integers, e.g.: [-1,476,578,27,0,1,-1,1,2] and an index of that array (this example uses 0 based indexing, though you can use 1 ...
2k views

### Halve the falses

Task Given a non-empty array of 0 and 1, halve the lengths of the runs of 0. Input An ...
1k views

### Parity of sum of other elements

Task Given an array of positive integers, replace each element with the parity of the sum of the other elements. The array is guaranteed to have at least 2 elements. Definition Parity: whether a ...
842 views

### Longest equal subsequences

Definitions A subsequence may not be contiguous, e.g. [1, 1, 1] is a subsequence of [1, 2, 1, 2, 1]. An equal subsequence is a ...
146 views

### Indices of elements in an array in order from smallest to largest [duplicate]

Task Basically you have an array of random integers e.g. I() = [1, 4, 3, 2, 5, 3, 2, 1] and you have to create another array of the same length with the numbers ...
1k views

### The tedious array of 7 rules

The rundown Create a program that generates an array of random length with random numbers, then apply a series of rules that alter the array. After the rules have been applied, print the sum of the ...