Questions tagged [subsequence]

Challenges pertaining to a sequence within a larger sequence

Filter by
Sorted by
Tagged with
9 votes
11 answers
732 views

Otteretto Classic game scoring method

Brief description of the game In the game Otteretto Classic (which you can test directly in your browser; try it!) the player has to form palindromic sequences using adjacent cells on a square grid. ...
Luis Mendo's user avatar
  • 104k
-4 votes
7 answers
1k views

Straight pen strokes for Prime Numbers

Challenge You are supposed to output the series I recently designed which goes as follows which are pen stroke counts of ascending prime numbers: ...
Aitzaz Imtiaz's user avatar
7 votes
6 answers
378 views

Bumping Series Implementation

I have a follow-up question here from my previous question on Math SE. I am lazy enough to explain the content again, so I have used a paraphraser to explain it below: I was considering arbitrary ...
Aitzaz Imtiaz's user avatar
7 votes
18 answers
605 views

Find the largest sum of any contiguous subarray of the array [duplicate]

Let's say you are given an integer array. Create a function to determine the largest sum of any array's adjacent subarrays. For instance, the contiguous subarray with the largest sum is ...
user avatar
15 votes
23 answers
2k views

Find the first run of numbers summing to n

Given as input a positive nonzero integer n >= 10 and a sequence of digits 0-9 (which may be taken as a string or a list), ...
Ginger's user avatar
  • 5,420
14 votes
12 answers
1k views

Count the shared substrings with 2 programs

Write 2 programs in the same language which count the number of shared subsequences of consecutive elements from 2 given sequences. For example, given ...
Fatalize's user avatar
  • 38.4k
17 votes
9 answers
1k views

Longest alternating subsequence

inspired by Longest Increasing Substring Task Given a list of non-negative integers, output the length of its longest alternating subsequence. An alternating sequence is a sequence of numbers which ...
Bubbler's user avatar
  • 73.8k
29 votes
33 answers
3k views

Backronymiser឵឵

Background A backronym is an acronym that was formed from an existing word. For example, spam is actually named after the canned meat product as used in the Monty Python sketch, but can be ...
pxeger's user avatar
  • 23.3k
14 votes
11 answers
1k views

Make the list Fibonacci-like

Related, but not dupe. Challenge A list of integers \$a_1, a_2, a_3, \dots, a_n\$ (\$ n ≥ 1 \$) is Fibonacci-like if \$a_i = a_{i-1} + a_{i-2}\$ for every \$i > 2\$. Note that every list that ...
badatgolf's user avatar
  • 1,267
11 votes
7 answers
665 views

Shortest restricted superstring

Given two sets of strings, \$ D \$ and \$ R \$, find the shortest string which contains every string in \$ D \$, but contains none of the strings in \$ R \$. There are almost always multiple possible ...
pxeger's user avatar
  • 23.3k
19 votes
8 answers
2k views

Optimally break a string into words

Given a string, like potatocarrot, break it into the smallest number of substrings possible. These substrings can consist either be a single character, or one of a ...
Rydwolf Programs's user avatar
30 votes
35 answers
3k views

Is it a fibonacci-like sequence?

The Fibonacci Sequence is a sequence of positive integers where the first two elements are 1 and the rest are the sum of the previous two. It begins \$1, 1, 2, 3, 5, 8, 13\$ and continues forever. But ...
emanresu A's user avatar
  • 35.6k
12 votes
8 answers
836 views

All sequences as substrings

Make a program that outputs a sequence of integers so that every finite sequence of positive integers is a substring (continuous subsequence) of the output. For example, the following sequence ...
AnttiP's user avatar
  • 7,828
22 votes
23 answers
1k views

How many laps around the permutation?

Your input is an array of numbers: a permutation of \$\{1, 2 \dots n\}\$ for some integer \$n \geq 2\$. How many times must you repeat this list before you can "pick out" the numbers \$[1, 2 ...
Lynn's user avatar
  • 68.1k
21 votes
13 answers
2k views

Output every sublist ... eventually

You will be given as input an infinite stream of positive integers. Your task is to write a program which outputs an infinite sequence of lists with two requirements: All lists in the output are ...
Wheat Wizard's user avatar
  • 96.5k
16 votes
17 answers
905 views

Shuffle a subsequence

Thanks to rak1507 for the suggestion "Random" in this challenge always refers to "uniformly random" - of all possible choices, each has an equal chance of being chosen. Uniform ...
caird coinheringaahin g's user avatar
24 votes
27 answers
1k views

Check if the string is reshaped

Challenge Given an input string X, determine if X can be obtained from reshaping a strict prefix of itself (a prefix that is not ...
Fmbalbuena's user avatar
  • 3,127
24 votes
29 answers
3k views

AoCG2021 Day 2: Naughty or nice?

Part of Advent of Code Golf 2021 event. See the linked meta post for details. The story continues from AoC2015 Day 5, Part 2. Santa needs help figuring out which strings in his text file are naughty ...
Bubbler's user avatar
  • 73.8k
26 votes
34 answers
2k views

Even sum subarrays

Given an array of integers, count the number of contiguous subarrays with an even sum. You may assume that the array is non-empty, and contains only non-negative integers. This is code-golf, so the ...
dingledooper's user avatar
  • 22.3k
11 votes
22 answers
2k views

Park, Lake, Santa Fe [closed]

Given a long multi-sentence string, the goal is the count the occurrences of the following words: park, lake, ...
Taako's user avatar
  • 569
22 votes
22 answers
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 ...
tsh's user avatar
  • 34k
34 votes
26 answers
4k views

Is there a single straight line in the matrix?

Inspired by Wzl Determine if a given square binary matrix has exactly one row or column consisting of entirely 1s, and the rest of the matrix is ...
caird coinheringaahin g's user avatar
20 votes
19 answers
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\$...
Wezl's user avatar
  • 1,458
18 votes
19 answers
3k views

Did I die or not?

Given a permutation of the alphabet and an intended "word", determine if the word was guessed in a game of Hangman, where the permutation is the list of guesses. For example, given ...
caird coinheringaahin g's user avatar
14 votes
2 answers
517 views

What's my TIO uniqueness?

Try it online! currently has 680 listed languages, all of which are searchable. For most of those languages, when searching for it, you don't have to enter the entire string. For example, entering <...
caird coinheringaahin g's user avatar
12 votes
15 answers
795 views

Check if B is composed of substrings of A of length n

Given two strings \$ A \$ and \$ B \$ and a positive integer \$ n \$, determine whether \$ B \$ is composed entirely of (possibly overlapping) strict substrings of \$ A \$ of a length of at least \$ ...
pxeger's user avatar
  • 23.3k
18 votes
20 answers
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 ...
Wezl's user avatar
  • 1,458
19 votes
13 answers
1k views

Count strictly overlapping substrings

Given two strings a and b, count how many times b occurs as a substring in ...
pxeger's user avatar
  • 23.3k
44 votes
38 answers
8k views

Speed of Lobsters

From the subreddit r/SpeedOfLobsters: Edit the text of an image to create a new phrase This meme format/style is pretty self-explanatory. Simply have a browse through the subreddit if you need more ...
caird coinheringaahin g's user avatar
20 votes
19 answers
2k views

Vandalizing Marquees

A marquee is a low-tech board that allows customizable letters. For example, here is a marquee: SALE ON SNEAKERS However, someone might come along and vandalize it ...
Stephen's user avatar
  • 13.8k
18 votes
19 answers
2k views

The Fibonacci Rectangular Prism Sequence

What is the Fibonacci Rectangular Prism Sequence? The Fibonacci Rectangular Prism Sequence is a sequence derived from the Fibonacci sequence starting with one. The first 3 numbers of the Fibonacci ...
nthnchu's user avatar
  • 399
5 votes
11 answers
891 views

Even-Odd chunks

(Inspired by the Keg utility of this challenge) Given a non-empty input string, e.g. s c 1= e(a"E"), split the input into even-odd chunks. Example (Feel free to ...
user avatar
4 votes
2 answers
232 views

How many ways can given subsequence occur in given sequence?

Let me know if this task has already been posed. I haven't found it when I looked. Input master sequence \$\ X = x_1\dots x_n\$: sequence of characters, eg. \$\rm international\$ subsequence \$\ Y = ...
kyrill's user avatar
  • 615
46 votes
23 answers
4k views

Is it a circumfix?

Introduction We all know prefixes and suffixes. But there are other types of affixes that exist too. Such as circumfixes, a type of affix that has two parts, one of which is a prefix and another of ...
Sara J's user avatar
  • 3,755
39 votes
27 answers
3k views

Length-terminated sequences

We all know the age-old debate - should strings be length-prefixed or should they be null-terminated? Well, you've run into a blob of binary data and apparently whoever made it decided that the best ...
Sara J's user avatar
  • 3,755
24 votes
10 answers
3k views

Where are they calling from?

When making phone calls internationally, phone numbers are prefixed with a code indicating what country the number is located in. These codes are prefix codes, meaning that no code is a prefix of ...
Sara J's user avatar
  • 3,755
5 votes
2 answers
550 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 ...
Mike Ponemariko's user avatar
16 votes
13 answers
985 views

Determine if a grid contains another grid

Challenge Create a function takes in two 2-dimensional arrays of characters (or strings if the programming language does not have characters as a datatype) as inputs: a and b. If your language does ...
Hazard's user avatar
  • 161
32 votes
31 answers
4k views

Greatest common substring

Create a program or function which takes a list of strings as input, and outputs the longest string that is a substring of all input strings. If there are several substrings of equal length, and no ...
Sara J's user avatar
  • 3,755
25 votes
29 answers
3k views

Make me a metasequence

Background For this challenge, a 'metasequence' will be defined as a sequence of numbers where not only the numbers themselves will increase, but also the increment, and the increment will increase by ...
Geza Kerecsenyi's user avatar
5 votes
0 answers
215 views

Pattern Finder - Find Repeated Pattern in String [closed]

Introduction This is a little challenge with the goal of identifying repeated pattern "blocks" in a string, and outputting them with their frequency of occurence from left to right. A friend ...
R. Gosman's user avatar
19 votes
21 answers
920 views

Most contributing rows

Given a non-empty matrix of non-negative integers, answer which unique rows contribute most to the sum total of elements in the matrix. Answer by any reasonable indication, for example a mask of the ...
Adám's user avatar
  • 29.9k
20 votes
23 answers
3k views

Playing with the musical turtle

My two kids like to play with the following toy: The colored areas with the shapes inside can be touched and the turtle then lights the area and plays a sound or says the name of the color or the ...
Charlie's user avatar
  • 12.8k
18 votes
19 answers
4k views

Longest Repeating Subsequence of a Single Digit

Challenge: Given a positive integer, output the longest single-digit subsequence that occurs at least twice, AND has boundaries of another digit (or the start/end of the integer). An example: Input: <...
Kevin Cruijssen's user avatar
1 vote
10 answers
2k views

Indent your code according to Fibonacci

Okay, so I saw this in a meme and decided it'd be the perfect code golf challenge: I prefer to increase the side of my indents according to the Fibonacci sequence: ...
AJFaraday's user avatar
  • 11.8k
10 votes
8 answers
587 views

Codegolf Rainbow : Sorting Colors with Reflection

Introduction: After I posted two rainbow-related challenges: Codegolf Rainbow : Fun with Integer-Arrays 1 and Codegolf Rainbow : Draw in Black-and-White 2, the following comment was made by @ChrisM in ...
Kevin Cruijssen's user avatar
22 votes
2 answers
496 views

Subset Sum Orderings

A set of n positive numbers has 2^n subsets. We'll call a set "nice" if none of those subsets have the same sum. ...
isaacg's user avatar
  • 42k
12 votes
8 answers
2k views

Indexing Cha-Cha Slide

Introduction: Although I originally had a Dutch song in my head, where the lyrics are: "Doe 'n stapje naar voren, en 'n stapje terug" (which translated to "Take a little step forward, and a little ...
Kevin Cruijssen's user avatar
23 votes
11 answers
2k views

The Ever-Increasing Graph

Consider a one-dimensional sequence of numbers within a fixed range, i.e. [1, 2, 4, 6, 8, 0, 2, 7, 3] in range [0, 10⟩ The Ever-Increasing Graph* ** is a line ...
RvdV's user avatar
  • 333
7 votes
5 answers
433 views

Visit and exit an array

Challenge: Input: An integer n (> 0) An integer-array a of size ...
Kevin Cruijssen's user avatar