Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [array-manipulation]

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

22
votes
29answers
782 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
561 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
5k 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 ...
17
votes
15answers
854 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
342 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
955 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 (...
19
votes
15answers
3k 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
1k 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
995 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 ...
9
votes
1answer
248 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 ...
30
votes
35answers
2k 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
776 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
429 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 ...
43
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
387 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
208 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
607 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 ...
12
votes
19answers
873 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
776 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
647 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
286 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
827 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 ...
9
votes
1answer
194 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 ...
51
votes
39answers
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 ...
46
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 ...
10
votes
14answers
293 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 ...
17
votes
39answers
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
32answers
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 ...
17
votes
21answers
819 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
137 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 ...
12
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
973 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 ...
13
votes
6answers
513 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 ...
24
votes
7answers
1k views

Find the binarray!

We define a binarray as an array satisfying the following properties: it's non-empty the first value is a 1 the last value is a ...
11
votes
18answers
639 views

Sort and Re-apply Deltas of an Array

It seems that any Simple Modification of deltas using a consistent function can almost always be done some other shorter way, Dennis. Thus, the only solution I can imagine to make this harder, is to ...
21
votes
14answers
1k views

Safety in numbers

Write a program to determine if a periodic sequence of positive integers has the property that, for every integer n occurring in the sequence, there are never more ...
25
votes
24answers
1k views

Raise a single number

Introduction Suppose you want to compute the tail maxima of a list of numbers, that is, the maximum of each nonempty suffix. One way to do it is to repeatedly choose one number and replace it by a ...
13
votes
26answers
2k views

Find two integers from an unordered list to sum to the input

This is a Google interview question, see here for a youtube link. The task: Find 2 integers from an unordered list that sum to a given integer. Given an unordered list of integers, find 2 integers ...
4
votes
7answers
604 views

Dancing arrays. Output them with some forward-backward moves

The task is to create a program (or a function), which outputs array elements in the order, determined by two numbers F and B. F is number of elements to print, B is the rollback distance (from last ...