Questions tagged [string]

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

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

Human oriented string comparison

Traditionally when you compare two strings you use lexicographical comparison. That can be described by the recursive algorithm: $$ f(x, y)= \left\{\begin{array}[rr] \\ \mathrm{EQ} & \mathrm{if}\,\...
Wheat Wizard's user avatar
  • 96.6k
9 votes
15 answers
2k views

Sum of numbers of arbitrary length

Your function must accept 2 strings which are correct numbers. It needs to sum them up (without rounding and floating point errors) and return the result (which is also a correct number) without any ...
EzioMercer's user avatar
  • 1,473
14 votes
13 answers
2k views

Salacious Bacon Tripod

In a certain chatroom, we like making acronym jokes about the build tool we use called sbt. While it usually stands for "Scala Build Tool", we aim to come up with all sorts of meanings, such ...
lyxal's user avatar
  • 32.3k
11 votes
9 answers
915 views

Parse basic arithmetic into an AST

Introduction An abstract syntax tree (AST) is a tree of tokens that shows their connection to each other and syntactical meaning. They are commonly used in compilers and static analysis tools, as ...
Michael M.'s user avatar
10 votes
9 answers
802 views

Find the length of the longest substring with all different characters in O(n) time

Let's solve the same task as in this challenge but faster! Input: a non-empty string containing letters a-z Output: the length of a longest (contiguous) substring in which all letters are different ...
anatolyg's user avatar
  • 13.2k
14 votes
8 answers
1k views

Change the subject

Sometimes I feel like the conversation is going down the wrong path and take it upon myself to steer it in another direction. And this conversation is going wrong real fast, so I need to change the ...
noodle man's user avatar
  • 5,527
15 votes
20 answers
3k views

Guess the song title

I have this problem where I listen to so much music that I can never remember what songs are called. But even if I remember the lyrics, I won't always know the song's name. But lucky for me, there's a ...
noodle man's user avatar
  • 5,527
13 votes
17 answers
2k views

Remove duplicates from my academic transcript

Consider a list of subject, grade pairs. E.g. ...
Simd's user avatar
  • 2,028
16 votes
15 answers
1k views

Division between two strings

Inverse function of this challenge To (properly) multiply an string by an integer, you split the string into characters, repeat each character a number of times equal to the integer, and then stick ...
l4m2's user avatar
  • 20.7k
8 votes
9 answers
2k views

Wordle games without repeating letters

Given a word list, find all sets of five words of five letters each, such that the words of each set have 25 distinct letters in total. This challenge was inspired by this video by Matt Parker. ...
matteo_c's user avatar
  • 5,863
21 votes
21 answers
2k views

Is it true? Ask Pip!

Title is an homage to this classic challenge In Pip, the Scalar data type encompasses strings and numbers. A Scalar value is truthy in most cases. It is falsey only if: It is the empty string ...
DLosc's user avatar
  • 38k
15 votes
7 answers
933 views

Parse WebSocket frames

According to MDN, every WebSocket message is sent as one or more frames. Your job is to extract the payload given a (masked) client-to-server text frame. The steps to extract the payload is as follows:...
sheared's user avatar
  • 151
15 votes
5 answers
432 views

Flip the order of operations

Scientists have made contact with a parallel universe. Just one problem: They write math differently. Help the scientists make a program that can convert normal math expressions to their equivalent in ...
mousetail's user avatar
  • 11.8k
8 votes
32 answers
1k views

Keep elements in sequence that have a letter repeated at least 3 times

Challenge: Given the input array l with a list of strings, only keep the elements in the sequence that have a letter that's repeated at least 3 times. Like ...
U13-Forward's user avatar
  • 2,001
28 votes
45 answers
2k views

Replace 0s In a String With Their Consecutive Counts

Challenge Given a string of any length which contains only digits from 0 to 9, replace each consecutive run of the digit ...
user avatar
32 votes
30 answers
4k views

Replace all vowels with repeated "aeiou"

Let's say I have this string: s = "Code Golf! I love Code Golf. It is the best." I want to replace all the vowels with repeated "aeiou". Notes: ...
U13-Forward's user avatar
  • 2,001
16 votes
12 answers
801 views

CGAC2022 Day 20: Reconstruct Santa's Book

Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details. Oh no, Santa spilled wine all over his great book. Now most of the letters are illegible. How will Santa now know ...
mousetail's user avatar
  • 11.8k
12 votes
27 answers
2k views

Make every consonant after a vowel uppercase

I have a string like this: s = "helloworldandhellocodegolf" I want to make every consonant after a vowel uppercase. Desired output: ...
U13-Forward's user avatar
  • 2,001
13 votes
11 answers
428 views

Sorted strings filter

Input a list of strings a and a string s for search keyword. Find out all strings in a which ...
tsh's user avatar
  • 34k
20 votes
5 answers
981 views

Clutch Wordle solver with known inputs

Sometimes when you're playing Wordle, you get to your fifth guess and you can't figure out the word any more, so you start mentally running through the list of remaining iterations, both sensical and ...
Catija's user avatar
  • 301
15 votes
7 answers
916 views

CGAC2022 Day 12: Santa's gift and the laser lock

Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details. There's a good news and a bad news. Good news: you got a Christmas present from Santa. (Already?! Christmas is two ...
Bubbler's user avatar
  • 73.8k
13 votes
14 answers
1k views

CGAC2022 Day 10: Help Santa sort presents!

Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details. Santa likes to sort his presents in a special way. He keeps "uninterleaving" the pile of presents into ...
math scat's user avatar
  • 8,563
9 votes
15 answers
757 views

Join Columnar Strings

Write the shortest possible program or function that will join a list of columnar strings. For this challenge, columnar strings are defined as one-character-wide strings spanning across multiple lines....
bigyihsuan's user avatar
  • 8,618
25 votes
54 answers
3k views

Range of ASCII values

Your task Given a string, output the range of ASCII values. Example Let's say we have the string Hello. We get the ASCII values: ...
The Thonnu's user avatar
  • 17.8k
14 votes
6 answers
1k views

Shortest path between two directories

The challenge is to write a program which will find the shortest (least number of characters) command which will navigate to a target directory, given a starting directory, assuming a standard linux ...
Ted's user avatar
  • 149
-10 votes
4 answers
346 views

Fastest code: Does a list of string contains %s, %d, %f, or %r?

The aim is to create an algorithm to detect that one of the string in a small list of strings contains %s, %d, ...
Jylo's user avatar
  • 313
15 votes
23 answers
3k views

Rarity of a String

Input: A string Output: The rarity of the string, as described below. To find the rarity of a string, follow the steps below. Start with 0. Subtract 3 for each E, A, T, or O in the string. Subtract 2 ...
user avatar
17 votes
17 answers
2k views

Number to letters

Your task Given a numerical string or integer \$\ge 0\$ (which may have leading zeros), convert it to letters using the below rules. Rules Loop through the digits: If the digit is ...
The Thonnu's user avatar
  • 17.8k
14 votes
7 answers
762 views

Implement Casio's M

The task Most Casio calculators featured a variable M, which has 3 operators related to it: M, ...
oeuf's user avatar
  • 1,793
8 votes
8 answers
662 views

LS, Part 1: Ana Gram

Warning: Wouldn't you rather answer a challenge about ponies?1 If you have read The Hostile Hospital, you would know that the Baudelaire orphans, from one of the scraps of paper recovered from the ...
UndoneStudios's user avatar
-11 votes
13 answers
347 views

Check if my input was 'hi whats up' without using any of those letters in your code

Write a script, program or function which takes one input of type string and outputs or returns some sort of indication wether the input string was 'hi whats up' (without the apostrophes) or not. You ...
Squareoot's user avatar
  • 145
25 votes
49 answers
2k views

Maximum average ord

Your task Take a list of strings as the input, and output the maximum average ord. Example Given the list ...
The Thonnu's user avatar
  • 17.8k
26 votes
15 answers
2k views

Is this series of quotes valid Python?

Python string parsing has quite a few edge cases. This is a string: "a" Putting 2 strings immediately after each other implicitly concatenates them, so ...
mousetail's user avatar
  • 11.8k
19 votes
25 answers
2k views

Remove the last 'n' occurences of a substring from a string

Given a string and a substring and a positive integer n. Remove the n occurences of a substring from the end of the originally ...
anoman's user avatar
  • 319
19 votes
15 answers
1k views

Character insertion on letterboards

You know those letterboards outside old-style cinemas which show upcoming films - perhaps you have a miniature one in your home? If you've operated one, you'll know that you can normally add letters ...
FlipTack's user avatar
  • 14.6k
27 votes
54 answers
3k views

Alphabet Checksum

Your task Given a string of lowercase letters, output the "alphabet checksum" of that string, as a letter. Example Let's say we have the string "helloworld". With ...
The Thonnu's user avatar
  • 17.8k
13 votes
7 answers
793 views

Box blur the string

Box blur is a simple operation for blurring images. To apply box blur, simply replace each pixel with the average of its and the surrounding 8 pixels' values. Consider, for example, the following ...
Jordan's user avatar
  • 9,726
33 votes
37 answers
3k views

Is it an alphadrome?

An alphadrome is a word in which each letter in the first half of the word "reflects" its alphabetical "opposite" in the second half of the word. Write a program or function that ...
Jordan's user avatar
  • 9,726
14 votes
13 answers
2k views

Make a Court Transcriber

Discussion in courtrooms often occurs at a high speed and needs to be accurately transcribed in case the text of the decision is needed in future cases. For this purpose, the stenographers who ...
Ginger's user avatar
  • 5,420
31 votes
52 answers
3k views

Number to String in aaaaa way!

In this challenge, you are going to take a number and turn it into a string, but not in the common way. You will use the aaaaa way! The ...
Mehan Alavi's user avatar
12 votes
39 answers
3k views

Hexadecimal -> Binary Art

Take a list of 2-digit hexadecimal numbers as input, and output the binary value, replacing each 1 with an 'X', and each 0 with a space. For example Input = ...
The Thonnu's user avatar
  • 17.8k
17 votes
11 answers
2k views

Numbers vs. Strings: Language fitness challenge

inspired by thejonymyster's idea Rules This challenge is about finding languages that are very suitable for one task but quite the opposite in the other. The two tasks share a theme, but Task 1 is ...
Bubbler's user avatar
  • 73.8k
-12 votes
8 answers
498 views

Write "tut-tut-tut" without using "tut"

Following this question: Tut-tut-tut-tut-tut Write a program that writes "tut-tut-tut" without using the characters "t", "u" or "-" in the code itself. This is ...
JuanCa's user avatar
  • 187
38 votes
11 answers
3k views

Re-name all identifiers to a single letter

Imagine a very simple language. It has just 2 syntax features: () indicates a block scope, and any word consisting only of 1 or more lower case ASCII letters, which ...
mousetail's user avatar
  • 11.8k
44 votes
28 answers
6k views

Tut-tut-tut-tut-tut

The string tut-tutut-tut-tuttut-tut can be constructed with overlapping or concatenated instances of the word tut-tut: ...
Sisyphus's user avatar
  • 14.7k
21 votes
5 answers
642 views

Does there exist a synchronizing word?

A complete deterministic finite automaton is a machine, with some states. Each state in the automaton has, for each character in the alphabet, a pointer to a state (not necessarily a different one). ...
Command Master's user avatar
9 votes
6 answers
389 views

Change the quotations as if in Microsoft Word

I noticed that in Microsoft Word, single quotations are either or , but not in Notepad. Your task today is: given a string <...
UndoneStudios's user avatar
19 votes
36 answers
2k views

Divisor of a string

Challenge Given a positive-length string \$S\$, a divisor of \$S\$ is another (not necessarily distinct) string for which there exists a number \$a\$ such that when we repeat the divisor \$a\$ times, ...
badatgolf's user avatar
  • 1,267
23 votes
17 answers
3k views

Add parentheses to Polish notation

In most programming languages, arithmetic is written with infix notation -- i.e. the operator is put in between the operands -- e.g. 1+2. In contrast, with Polish ...
97.100.97.109's user avatar
4 votes
3 answers
1k views

Python: can I shorten this code further for checking substrings

So the golf question was like this: You are given a number T and then a total of T number of 17-character strings. For each of ...
chnmasta05's user avatar

1
2
3 4 5
44