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.

36
votes
43answers
6k views

In Search of a Soulmate

Given a nonempty finite list of integers, output a truthy value if there are exactly two equal entries and all other entries are distinct, and a falsey value otherwise. Examples ...
21
votes
15answers
964 views

An expanding array

Given two positive integers p and q, your task is to return the array A created by applying the following algorithm: Start with A = [p, q] and d = 2 For each pair (x, y) of contiguous numbers in A ...
15
votes
20answers
3k views

Narcissistic array elements

Definition Narcissistic 1 integers of an array think they are better than their neighbours, because they are strictly higher than their arithmetic mean. Neighbours are defined as follows: If the ...
19
votes
15answers
2k views

Deep Search a List

For this challenge, a list is considered valid if and only if it consists entirely of integers and valid lists (recursive definitions \o/). For this challenge, given a valid list and an integer, ...
31
votes
21answers
3k views

The Three 'R's: Reverse, Reorder, Repeat

While doodling around with numbers, I found an interesting permutation you can generate from a list of numbers. If you repeat this same permutation enough times, you will always end up back at the ...
40
votes
48answers
7k views

Am I an insignificant array?

An insignificant array is an array of positive integers, where the absolute differences between consecutive elements are all smaller than or equal to 1. For example, the following array is ...
22
votes
18answers
2k views

Score a Game of Boggle

Background In Boggle, a round is scored by adding up the points for each unique word a player has found (i.e. any word that more than one player has found is worth 0 points). The points are ...
22
votes
39answers
4k views

Add an array with itself

Your challenge today is to take an array, split it into chunks, and add those chunks. Here's how this works: Your program or function will be given an array of integers ...
19
votes
36answers
3k views

Randomly select from an array

This challenge is rather simple: You are given an array of positive (not including 0) integers, and have to select a random element from this array. But here's the twist: The probability of selecting ...
27
votes
30answers
2k views

Nth Differences

In math, one way to figure out what the type of a given relation (linear, quadratic, etc) is to calculate the differences. To do so you take a list of y values for which the gap between the ...
18
votes
18answers
1k views

Reverse Maths Cycles

Inspired by this In the linked challenge, we are asked to apply addition to the elements of the original and the reverse of the input array. In this challenge, we are going to make it slightly more ...
19
votes
6answers
846 views

Kolakoski-like self-referencing sequences

This is how the Kolakoski sequence (OEIS A000002) is defined: The Kolakoski sequence is a sequence that contains 1 and 2, and ...
16
votes
7answers
955 views

Measuring a pile of logs

Introduction This is a log of length 5: ##### I want to pile a bunch of these logs on top of each other. How I do this is that I slide a new log onto the ...
21
votes
18answers
2k views

Is this a valid Takuzu board?

Takuzu is a logic game in which you have to complete a grid with cells containing 0s and 1s. The grid must follow 3 rules: No ...
12
votes
27answers
1k views

Array Factorization

Given an array of positive integers, output a stable array of the distinct prime factors of these integers. In other words, for each integer in the input in order, get its prime factors, sort them, ...
18
votes
28answers
1k views

Matrix in Range

The Challenge Given an integer n>0 output a n+1 X n+1 matrix containing all integers from ...
19
votes
43answers
3k views

Get the best of two Arrays

You will be given two arrays of floating-point numbers. Your task is to pair the corresponding elements of the two arrays, and get the maximum of each pair. However, if the two corresponding elements ...
20
votes
22answers
1k views

Are the lists divisible?

Inspired (with the explanation stolen from) this Background Say you have two lists A = [a_1, a_2, ..., a_n] and ...
13
votes
4answers
542 views

Stretch an array

Earlier I defined the process of crushing an array In a crush we read the array left to right. If at a point we encounter two of the same element in a row we remove the first one and double the ...
24
votes
20answers
2k views

Circularly moving sum

Inspired by a question at Stack Overflow. Given a non-empty array of integers x and a positive integer n, compute the sum of ...
30
votes
15answers
3k views

How hard can I crush my array?

Lets define the process of crushing an array of numbers. In a crush we read the array left to right. If at a point we encounter two of the same element in a row we remove the first one and double ...
12
votes
13answers
2k views

Skip like a frog!

Given an array of non-negative integers, your task is to only keep certain elements of it, as described below. Let's say the array is ...
0
votes
0answers
67 views

Turn an integer n into an N-DIMENSIONAL list [duplicate]

Inspired by this question. Given an integer n, create an n-dimensional list of "length" n in every dimension, where every element is n. Rules: If your language has a built-in that does this, you ...
15
votes
95answers
6k views

Turn an integer n into a list containing it n times

Given an integer n as input, return a list containing n, repeated n times. For example, the ...
16
votes
14answers
2k views

Mario Kart Scoring w/ Ties

I ran into this problem while working on another challenge I'm making for this site. In that challenge I utilize "Mario Kart 8 Scoring". The amount of points the player in kth place gets is ...
19
votes
28answers
2k views

Finding your partner

Challenge Given an arbitrary list of 2-tuples, and a single element in one of those tuples, output its "partner", i.e. given a and ...
15
votes
9answers
2k views

L€€CH€$! D€AṬH ỊṢ ṢOOṄ! (Length Mapping)

The title is valid Jelly Code which has the same output as L€€ except printed twice. Background You can skip this section without losing ability to complete the ...
15
votes
24answers
1k views

Filter out the pseudo-elements!

We define the hyper-average of an array / list (of numbers) the arithmetic mean of the sums of its prefixes. For example, the hyper-average of the list ...
22
votes
36answers
4k views

Reliably Broken Sort

Given a list of positive integers that contains at least 3 distinct entries, output a permutation of that list that isn't sorted in ascending or descending order. Examples ...
33
votes
8answers
2k views

No co-prime neighbors

Given a list of positive integers, output whether every adjacent pair of integers in it shares a prime factor. In other words, output truthy if and only if no two neighboring integers in the list are ...
24
votes
13answers
457 views

Generate a congruent list with the smallest sum

Two lists A and B are congruent if they have the same length, and elements that compare equal in ...
14
votes
8answers
581 views

Find the shortest unique sublist

Given a list of lists find the shortest list that is a contiguous sublist of exactly one list. For example if we had ...
21
votes
25answers
952 views

Maximum sub-array

Define the "maximum sub-array" of a given array as "a (consecutive) sub-array that has the biggest sum". Note there's no "non-zero" requirement. Output that sum. Give a description of your code if ...
21
votes
27answers
932 views

Sort a difference list

The difference list of a list of integers is the list differences of consecutive members. For example the difference list of 1, 3, 2 ,4 is ...
17
votes
36answers
1k views

Disappearing Elements

Given a string S and a list of indices X, modify S by removing the element at each index of <...
20
votes
29answers
1k views

Running second maximum of a list

Given a list of integers, your task is to output the second largest value in the first k elements, for each k between 2 and the length of the input list. In other words, output the second largest ...
23
votes
25answers
3k views

Numbers Increase While Letters Decrease

Inspired by this Stack Overflow question: Sorting a list: numbers in ascending, letters in descending. Your task is to solve the following problem and, as this is code-golf, you should do so in as few ...
8
votes
2answers
270 views

Implement the Cubically Cube

Cubically is a fairly new esoteric language capable of creating short, golf-like answers for a very specific subset of problems. It is unique in that it stores memory in the form of a 3x3 Rubik's cube,...
28
votes
60answers
3k views

Triangle a number!

We are used to the term "squaring" n to mean calculating n2. We are also used to the term "cubing" n to mean n3. That being said, why couldn't we also triangle a number? How to triangle a number? ...
12
votes
7answers
932 views

Count arrays of periods

The period of a string is the shortest non-zero shift so that the string matches itself, ignoring any parts that overhang. So for example, ...
20
votes
41answers
3k views

Where's my value?

My boss now wants me to implement a mechanism that lets him search for an item in an array, and gives him the index/indices where that value occurs. Your Task: Write a program or function that ...
32
votes
22answers
3k views

Sort the climbing grades

My first code golf post, apologies for any mistakes... Context In rock climbing (bouldering specifically), the V/Vermin (USA) climbing grades start at 'VB' (the easiest grade), and then go 'V0', 'V0+...
20
votes
26answers
2k views

Fold a List in Half

We are going to fold a list of integers. The procedure to do so is as follows, If the list is of even length, make a list of half of its length where the nth item of the new list is the sum of the ...
39
votes
49answers
4k views

Find the first duplicated element

Given an array a that contains only numbers in the range from 1 to a.length, find the first duplicate number for which the second occurrence has the minimal index. In other words, if there are more ...
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
739 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-...
37
votes
38answers
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
538 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 ...