Questions tagged [array-manipulation]

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

Filter by
Sorted by
Tagged with
14
votes
33answers
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 ...
14
votes
23answers
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-...
41
votes
45answers
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: ...
16
votes
10answers
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. ...
34
votes
58answers
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 ...
24
votes
27answers
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 ...
22
votes
29answers
962 views

Collapse Adjacent Duplicates

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 ...
9
votes
3answers
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 ...
27
votes
49answers
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 ...
3
votes
1answer
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 ...
19
votes
19answers
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 ...
21
votes
34answers
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 ...
4
votes
1answer
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 ...
9
votes
18answers
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 (...
20
votes
15answers
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 ...
18
votes
45answers
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: ...
18
votes
11answers
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): ...
23
votes
12answers
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 ...
27
votes
56answers
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 ...
12
votes
11answers
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 ...
30
votes
18answers
2k views

N-dimensional identity “matrix”

Given a positive integer n, output the N-dimensional identity "matrix", which is the N^N ...
8
votes
1answer
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 ...
31
votes
35answers
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, ...
11
votes
27answers
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 ...
10
votes
2answers
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 ...
44
votes
16answers
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 ...
26
votes
21answers
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: ...
5
votes
5answers
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 ...
4
votes
0answers
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 ...
21
votes
6answers
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 ...
11
votes
19answers
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 ...
27
votes
25answers
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 ...
8
votes
10answers
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 ...
23
votes
16answers
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 ...
20
votes
45answers
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) ...
7
votes
7answers
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 ...
22
votes
1answer
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 ...
29
votes
21answers
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 ...
8
votes
1answer
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 ...
53
votes
40answers
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 ...
47
votes
54answers
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 ...
9
votes
14answers
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; ...
30
votes
21answers
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 ...
19
votes
40answers
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 ...
23
votes
34answers
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 ...
18
votes
21answers
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 ...
2
votes
5answers
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 ...
11
votes
16answers
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 ...
26
votes
24answers
1k views

When integers join the queue

Introduction A queue is an abstract data type where elements are added to the front (enqueue) and removed from the back (dequeue). This is also known as the FIFO (First In First Out) principle. It ...
12
votes
6answers
558 views

Topple the sandpile

(There are related questions about infinite sandpiles, and finding identity elements of sandpiles.) Given a matrix of non-negative integers, return a matrix of the same dimensions, but toppled: If ...

1
4 5
6
7 8
11