Questions tagged [array-manipulation]

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

622 questions
Filter by
Sorted by
Tagged with
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 ...
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 ...
462 views

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

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 ...
370 views

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

Close neighbours stick together

Given a list of positive digits, return that list with consecutive elements grouped together. For example: ...
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 ...
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 ...
2k views

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

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 ...
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, ...
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. ...