What's the deal with Deno? We talk with a major contributor to find out. Listen now.

Questions tagged [array-manipulation]

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

Filter by
Sorted by
Tagged with
-1
votes
6answers
81 views

Safe bidirectional array index navigation [closed]

Introduction Arrays are usually used with for-loops or iterators. One different task might be the use as a cheap way to rotate through a set of items, so after reaching the last index, the next item ...
2
votes
0answers
117 views

Using subscription for the iteration variable in Python for loop [closed]

I just realized that Python allows more than names as for loop iteration variables: for a[i] in sequence: pass The real fun ...
2
votes
1answer
209 views

Remove duplicates from list and order it by count? (python 3)

How do I remove all duplicates from list and order it based on count? ...
36
votes
60answers
5k views

The shortest way to find one unique value when all other values are the same

In this question at Code Review they tried to find the fastest way to return the unique element in an array where all the elements are the same except one. But what is the shortest code that ...
38
votes
36answers
3k views

Hot moo shuffle: milk an array

Background Milking the deck is the name given to the following card shuffling method: 'Pinch' the deck to remove the top and bottom cards simultaneously. (With lots of imagination, this action ...
23
votes
46answers
3k views

Sum the array times n, except the last

I've been posting relatively hard challenges recently, so here goes an easy one. Task Given an array \$A\$ and a number \$n\$, calculate the sum of all numbers of \$A\$ multiplied by \$n\$, except the ...
14
votes
6answers
738 views

Implement 1-dimensional version of Multi-Take

Background Adám and I were once discussing a way to properly extend some features in Dyalog APL. I came up with the following extension to Take, a function that takes some front or back elements (and ...
14
votes
9answers
1k views

How many numbers can we make?

You are given a non-empty list of positive integers. Your task is to figure out how many distinct numbers can be obtained by applying the following algorithm: Remove either the first or the last item ...
12
votes
7answers
660 views

Toroidally magnify-blur a matrix

Task Given a matrix of numbers \$M\$ with \$r\$ rows and \$c\$ columns, and the magnification factor \$n\$, build the matrix with \$rn\$ rows and \$cn\$ columns where the original elements are spaced ...
12
votes
0answers
183 views

Score a 1 player game of Carcassonne

Carcassonne is a tile-based game, where the objective is to construct Roads, Cities and Monasteries, in order to score points. The game works by players taking turns to draw and place tiles to ...
3
votes
0answers
123 views

Chinese checkers adjacent squares [closed]

Challenge You have a Chinese Checkers board looking like this: ...
25
votes
22answers
1k views

Cut resistance of a list

Background Define a run in a list as a maximal contiguous subsequence of identical values. For example, the list 0 0 0 1 1 0 3 3 3 2 2 has five runs of lengths ...
35
votes
14answers
4k views

Maintain Social Distancing!

Task Given the situation with this global pandemic, you've been enlisted to help maintain social distancing. Your challenge, should you choose to accept it, is to write a program that takes in the ...
0
votes
1answer
93 views

Look for n-plicates [closed]

If you are given an array of numbers between 1 and 100 and an integer n, you must remove any instances of an item that appear greater than ...
17
votes
33answers
1k views

Binary Reduce a List By Addition With a Right Bias

Given a list of 2 or more strictly positive integers, sum the first and last half of the list, with the middle element being counted only in the right half if the list has an odd number of elements ...
20
votes
25answers
2k views

Split a list evenly

You are given a list of at least two positive integers as input. The challenge is to find such a position of a cut that minimizes the absolute difference between the sums of the two parts (to the left ...
4
votes
0answers
172 views

How annoying is my Euler diagram?

Challenge Premise Euler diagrams consist of simple closed shapes in a 2-D plane that each depict a set or category. How or whether these shapes overlap demonstrates the relationships between the ...
3
votes
5answers
182 views

Squeezy sequence, sideways sedimentation

Challenge Premise I've got multiple pretty numbers all in a row. Each is a decimal digit. 0s are weakly attracted to 0s, 1s are attracted to 1s a little more strongly and so on until 9. I don't ...
15
votes
43answers
2k views

Generate list of numbers and their negative counterparts

A recent SO question asks for a convenient one-liner to generate a list of numbers and their negative counterparts in Python. Given two integers \$1≤a≤b\$, generate all the integers \$x\$ such that \$...
24
votes
17answers
5k views

How many fingers does bad pianist need?

Challenge Premise Bob is a novice pianist who can only play sequences of single notes. In addition, he does quite an interesting thing: for every note after the first, if it's higher than the ...
2
votes
0answers
52 views

Find two contiguous subarrays with the greatest difference [closed]

Here's an interview question I've seen on a few sites. People claim that an O(n) solution is possible, but I've been racking my brain these last 2 days and I couldn'...
13
votes
26answers
2k views

Filter an array so that duplicate items are removed

In the shortest amount of code in any programming language, filter out the duplicate items in an array of which the order is irrelevant. Here are some test cases: ...
2
votes
1answer
173 views

Summing intertwined terms of an array

I'm recieving 2-dimensional positions of two objects as a string with this format: x1,y1,x2,y2. The string is recieved from a ...
21
votes
16answers
1k views

Bucket and Minimize

The challenge - given a numeric list L and an integer N as inputs, write a function that: finds the bucket sizes for L such that it is split into N whole buckets of equal or near-equal size, and ...
25
votes
17answers
926 views

Cartesian LCM of two arrays

Given two nonempty arrays of natural numbers \$a\$ and \$b\$, return the shortest nonempty array of pairs of natural numbers \$q\$ such that the sequence of first elements of \$q\$ consists of a whole ...
2
votes
3answers
367 views

Simulate move left for 2048 [duplicate]

I have a fixed length vector of 4 elements. The inputs of which are always 0 or 2^n for n = 1 to 15 (so n = 0 excluded i.e. 2^0 = 1 will not appear) ...
19
votes
18answers
2k views

Clockwise matrix rotation

The title pretty much describes it all. Given as input a \$n \times m\$ matrix and an integer \$i\$ create a complete function/program that returns the matrix \$i\$ times clockwise rotated by \$90^\...
17
votes
14answers
2k views

Unique magic triplets

Description Your input is a list of integers \$[a_1, \dots, a_n]\$. A magic triplet is a triplet \$(a_i, a_j, a_k)\$ of values from this list, such that the indices \$\{i, j, k\}\$ are all distinct,...
10
votes
8answers
433 views

1D Shikaku Validation

Shikaku is a 2D puzzle. The basic rundown of it is that a rectangular grid has some numbers in it, and you want to partition the grid into rectangular components such that each component contains ...
2
votes
1answer
147 views

Minimum number of changes required [closed]

Given an array where each number represent a color. After iterating each item in the array (for each item in the iteration the pointer can also point to the second-item-to-the-right), and the two ...
2
votes
1answer
142 views

Shooting gallery Puzzle!

Have you been shooting gallery? We are recently. In our shooting gallery cans and aluminum cans from under various drinks hang and stand. More precisely, they hung and stood. From our shots, banks ...
12
votes
18answers
2k views

It's as easy as 1,2,3 (except you have to add them up)

Let's consider a list \$L\$ (initially empty) and a pointer \$p\$ into this list (initialized to \$0\$). Given a pair of integers \$(m,n)\$, with \$m\ge 0\$ and \$n>0\$: We set all uninitialized ...
6
votes
6answers
299 views

Explore a Klarner-Rado sequence [duplicate]

One of the Klarner-Rado sequences is defined as follows: the first term is \$1\$ for all subsequent terms, the following rule applies: if \$x\$ is present, so are \$2x+1\$ and \$3x+1\$ the sequence ...
16
votes
43answers
3k views

Find the percentage

We haven't had any nice, easy challenges in a while, so here we go. Given a list of integers each greater than \$0\$ and an index as input, output the percentage of the item at the given index of the ...
5
votes
7answers
250 views

Replace by most recent nonzero [duplicate]

Given a non-empty list of decimal digits (0, 1, ..., 9), replace each zero by the most ...
5
votes
2answers
340 views

Highest cardinality grouping of contiguous integers with minimum-sum threshold

Challenge Given an array of positive integers and a threshold, the algorithm should output a set of consecutive-element-groupings (subarrays) such that each group/subarray has a sum greater than the ...
-5
votes
11answers
956 views

Return the nth element of an array even if its out of bound [closed]

The challenge Write a function that returns the nth element of an array even if its out of bound. ...
25
votes
24answers
5k views

Count the number of triangles

Given a list of positive integers, find the number of triangles we can form such that their side lengths are represented by three distinct entries of the input list. (Inspiration comes from CR.) ...
31
votes
29answers
2k views

The Lucky House

There's a minigame in Super Mario 3D World known as the Lucky House. It consists of a slot machine with 4 blocks. Each block may be one of 5 different icons (Flower, Leaf, Bell, Cherry or Boomerang) ...
-4
votes
2answers
141 views

Elimination ordering

Your task is to remove smallest amount elements from a list, so the most elements are on their corresponding place. The element is on it's corresponding place, when it's value is equal to it's ...
11
votes
7answers
1k views

An array battle with odd secret powers

Here is a relatively simple two dimensional array challenge. Imagine a battlefield of 625 foot soldiers. You command the odd troops, but unfortunately the strength of the even troops overwhelms you. ...
13
votes
34answers
1k views

Chunk + Enumerate a list of digits

I have a list of decimal digits: 4, 4, 4, 7, 7, 9, 9, 9, 9, 2, 2, 2, 4, 4 The list of decimal digits are known as items. We can form "chunks" from these items by ...
11
votes
7answers
273 views

Crossing sequences

Crossing Sequences Given a list of positive integers A, call it an increasing sequence if each element is greater than or equal to the previous one; and call it a ...
6
votes
7answers
219 views

Dropsort with a Twist

This is my first attempt at a Code Golf question. If it needs obvious edits, please feel free to make them. Below is a description of the basic Dropsort algorithm. Dropsort is run on a list of ...
3
votes
3answers
162 views

Golf range minimum queries of a list [closed]

(Inspired by the first problem solved in Stanford’s advanced data structures course.) Despite the academicese-heavy name, the problem we're going to solve is almost unbearably simple. We have a list ...
36
votes
11answers
1k views

There's an echo in my array… echo in my array… my array

Help! I seem to have an annoying echo in some of my arrays, and I'd like to get rid of it. When this occurs, the original array repeats itself somewhere in the middle causing the values to be added ...
22
votes
17answers
3k views

Matchmaker, Matchmaker, make me a match

(we won't be finding a Find or catching a tryCatch, though) This is part two of a multi-part series of implementing some ...
15
votes
9answers
1k views

Fivenum and a little bit

(a paradox, a paradox, a most ingenious paradox) This is the first part of a multipart series inspired by different R functions. The Task Given a dataset \$D\$ of positive integers, I need you to ...
14
votes
4answers
464 views

Distributing parliament seats

Introduction In a general election, one would like to calculate a constant price per parliament seat. This means that for N >= 0 seats to be distributed and a ...
4
votes
3answers
225 views

Find longest consecutive characters in 2D array

Challenge Given a 2D array, find the length and direction of all the longest consecutive characters. If there are ties, output every possible winning combination in any order, (winners can overlap ...

1
2 3 4 5
12