Stack Exchange Network

Stack Exchange network consists of 175 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.

35
votes
25answers
2k views

Print a physical multiplication table

Rectangles have this nice property - an \$n \times m\$ rectangle consists of exactly \$n \times m\$ characters! A.. more interesting property is that the rectangles can be aligned nicely in a ...
29
votes
23answers
7k views

Could you please stop shuffling the deck and play already?

Challenge: Input: A list of distinct positive integers within the range \$[1, \text{list-size}]\$. Output: An integer: the amount of times the list is riffle-shuffled. For a list, this means the ...
18
votes
9answers
1k views

Generate the Rummy Sequence

Your task is to take an input n and output element n of the Rummy Sequence, a sequence which I made (looking on OEIS will not ...
12
votes
28answers
2k 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, ...
14
votes
10answers
644 views

How many steps did I walk?

A simple pedometer can be modeled by a pendulum with two switches on opposite sides—one at x=0 and one at x=l. When the pendulum contacts the far switch, the ambulator can be assumed to have taken ...
33
votes
16answers
2k views

Who is the tallest?

N children, with no two sharing their exact size, are lined up in some order. Each can only compare heights with their immediate neighbours. When the teacher shouts "raise hands if you are the tallest"...
28
votes
12answers
4k views

Lifetime of a Worm

Terms A worm is any list of nonnegative integers, and its rightmost (i.e., last) element is called the head. If the head is not 0, the worm has an active segment consisting of the longest contiguous ...
21
votes
15answers
4k views

My array should equal this, but it doesn't!

Given an array of integers a which contains n integers, and a single integer x; remove the fewest amount of elements from ...
40
votes
50answers
7k 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 ...
18
votes
37answers
3k views

Create chunks from an array

Your task is to write a program which given an array and a number, you need to split the array into chunks with size is number. Rules Your program will receive an array ...
22
votes
33answers
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 ...
11
votes
14answers
1k views

Maximum Maxima!

Inspired by this question and refined by Luis Mendo. Challenge Given a 2D matrix of integers, each row has a maximum value. One or more elements of each row will be equal to the maximum value of ...
19
votes
2answers
328 views

One goes up, the other comes down

Introduction In this challenge, your task is to decide whether a given sequence of numbers can be separated into two subsequences, one of which is increasing, and the other decreasing. As an example, ...
15
votes
20answers
2k views

Deal the cards to the players

Tonight is card game night! You are the dealer and your task is to write a program to deal the cards to the players. Given an array of cards and the number of players, you need to split the array of ...
22
votes
39answers
3k views

Shortest power set implementation

Problem definition Print out the powerset of a given set. For example: [1, 2, 3] => [[], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]] Each element is to ...
32
votes
31answers
6k views

Flatten the Array!

In this challenge, your task is to create a program which takes in a nested array and returns a single-dimensional flattened array. For Example [10,20,[30,[40]],50] ...
19
votes
7answers
697 views

Hilbert-Curvify a Matrix

Inspired by this question Another way to unroll a 2D image into a 1D string is to use an Hilbert Curve. There are many version of this curve, depending on the number of iterations used while ...
20
votes
23answers
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 ...
32
votes
20answers
2k views

Superior Passtimes

Sometimes, when I'm really bored I like to take the sum of an array of non-negative integers. I only take the sum of arrays of lengths that are powers of two. Unfortunately I often make mistakes. ...
17
votes
42answers
2k views

Count repetitions of an array

You will receive an array and must return the number of integers that occur more than once. [234, 2, 12, 234, 5, 10, 1000, 2, 99, 234] This will return 2, since ...
21
votes
23answers
3k views

Pointer jumping

Suppose we have an array \$\texttt{ps}\$ of length \$n\$ with pointers pointing to some location in the array: The process of "pointer jumping" will set every pointer to the location the pointer it ...
24
votes
44answers
3k views

Non Unique Elements

Write a program which finds the non-unique elements of an array of signed integers. The resulting array can be in any order. Your answer may be a snippet which assumes the input to be stored in a ...
26
votes
33answers
4k views

Separate a list into even-indexed and odd-indexed parts

Inspired by this question: Make a function (or a full program) that receives a list of numbers and outputs the list rearranged, so that even-indexed numbers appear first, and odd-indexed numbers ...
23
votes
25answers
2k views

Reverse Deltas of an Array

Reverse Deltas of an Array A continuation of Inverse Deltas of an Array Your task is to take an array of signed 32 bit integers, recompile it with its deltas reversed. Example The List, ...
15
votes
97answers
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 ...
62
votes
47answers
6k views

N-dimensional N^N array filled with N

In: Enough memory and a positive integer N Out: N-dimensional N^N array filled with N, where N^N means N terms of N-by-N-by-N-by... Examples: 1: [1] ...
21
votes
14answers
2k views

Find a maximal rectangle of 1s

Background I want to buy an plot of land and build my house on it. My house should be rectangular, and as large as possible; however, the available plots have lots of rocky areas that I cannot build ...
48
votes
44answers
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
4answers
547 views

Rotate every row and column in a matrix

The Challenge Given a n x n matrix of integers with n >= 2 1 2 3 4 and a list of integers with exactly ...
39
votes
32answers
3k views

Remove surrounding zeroes of a 2d array

This is a 2-dimensional version of this question. Given a non-empty 2-dimensional array/matrix containing only non-negative integers: $$ \begin{bmatrix} {\color{Red}0} & {\color{Red}0} & {\...
43
votes
23answers
4k views

Covering a Skyline with brush strokes

Given a non-negative integer skyline height list, answer how many uninterrupted 1-unit-high horizontal brush strokes are needed to cover it. [1,3,2,1,2,1,5,3,3,4,2]...
15
votes
7answers
2k views

Borderless table

In this challenge you are going to place letters from the alphabet in a Cartesian plane and output the result as a text. Your input will consist in a list of list with 3 parameters: X coordinate Y ...
7
votes
1answer
354 views

Hilbertize an image

For a computer vision app I want to do a mapping of an image, in such a way that every pixel fit hilbert curve, instead of conventional layout. So task could be as follows: Task description Given ...
35
votes
35answers
6k views

Random Golf of the Day #1: Shuffle an Array

About the Series I will be running a little series of code-golf challenges revolving around the theme of randomness. This will basically be a 9-Hole Golf Course, but spread out over several questions....
28
votes
29answers
3k views

Most Common Multiple

Not to be confused with Least Common Multiple. Given a list of positive integers with more than one element, return the most common product of two elements in the array. For example, the MCM of the ...
10
votes
11answers
514 views

Map the cheaters!

After all assignments are submitted, a dictionary is created that maps student number to the hash of their file. This dictionary, or hashmap, or mapping (whatever your language calls it) will look as ...
24
votes
15answers
2k views

All the single eights

Given a non-empty rectangular array of integers from 0 to 9, output the amount of cells that are ...
26
votes
25answers
2k views

Home on the Range of Lists

This challenge is simply to return a list of lists of integers, similar to the Python range function, except that each successive number must be that deep in lists. Rules: Create a program or a non-...
20
votes
20answers
1k views

Find the “Recursive Size” of a List

Inspired by Find the “unwrapped size” of a list. Define the Recursive Size, RS, of a list containing no lists as its length (number of items contained) and the ...
13
votes
20answers
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....
3
votes
6answers
263 views

Nested lists as printable 2D objects [closed]

I don't know if something like this exists already (and I'm not finding the right key words) but if not, it felt like it could be an interesting coding puzzle. The challenge is, to take an ...
23
votes
26answers
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 ...
79
votes
42answers
7k views

2048-like array shift

Assume we want to shift an array like it is done in the 2048 game: if we have two equal consecutive elements in array, merge them into twice the value element. Shift must return a new array, where ...
34
votes
64answers
5k views

P Pr Pre Pref Prefi Prefix Prefixe Prefixes

Given some finite list, return a list of all its prefixes, including an empty list, in ascending order of their length. (Basically implementing the Haskell function ...
44
votes
38answers
9k views

Weapons of Math Instruction

Last time when I tried to come up with something easy that wasn't a duplicate, it ended up being way too hard.. So hopefully this time it's indeed something newcomers can try as well. Input: An ...
12
votes
13answers
442 views

Count the contiguous submatrices

Migrated from chat Given two non-empty non-negative integer matrices A and B, answer the number of times A occurs as a contiguous, possibly overlapping, submatrix in B. Examples/Rules 0. There may ...
5
votes
2answers
245 views

Execute Triangularity Move

TL;DR for those not interested: Look at the test cases at the bottom. Have a program/function that outputs the 2D list displayed for the given input. Introduction: On November 15th, 2018 puzzle ...
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 ...
24
votes
61answers
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 ...
22
votes
13answers
2k views

Coat of Many Colours

Challenge Given a list of unique colour names as input, sort them in the order that they first appear in Joseph's Amazing Technicolour Dreamcoat. Example ...