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.

12
votes
11answers
714 views

Find the minimum cost matching between arrays of integers

Consider two sorted arrays of integers \$X\$ and \$Y\$ of size \$m\$ and \$n\$ respectively with \$m < n\$. For example \$ X = (1,4)\$, \$Y = (2,10,11)\$. We say that a matching is some way of ...
12
votes
3answers
275 views

Optimize my Nullifiers

I am a big fan of the game Creeper World, and especially the sequel. You don't need to know how this game works to answer the question, I just wanted to mention where my question originated from. In ...
13
votes
1answer
297 views

FIFO cache anomalies

This is the followup challenge from this one, if you're confused please check that one out first. First, let \$m(s, k)\$ be the number of cache misses a sequence \$s\$ of resource accesses would have ...
17
votes
3answers
447 views

Dead Frog Walking

Introduction Jonny wants to play Frogger. However, he's not very good. In fact, he will only try to move forward, and only after the platforms have moved. Find out if Jonny's frog manages to reach ...
24
votes
29answers
2k views

Replace me by the sum of my cyclic successors!

I have a simple challenge for you this time. Given an array of positive integers A (or the equivalent in your language), replace each entry Ai with the sum of the next Ai elements of A, cycling back ...
1
vote
0answers
72 views

Finding Fastest Frog's Frolicks [duplicate]

A frog sits on a lily pad wishing it were on the other side of the river. There are some lily pads of varying sizes between the frog and the other side of the river. Larger lily pads allow the frog ...
35
votes
22answers
3k views

Number of FIFO cache misses

This challenge is really simple (and a precursor to a more difficult one!). Given an array of resource accesses (simply denoted by nonnegative integers) and a parameter ...
1
vote
5answers
314 views

String Array to JSON String

Introduction I've seen throughout the code-golf challenges several simple tasks involving JSON, such as interpreting JSON strings with RegExs, and almost every other manipulation I could think of. ...
8
votes
25answers
676 views

Find unique elements based on a given key

Input Take a list of values xi each paired with a key yi. [(x1, y1), (x2, y2), ...] Output Return a list L containing only values from the set {xi}. The ...
16
votes
21answers
1k views

Get the sequence steps

Challenge Given a sequence of numbers, create a function which returns the sequence steps. Assume a sequence will be N >= 3 Sequence will repeat it steps at ...
16
votes
26answers
931 views

Equal numbers in sub-array

Given an array of numbers with length >=3 and length % 3 == 0 [1, 2, 3, 4, ...] You ...
16
votes
8answers
575 views

Classify a region by its slope

Definitions The kth ring of a square matrix of size N, where 1 ≤ k ≤ ceiling(N/2) is the list formed by the elements of the kth and (N-k+1)th rows and columns, but without the first and last k-1 ...
10
votes
22answers
1k views

Cartesian product of a list with itself n times

When given a a list of values and a positive integer n, your code should output the cartesian product of the list with itself n ...
0
votes
0answers
120 views

Validate Sudoku (N by N) [duplicate]

Challenge : Create a random (pseudo random) Sudoku board with dimension n x n Input : Given : ...
11
votes
12answers
827 views

Sum of replicated matrices

Given a list of numbers [ a1 a2 ... an ], compute the sum of all the matrices Aᵢ where Aᵢ is defined as follows (m is the maximum of all aᵢ): ...
20
votes
15answers
2k views

Function clipboard: paste

This challenge is related to some of the MATL language's features, as part of the May 2018 Language of the Month event. Associated challenge: Function clipboard: copy. Introduction MATL's function ...
12
votes
13answers
678 views

Grouping Array Data

Given an integer matrix a and a nonnegative integer i, output a mapping b that maps the ...
26
votes
12answers
2k views

Find arsonist's lullaby

Imagine an arsonist walking around the town and picking its victims according to a very specific pattern (Or, alternatively, Imagine a bee flying around the garden and picking its flowers to pollenize ...
24
votes
15answers
1k views

Modular broadcasting

This challenge is related to some of the MATL language's features, as part of the May 2018 Language of the Month event. Introduction In MATL, many two-input functions work element-wise with ...
10
votes
26answers
2k views

Weighted average - the pressup trend problem

Let's say that this array is how many press-ups I've achieved each day in the last 28 days: ...
11
votes
2answers
283 views

Find out my number neighbors

The input consists of i rows with neighbors information. Each ith row contains 4 values, representing the neighbor of i to the North, East, South and West directions, respectively. So each value ...
8
votes
1answer
400 views

Implement Tyrant Sort [closed]

TL;DR Record (left-right)/length for each pair of consecutive elements. If they're 0 or negative, don't record it. Once this is done, take these actions. Don't update quotients: Increment right and ...
43
votes
41answers
5k views

Detect heat waves

Background The Royal Netherlands Meteorological Institute defines a heat wave* as a series of at least 5 consecutive days of ≥25°C weather (“summery weather”), such that at least 3 of ...
15
votes
3answers
983 views

How to swap elements in a vector using an anonymous function in Octave?

Swapping two elements in a vector/matrix is very simple in Octave: x='abcde'; x([4,1])=x([1,4]) x = dbcae Unfortunately, I have yet to find a way to do this ...
10
votes
4answers
681 views

The Top Ten Elements You Won't BELIEVE Are In This Array

AKA: Generate Clickbait From an Array. Given an array of integers, generate some cringe-worthy clickbait based on its arrangement and length: If it's 20 elements or less, you can make a Top X List. ...
14
votes
6answers
938 views

Will you be my Weaver?

I've been recently playing through 'The Weaver' and I think it presents an interesting challenge for code-golf. Premise: The Weaver is a game wherein you are given a number of ribbons coming from 2 ...
14
votes
12answers
883 views

Circle intersection area

Description : Given x and y positions of two circles along with their radii, output the ...
11
votes
2answers
362 views

The Lonely Islands

Input: A 2D array containing two distinct (optional) values. I'll use 0 and 1 when explaining the rules. The input format is of course flexible. Challenge: Zeros are water, and ones are islands. In ...
17
votes
23answers
2k views

Sort spelled-out serial numbers

Given a list of two or more spelled-out serial numbers of equal length greater than two, e.g. ...
14
votes
9answers
1k views

Block Rearrangement

So your task is to take a 3x3 block where -'s mean blank spaces, and *'s mean filled spaces, for example: ...
-7
votes
7answers
143 views

Make Arrays/Lists start at one [closed]

Introduction For as long as programmers have been programming and as long as English teachers have been teaching, there's a controversy over the datasets called Arrays and Lists (or hashes). Arrays ...
21
votes
20answers
925 views

Reverse Range Successors

Given a positive integer n, do the following (and output every stage): start with a list containing n copies of ...
16
votes
13answers
885 views

Running gene crossover algorithm

Your task is to accept as input two gene sequences, and a sequence of "cross over points", and return the gene sequence that results from the indicated cross overs. What I mean by this is, say you ...
26
votes
36answers
4k views

Implement Lazy Drop Sort

This challenge already describes dropsort. However, I'm kinda lazy and I really only need my array to be a bit more sorted than before, it doesn't need to be sorted all the way. In Drop Sort, we drop ...
15
votes
10answers
1k views

Limit your numbers by your runs

Self-limiting lists Consider a nonempty list L containing nonnegative integers. A run in L is a contiguous sublist of equal elements, which cannot be made longer. For example, the runs of [0,0,1,1,3,...
-1
votes
3answers
315 views

Fastest to find the joint

The input is an array (or space-separated string, as you wish), zero-indexed, consisting of one strictly increasing array and one strictly decreasing array (in this order, not other vice versa), each ...
6
votes
7answers
419 views

Help John watch movies!

Introduction So John finally has his holidays! And what better could he do than watching some movies. He indeed has a lot of movies to watch, but he is unable to decide which one to watch first. He ...
27
votes
31answers
3k views

Rebuild a rectangular array from a corner

I once had a beautiful rectangular array. It was very symmetrical, but unfortunately it has fallen apart and now I only have the top left corner. Your task will be to rebuild the original array. Your ...
18
votes
8answers
610 views

Sort by shuffling blocks

Block shuffle sort The block shuffle sort is a (rather artificial) method of sorting a list. It works as follows, illustrated by an example. ...
7
votes
5answers
370 views

Visit and exit an array

Challenge: Input: An integer n (> 0) An integer-array a of size ...
18
votes
20answers
2k views

How to print the below format in the fewest bytes?

This challenge is inspired by this, now deleted question. Take a positive integer N as input, and output a matrix with the numbers 1 .. N2 that follows the pattern below: Fill in the first row with ...
17
votes
27answers
849 views

Quickly regrouping lists

Grouping takes a list and splits it into new lists of equal adjacent elements. For example [1,1,2,1,1] -> [[1,1],[2],[1,1]] If you then take the length of ...
59
votes
18answers
3k views

There are two new sheriffs in town – Identifying DJMcMego pairs!

We have some new sheriffs moderators in town, Mego and DJMcMayhem. We need a challenge to properly honour them for their new positions, so there we go. Here's something that has caught my attention ...
17
votes
7answers
454 views

1D Hopping Array Maze

Inspired by We do tower hopping and related to 2D Maze Minus 1D Introduction Your task is to find the shortest path to get out of an array maze following specified rules. Challenge A 1D array a ...
18
votes
14answers
2k views

We do tower hopping

Task Given an array of non-negative integers a, determine the minimum number of rightward jumps required to jump "outside" the array, starting at position 0, or ...
21
votes
11answers
3k views

The weight of a Zero

Given an ordered list of numbers (possibly with leading zeros), arrange the numbers vertically, then let all zeros drop all the way to the bottom and all overhangs drop to the bottom-most open slot. ...
-2
votes
24answers
623 views

Don't get your head in a spin!

Guidelines Task Write a function that takes in a sentence (a string, or list of characters) and reverses all the words that are greater than or equal to 5 in length. Examples ...
18
votes
10answers
1k views

Minimally sort a list into a matrix

Given an unsorted list of unique strictly positive integers, minimally sort it into a 2D matrix. The input list is guaranteed to be of composite length, which means the output matrix is not ...
39
votes
40answers
5k views

Is there a bump?

Given a list of positive integers determine if there is an element that is either greater than its two neighbors or less than its two neighbors (a "bump"). To be clear a bump can never be the first ...
14
votes
12answers
1k views

Stitch Together a Palindrome from Palindromic Substrings

Given a string l, find all palindromic substrings p of l (including duplicates and single ...