Questions tagged [array-manipulation]

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

479 questions
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 ...
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 ...
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 ...
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, ...
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 ...
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 ...
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 ...
4k views

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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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, ...
1k views

Matrix in Range

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

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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
2k views

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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
1k views

Disappearing Elements

Given a string S and a list of indices X, modify S by removing the element at each index of <...
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 ...
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 ...
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,...
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? ...
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, ...
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 ...
3k views

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+...
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 ...
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 ...
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 ...
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-...
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: ...
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. ...