Questions tagged [array-manipulation]

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

Filter by
Sorted by
Tagged with
16
votes
16answers
3k views

What's my PIN number?

My PIN number is 1077, but that's too difficult to remember. I know from muscle memory that it's a digit, followed by a different digit, then followed by two of the same digit, which is different to ...
19
votes
17answers
2k views

Build me a room

Related A room, in the context of this challenge, is a multidimensional array where the elements on the "outside" are 1, to represent the walls, and all ...
6
votes
6answers
462 views

Group binary shapes together

Consider the following binary matrix: $$\begin{matrix} 1 & 0 & 1 \\ 1 & 0 & 0 \\ 0 & 1 & 1 \end{matrix}$$ The (1-indexed) co-ordinates of the \$1\$s here are \$(1,1), (1,3), (2,...
19
votes
21answers
2k views

Longest Zero Sum Sub-array

Given an array of integers. Find out its longest sub-array (contiguous subsequence) whose sum is 0. The sub-array for output may be an empty array. Input Input an array of integers. Output Output the ...
6
votes
6answers
354 views

Blinking Lighthouses – Founder's Day Upgrade

To celebrate the island's next Founder's Day, colored filters (fuchsia, chartreuse, and aquamarine*) have been installed in every lighthouse. All lighthouses begin operation with their fuchsia filter,...
5
votes
3answers
139 views

Is this an ordinal transform? [duplicate]

Related: What's my telephone number? which asks to calculate the terms of A000085, the number of possible ordinal transforms of length n. Background Ordinal transform is a transformation on an integer ...
24
votes
8answers
2k views

Blinking Lighthouses

Lighthouses on an island have blink codes that let ships know which lighthouse they are seeing. Input should be strings of S and L. Here is a (Python) example of codes for 4 lighthouses as a list of ...
28
votes
23answers
2k views

Recursive Z-matrix

Originally from a CMC I proposed for the last BMG event Challenge Given a non-negative integer \$n\$, create a 2D array of size \$2^n × 2^n\$ which is generated in the following manner: Divide the ...
14
votes
10answers
1k views

How many bead arrangements on the abacus?

Your toy in this challenge is a special abacus of 4 rows and 8 positions per row. There's one bead on the first row, 2 beads on the 2nd row, 3 beads on the 3rd row and 4 beads on the 4th row. Beads on ...
1
vote
1answer
165 views

No of subsets of a given array such that their product is in the form of p1*p2*p3 [closed]

Given an array \$A\$ of size \$n\$. You have to find the number of subsets such that their product is in the form of \$p_1 \times p_2 \times p_3 \dots\$ where \$p_1, p_2, p_3, \dots\$ are prime ...
26
votes
38answers
2k views

Is this a Permutation of 1..n

Input a non-empty array with \$n\$ positive integers. Test if the input array contains every integer in \$1\cdots n\$. In case you prefer 0-indexed numbers, you may choose to input an array of non-...
1
vote
0answers
53 views

Reverse a sentence word by word [duplicate]

The setting "Well I actually wrote the sql library they, the maintainers actually.." "Right, but do you have any experience working with django?" " ...no I don't use ...
30
votes
12answers
2k views

Is it a checkered tiling?

Background A checkered tiling of a rectangular grid is a tiling using some polyominoes, where each region can be colored either black or white so that no two polyominoes sharing an edge has the same ...
15
votes
23answers
2k views

What's missing (aka the vanilla multiset difference challenge)

Write a program which takes two arrays of positive integers as input. One of them (your choice which) will have one item missing compared to the other. Your program must figure out what is missing. ...
27
votes
22answers
1k views

Consecutive Distance Rating

We'll call the consecutive distance rating of an integer sequence the sum of the distances between consecutive integers. Consider 2 9 3 6 8 1. ...
13
votes
7answers
1k views

A Cat’s Game to Claim

Intro You like cats. Naturally, you like cat’s games in tic-tac-toe. So, you’ve come up with a little party trick. You ask someone what square on the board they want you to make a move in. And you ask ...
17
votes
8answers
1k views

Generalised multi-dimensional chess knight's moves

Multi-dimensional chess is an extension of normal chess that is played on an 8x8x8x8... "board". In normal 2D chess, a knight's move is a movement by a vector of \$ \begin{bmatrix} \pm 2 \\ \...
31
votes
46answers
2k views

Split a list at the second occurrence of the first element

Why should you golf in Haskell? Find out here. In that answer, Zgarb defines a task: Let's define a function f that splits a list at the second occurrence of the ...
17
votes
14answers
982 views

Smallest slice of array containing a number of items

Take this array: [1, 2, 6, 4, 4, 1, 0, 0, 2, 0, 4, 1, 4, 2, 4, 8, 1, 2, 4] There are quite a few places where ...
26
votes
21answers
3k views

I'm Lazy*: Top-left align my text

* and don't have a word processor with top-left align support :D Take several lines of input, with at least four unique characters of your choice including newline and space. The input can also be ...
15
votes
6answers
507 views

Split a list into maximal equal-sum sections

Task Given a non-empty list of positive digits, group them into sublists of equal sum. You may output any subset of solutions with maximal number of sublists (equivalently, minimal sum). The input may ...
24
votes
13answers
1k views

1D monochrome Link-a-Pix solvability

Background Link-a-Pix is a puzzle on a rectangular grid, where the objective is to reveal the hidden pixel art by the following rules: Connect two cells with number N with a line spanning N cells, so ...
5
votes
3answers
370 views

Dr. Lamport's Unfinished Business

Introduction Dr. Leslie Lamport, of the eponymous Lamport one-time signature scheme, is getting rather old. But he can't die until his most famous algorithm gets all the kinks ironed out! In ...
15
votes
11answers
2k views

Generate a mantis's head (symmetrical triangle)

Given guaranteed strictly positive integers \$w\$ and \$n\$, output An equilateral triangle array with side length \$w\$, filled with two distinct, consistent values. I'll call these ...
20
votes
14answers
1k views

List array elements which can be summed from other elements

Consider an array of unique integers, with an arbitrary length greater than 2. It is sometimes possible to express elements of the array as the sum of at least two other elements. For example, if our ...
15
votes
10answers
2k views

The Computer Thief

You wake up and find out that your computer has been stolen! You have a few sensors and scanners, but unfortunately, the footage is incomplete, so you want to find and rank your suspects for further ...
25
votes
18answers
1k views

Sum on a Fenwick Tree

Background Information: What is a Fenwick Tree? With a normal array, it costs \$O(1)\$ to access and modify an element, but \$O(n)\$ to sum \$n\$ elements. Working with a prefix sum array (an array ...
15
votes
23answers
956 views

Longest Sublist with Equal Occurrences

Given a non-empty list of integers between 1 and 9 inclusive, find the longest contiguous sublist such that the number of occurrences of each element (of the sublist) within the sublist is equal (not ...
19
votes
19answers
2k views

Guide my eyes in the right direction

Inspired by this: http://nolandc.com/smalljs/mouse_reveal/ (source). A valid answer: Takes a number \$w\$ and (assumed non-negative) integer \$x\$. Starts with an integer list with a length of \$2^w\$...
22
votes
33answers
2k views

Apply at indices

Given: a blackbox function \$f : \mathbb N \to \mathbb N\$, a list of positive integers \$L\$, and a list of indices \$I\$, apply \$f(x)\$ to the elements of \$L\$ at the indices specified in \$I\$. ...
15
votes
15answers
1k views

How many Faro shuffles for a cycle?

Background Inspired by this video by Matt Parker A Faro shuffle is a perfect riffle shuffle where the deck is exactly interleaved with its other half. This is how to perform one: the deck of 52 cards ...
10
votes
6answers
321 views

Generate the ticks of a graph

A challenge many developers face when drawing a graph from scratch to plot some data is generating its ticks. In below graph, there are 6 horizontal ticks (1750, 1800, 1830, 1860, 1880 and 1900) and ...
14
votes
8answers
2k views

Solve the Alien Probe puzzle

Introduction In this TED-Ed video (which I'd recommend watching first), a puzzle is presented. 27 unit cubes must be painted with one of red, green, or purple on each face, so that they can be ...
6
votes
20answers
885 views

Best Rolling Ao5

In speedcubing, an Ao5 (Average of 5) is computed for a set of five times by removing the fastest and slowest times, and then computing the mean of the remaining three times. A "rolling ao5" ...
1
vote
11answers
224 views

Implement ΔList [duplicate]

Given a list of integers, such as {1, 4, 2, 8, 10}, TI-Basic's ΔList will determine the difference between every overlapping ...
23
votes
37answers
1k views

Replace all items with their counts

Task: Given an array of numbers as input (you can choose what subset, such as integers or natural numbers), replace all items with the number of times they appear within the array. As an example, <...
17
votes
43answers
2k views

Are All the Items the Same?

Given a list of non-negative integers, return whether or not that list is all the same number. Rules Input and output can be taken/given in any reasonable and convenient format Truthy/Falsey values ...
25
votes
31answers
2k views

Close neighbours stick together

Given a list of positive digits, return that list with consecutive elements grouped together. For example: ...
25
votes
14answers
4k views

Is it better to walk or run in the rain?

The age-old question - is it better to walk or run? There are two trains of thought. If you run, you cause the rain to effectively hit you from the front, which increases your surface area and ...
26
votes
13answers
2k views

How many bystanders will help?

Flavortext The Bystander Effect is a phenomenon where individuals are less likely to help a victim if other people are present. The idea is that as there are more people around, the individual burden ...
22
votes
42answers
2k views

Output a Latin Square

An \$n\times n\$ Latin Square is a grid containing exactly \$n\$ distinct values where the values in each row and column are distinct. For example, $$\begin{matrix} A & B & C \\ C & A &...
15
votes
22answers
1k views

Remove first encountered elements from a second list

Inspired by this question on Stackoverflow. The task Let's have two lists/arrays of integers: L1 and L2 of equal length. You ...
1
vote
4answers
207 views

A problem of rarity [closed]

Given a positive input \$n > 0\$, output the amout of two types based on their rarity. The two types are called \$A\$ and \$B\$, we know the followings: \$n\$ is a limited input and the maximum is ...
12
votes
4answers
475 views

The Game of Cat And Mice | With Matrices

Challenge This coding challenge is to figure out how many rounds the cat can live. In a \$4\times4\$ matrix, there are a number of mice and exactly 1 cat. Example: $$ \begin{array} {|r|r|}\hline 🐭 &...
17
votes
21answers
1k views

Trim elements from the ends of a list

The aim is to trim elements in from the ends of a list, depending on if they are in a second list of "falsey" results. For example, if the first list is ...
17
votes
19answers
3k views

cadaddadadaddddaddddddr - linked list accessing

Create a function (or closest equivalent, or full program) that takes an list of some datatype (your choice) that may be nested and a string (in either order), and generalizes the lisp c[ad]+r ...
9
votes
2answers
223 views

Highest single-turn score in Match Land

Background Match Land is a mobile game that falls into the Match-3 genre (think Bejeweled or Candy Crush Saga series): swap two orthogonally adjacent pieces to make a 3-in-a-row or longer. However, ...
19
votes
29answers
2k views

Create all arrays of non-negative integers of length N with sum of parts equal to T

Create all arrays of non-negative integers of length N where the array sum is equal to T. The output order of arrays does not matter. Possible solutions are e.g. ...
12
votes
5answers
509 views

Subarrays With At Least N Distinct Integers

Given a sequence of integers and an integer N, output the number of contiguous subsequences that contain at least N distinct ...
12
votes
13answers
3k views

She sells sanctuary

A huge storm is ravaging the world and as you and your family run away from it, you come across a gigantic shelter run by a girl. She tells you that "she sells sanctuary" and that different ...

1
2 3 4 5
13