Questions tagged [array-manipulation]

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

Filter by
Sorted by
Tagged with
10
votes
6answers
2k views

Game of Life, but on a 4-8-8 tiling

Background The 4-8-8 tiling looks like this: For the purpose of this challenge, we take the orientation of the tiling as exactly shown above. In plain English words, we take the tiling so that it can ...
8
votes
4answers
199 views

So is that maximum?

Given a map from arrays of integers of same size to single integers, determine if there is a set of indices such that the output is equal to the maximum of the elements at those indices for every ...
4
votes
0answers
113 views

How many fill buckets to blank? [duplicate]

The fill bucket is a tool available in many drawing tools which replaces a contiguous chunk of one color with a another color. We are going to define a fill bucket which operates on lists of non-...
11
votes
2answers
228 views

Draw constraint system #18762389

Background Page 219 of A New Kind of Science (a book by Stephen Wolfram, the creator of Mathematica) shows an interesting 2D pattern generated by constraints. The relevant section in the book starts ...
24
votes
31answers
3k views

"-rot" transform

Background -rot transform (read as "minus-rot transform") is a sequence transformation I just invented. This transform is done by viewing the sequence as a stack in Forth or Factor (first ...
19
votes
19answers
2k views

Hunt for discount

Story My local pizza delivery introduced new discount. You get 50% discount from every second item on your order. But being greedy capitalists, they forgot to mention that they will rearrange items ...
23
votes
17answers
2k views

Show me the trajectory

Given a list of integers find the "trajectory" that results from indefinitely moving the instructed steps to the right (left if negative), wrapping if necessary, starting at the first ...
9
votes
7answers
707 views

Reverse cadaddadadaddddaddddddr [closed]

The Lisp language has a family of functions car, cdr, cadr, etc for accessing arrays. For ...
24
votes
26answers
1k views

Split into sublists of specified sizes

05AB1E has the £ builtin which, given a list of integers b and a string s, splits ...
18
votes
19answers
5k 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 ...
20
votes
18answers
4k 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
485 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,...
21
votes
22answers
3k 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
375 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
147 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
169 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 ...
27
votes
38answers
3k 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
54 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
48answers
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
984 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
515 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
373 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
958 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
322 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
887 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
225 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
44answers
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 &...

1
2 3 4 5
13