# Questions tagged [array-manipulation]

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

479 questions
281 views

### Selling electricity

Jack is a little businessman. He found out a way to earn money by buying electricity on days when it's cheap and selling it when it's much more expensive. He stores the electricity in a battery he ...
1k views

### Generate all square sub-matrices of a given size

You will be given a square matrix of integers M and another positive integer n, strictly smaller than the size of M. Your task is to generate all square sub-matrices of M of size n. For the purposes ...
624 views

### Wanna See a Card Trick? (Part I)

Amazingly, this is the easier of the three card tricks I know off the top of my head... The aim of this is to have your compiler perform a specific card trick. There's no slight of hand, and the ...
1k views

### The modulo parity party

You are given an array A of n strictly positive integers, with n ≥ 2. Your task is to map each entry Ai to: 1 if Aj mod Ai is odd for each j such that 1 ≤ j ≤ n and j ≠ i 2 if Aj mod Ai is even for ...
1k views

### Column-wise summation of overlapping slices

Task Given a list of integers L and another integer s, the goal is to compute the column-wise sums of all s-length (potentially overlapping) slices of L, while pertaining their positions relative to ...
2k views

### Tell me how to flop

As computer scientists, you're probably all familiar with the basic list operations of pop and push. These are simple operations that modify a list of elements. However, have you ever heard of the ...
368 views

### Remove entries from array to sort it and maximize sum of elements

This challenge is from an admission test to a closed number cyber security course. Anyway it doesn't have to do with cyber security, it's just to test the students logical and coding skills. Task ...
584 views

### Reverse columns while preserving shape

Introduction Suppose you have a list of lists of integers (or any objects really, but let's stick to integers for simplicity). The lists may be of different lengths, and some of them may be empty. ...
825 views

### Compare Two Lists by Their Maximum

Given two different lists of non-negative integers, return the list that has the highest maximum (e.g. [4, 2], [3, 3, 1] -> [4, 2]). If they both have the same ...
2k views

### Rotation summation

Take a square matrix containing positive integers as input, and calculate the "rotated sum" of the matrix. Rotated sum: Take the sum of the original matrix and the same matrix rotated 90, 180 and ...
2k views

### Enumerate an array, grouping duplicates

The objective of this challenge is to take an array of positive integers, and enumerate its indices, grouping like elements. An enumeration without any duplicates is done by just outputting an array ...
259 views

### Regrowing trees

Background Here you have another work-inspired challenge, but from my wife's work in this case. Imagine you have a service that returns the list of nodes in a tree structure (much like the files and ...
764 views

### Alternatively shift columns and rows of a 2D array

Objective Given a 2D array of any size, write a program or function to shift alternatively the columns and rows Example a b c d e f g h i j k l m n o All ...
562 views

### A Dance of Many Dimensions

Challenge Given a n-dimensional array of integers and a permutation of the first n natural numbers, permute the array ...
1k views

### Maximum run between identical elements

This is a overhaul of this now deleted question by ar kang. If the OP of that question would like to reclaim this question or has a problem with me posting this I'd be happy to accommodate Given a ...
1k views

### Compute the Optimal Square Matrix

The optimal matrix (for the rather narrow scope of this challenge) is obtained by "zipping" the elements from the corresponding rows and columns of a square matrix and getting the maximum of each pair....
2k views

### XOR sort an array

Given a key, and an array of strings, shuffle the array so that it is sorted when each element is XOR'd with the key. XOR'ing two strings To XOR a string by a key, XOR each of the character values ...
3k views

Definition An arrowhead matrix is a matrix that has all entries equal to 0, except the ones on the main diagonal, top row and leftmost column. In other words, the matrix should look like this: * * * ...
2k views

### Can this list be balanced?

To check whether a list of non-negative integers is balanced, one can imagine putting respective weights on a board and then try to balance the board on a pivot such that the summarized relative ...
6k views

### Find the longest word in an array

Your challenge is to take an array of strings and output the longest string in the array. So for ["tiny", "small", "bigger", "biggest"] the output would be ...
2k views

### Visualize Merge Sort

Merge sort is a sorting algorithm which works by splitting a given list in half, recursively sorting both smaller lists, and merging them back together to one sorted list. The base case of the ...
556 views

### N-bit Variation on Subset-Sum

For another challenge I am writing, I need to verify that test cases are solveable with bounded integers. Specifically, I need to verify the following, for a non-empty array of integers ...
5k views

### Duck, Duck, Josephus

Given an Integer array: Start from the first number Jump forward n positions where n is the value of the current position Delete the current position, making what was the next position the current ...
149 views

### Advent Challenge 8: Storage Cart Transport Planning!

<< Prev Thanks to the PPCG community, Santa now has balanced his storage carts. Now, he needs to move them into the transport docks so that they can be sent to the loading bays. Unfortunately, ...
171 views

### Advent Challenge 7: Balance the storage carts!

<< Prev Next >> After some careful analysis, Santa was able to determine the dock size ranges and get the presents into the correct transportation dock. Now, he needs you to help him balance ...
3k 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 ...
399 views

### Advent Challenge 6: Transport Dock Relabeling!

<< Prev Next >> Thanks to the PPCG community, Santa managed to sort his presents into the correct order for moving into the transportation dock. Unfortunately, the transportation dock signs are ...
1k views

### Advent Challenge 5: Move the presents to the transport docks!

<< Prev Next >> Thanks to the PPCG community, Santa has managed to remanufacture all of his presents and after the assembly line, the presents are now ready to be moved into the transport docks!...
460 views

### Make sets disjoint without emptying them

Suppose you have a set of sets of integers. It's possible that some of the sets will overlap (i.e. sharing elements). You could get rid of the overlaps by deleting elements from the sets, but then ...
1k views

### Mod-balanced lists

Introduction Suppose I have a list of integers, say L = [-1,2,2,1,2,7,1,4]. I like having balance in my life, so I'm happy to see it has as many odd elements as even elements. What's more, it also ...
599 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 ...
3k views

### Normalize a Vector

To normalize a vector is to scale it to a length of 1 (a unit vector), whilst keeping the direction consistent. For example, if we wanted to normalize a vector with 3 components, u, we would first ...
439 views

### The Shield Wall

Historical Background The shield wall is a tactical war formation that dates back to at least 2500 BC. It consisted of warriors overlapping their shields with those of their companions to form a '...
367 views

### Iterative Alliterative Additive Array Antics

I honestly don't know what the point of this sort of calculation would be, but it should make fun golfing. Shortest code wins. Input (in no particular order) An array of integers, ...
219 views

### The Median of Practically Recreational Languages

According to TIO there are two types of programming languages: Practical (seen in many corporate environments as a development standard). Recreational (if seen in a corporate environment, you're ...
778 views

### Largest Deep Sum [closed]

Given an n-dimensional array filled with numbers, output which p-dimensional array has the largest sum. Input An n-dimensional array of numbers, or your language's equivalent. You can assume this is ...
3k 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 ...
871 views

### Pick-flatten a list

Consider the process of "picking" a nested list. Picking is defined as follows: If the argument is a list, take an element from the list at random (uniformly), and pick from that. If the argument is ...
2k views

### An Array of Challenges #3: Moving Averages

Note: This is #3 in a series of array-manipulation challenges. For the previous challenge, click here. Moving Average of a List The moving average of a list is a calculation resulting in a new, ...
3k views

### Basic sort, with annoying bug

Your input is a list/sequence/vector/array of 5-255 positive integers, not necessarily unique. You may assume whatever input format is most suitable, and that each integer (as well as the quantity of ...
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 ...
3k views

### Count the changes in an array

Your task today is to write a program or function that takes an array of integers, and counts the number of times, reading it left to right, that the value changes. This is easier to show with an ...
3k views

### Does it oscillate periodically?

Challenge Given a list, determine if grouping the list into runs of increasing and decreasing elements will result in a list of equal-sized lists. In other words, "turning points" of the list are ...
628 views

### Oscillation equality

We have objects that oscillate between two integer points, [l, r], at the speed of one unit per time unit, starting at l on <...
781 views

### Alternested numbers

Consider the array of positive integers: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, ... Then, concatenate them: ...
492 views

### Expand an Array

Expand an array to all directions by duplicating the outer elements You will be given two inputs: an array and the expansion degree For example if I give you ...
469 views

### Fill the steps (randomly)!

This is Hole-9 from The Autumn Tournament of APL CodeGolf. I am the original author of the problem there, and thus allowed to re-post it here. Given a simple (rectangular, non-jagged) Boolean array (...
4k views

### Am I a golfy array?

Definition and Rules A golfy array is an array of integers, where each element is higher than or equal to the arithmetic mean of all the previous elements. Your task is to determine whether an array ...