Skip to main content

Questions tagged [string]

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

Filter by
Sorted by
Tagged with
523 votes
986 answers
196k views

"Hello, World!"

So... uh... this is a bit embarrassing. But we don't have a plain "Hello, World!" challenge yet (despite having 35 variants tagged with hello-world, and counting). While this is not the most ...
Martin Ender's user avatar
396 votes
50 answers
59k views

Covfefify a string

In this challenge, you must take a string matching the regex ^[a-zA-Z]+$ or whatever is reasonable (you don't have to consider uppercase or lowercase letters if you ...
Destructible Lemon's user avatar
380 votes
1 answer
119k views

Regex that only matches itself

There are some pretty cool challenges out there involving regex (Self-matching regex, Regex validating regex) This may well be impossible, but is there a regex that will ONLY match itself? NOTE, ...
Dylan Madisetti's user avatar
230 votes
65 answers
19k views

No A, just CAPS LOCK

What happens when the CapsLock key on your keyboard doesn't have a notch in it? "This hPPENS." The goal of this program is to consistently emulate keyboard misses where each A press is replaced with ...
Broadwell's user avatar
  • 1,851
199 votes
419 answers
78k views

1, 2, Fizz, 4, Buzz

Introduction In our recent effort to collect catalogues of shortest solutions for standard programming exercises, here is PPCG's first ever vanilla FizzBuzz challenge. If you wish to see other ...
Beta Decay's user avatar
  • 23.4k
195 votes
64 answers
31k views

Mathematics is fact. Programming is not

In mathematics an exclamation mark ! often means factorial and it comes after the argument. In programming an exclamation mark ! ...
Calvin's Hobbies's user avatar
183 votes
29 answers
24k views

Do you want to code a snowman?

Here is a simple ASCII art snowman: _===_ (.,.) ( : ) ( : ) Let's make him some friends. This will be the general pattern for our ASCII art snowpeople: ...
Calvin's Hobbies's user avatar
171 votes
169 answers
57k views

Don't google "google"

We all know that if you google the word "google" it will break the internet. Your task is to create a function that accepts one string and returns its length, in the fewest possible Unicode ...
rybo111's user avatar
  • 4,567
165 votes
128 answers
33k views

Trick or Treat polyglot

Since Halloween is coming up I thought I might start a fun little code golf challenge! The challenge is quite simple. You have to write a program that outputs either ...
BrainStone's user avatar
  • 1,531
146 votes
92 answers
24k views

Hello, World! (Every other character)

Write a program that prints "Hello, World!". But also, if you take only the first, third, fifth, etc. characters of your program, the resulting program should still print "Hello, World!". If your ...
pommicket's user avatar
  • 3,187
131 votes
211 answers
35k views

Sing Happy Birthday to your favourite programming language

Your favourite programming language has just had a birthday. Be nice and sing it the Happy Birthday song. Of course you should accomplish this by writing a program in that language. The program takes ...
David Frank's user avatar
  • 2,484
127 votes
42 answers
23k views

La La Land... no wait, Moo Moo Moonlight

This challenge is a tribute to the winner of Best Picture at the Oscars 2017, La La Land Moonlight! Write a function/program that takes a string containing only letters ...
Stewie Griffin's user avatar
118 votes
62 answers
27k views

GO OUT AND VOTE

Today is November 8th, 2016, Election Day in the United States of America. If you are a U.S. citizen eligible to vote, then go out and vote if you haven't already before answering this challenge. Do ...
Calvin's Hobbies's user avatar
118 votes
76 answers
28k views

I'm a palindrome. Are you?

There have been a couple of previous attempts to ask this question, but neither conforms to modern standards on this site. Per discussion on Meta, I'm reposting it in a way that allows for fair ...
user avatar
112 votes
330 answers
22k views

Simple cat program

One of the most common standard tasks (especially when showcasing esoteric programming languages) is to implement a "cat program": read all of STDIN and print it to STDOUT. While this is named after ...
Martin Ender's user avatar
106 votes
93 answers
24k views

It took me a lot of time to make this, pls like. (YouTube Comments #1)

Hold up..... this isn't trolling. Background These days on YouTube, comment sections are littered with such patterns: ...
Arjun's user avatar
  • 5,074
105 votes
92 answers
10k views

Unique is Cheap

Write a function or program that determines the cost of a given string, where the cost of each character equals the number of how many times the character has occurred up to this point in the string,...
Laikoni's user avatar
  • 26.3k
101 votes
62 answers
14k views

Make a "Ceeeeeeee" program

Once I wrote a JavaScript program that would take as input a string and a character and would remove all characters except for the first one and the character given as input, one by one. For example, ...
Esolanging Fruit's user avatar
99 votes
36 answers
7k views

Would this string work as string?

Write a program that takes a single line string that you can assume will only contain the characters /\_‾. (That's forward and backward slash, underline and ...
Discrete Games's user avatar
96 votes
176 answers
24k views

"99 Bottles of Beer"

Write a program that outputs the lyrics to 99 Bottles of Beer, in as few bytes as possible. Lyrics: ...
GamrCorps's user avatar
  • 7,592
96 votes
16 answers
20k views

I am passive aggressive and want to insult my boss without him finding out

It's been a rough few months at work and I feel like I just want to scream right to my boss' face. I am, however, not one to directly confront people I have a problem with. I also don't want to lose ...
Christofer Ohlsson's user avatar
95 votes
173 answers
16k views

Print a Tabula Recta!

The Tabula Recta (sometimes called a 'Vigenere Table'), was created by Johannes Trithemius, and has been used in several ciphers, including all variants of Bellaso's Vigenere cipher and the Trithemius ...
user avatar
95 votes
167 answers
13k views

Determine whether strings are anagrams

Challenge Given two strings, work out if they both have exactly the same characters in them. Example Input word, wrdo This returns true because they are the ...
Tom Gullen's user avatar
  • 1,259
93 votes
254 answers
20k views

"DDoouubbllee ssppeeaakk!!"

Super simple challenge today, or is it? I feel like we've heard a fair bit about double speak recently, well let's define it in a codable way... Double speak is when each and every character in a ...
AJFaraday's user avatar
  • 11.8k
92 votes
9 answers
5k views

Golf an Advent Calendar

It's that time of year when many of us get our advent calendars! If you are unfamiliar with an advent calendar, these are special calendars used to count down advent in anticipation of Christmas. In ...
Dom Hastings's user avatar
  • 24.3k
91 votes
119 answers
12k views

N(e(s(t))) a string

To "function nest" a string, you must: Treat the first character as a function, and the following characters as the arguments to that function. For example, if the input string was ...
DJMcMayhem's user avatar
  • 59.4k
91 votes
110 answers
13k views

Count of "a"s and "b"s must be equal. Did you get it computer?

In the popular (and essential) computer science book, An Introduction to Formal Languages and Automata by Peter Linz, the following formal language is frequently stated: $$\large{L=\{a^n b^n:n\in\...
user avatar
87 votes
64 answers
8k views

From Programming Puzzles to Code Golf

Your task is to write a program that outputs the exact string Programming Puzzles (trailing newline optional), but when all spaces, tabs, and newlines are removed ...
user avatar
87 votes
29 answers
4k views

Vertically collapse text

Say I have text like this (each word on one line, with no spaces) Programming Puzzles & Code Golf That makes no sense! It totally defies the laws of physics. ...
Trebuchette's user avatar
  • 1,712
86 votes
40 answers
14k views

What my dog really hears

My dog is called Rex. Every time I scold him, he seems not very impressed and the only times I see him react is when I pronounce his name. If I say ...
Ewan Delanoy's user avatar
  • 1,045
86 votes
13 answers
8k views

Z̡̬a̧̯̔l̆̓g̛̘̟o̡ generator

Write a program or function that transforms an input string into Zalgo text. For example, for an input string Zalgo, a possible output might look like: ...
Fatalize's user avatar
  • 39.1k
84 votes
141 answers
28k views

The shortest code to invert bit-wise a binary string

Me thinks there aren't enough easy questions on here that beginners can attempt! The challenge: Given a random input string of 1's and 0's such as: ...
ToonAlfrink's user avatar
  • 1,304
84 votes
42 answers
13k views

Non-discriminating Programming

We say a string is non-discriminating if each of the string's characters appears the same number of times and at least twice. Examples "aa!1 1 !a !1" is non-...
Laikoni's user avatar
  • 26.3k
80 votes
59 answers
14k views

War is peace. Freedom is slavery. Ignorance is strength

As George Orwell wrote in 1984: War is peaceFreedom is slaveryIgnorance is strength Write a program or function that takes in one of the six main words from the Orwell quote and outputs its ...
Calvin's Hobbies's user avatar
79 votes
31 answers
6k views

Cracking the Enigma?

Introduction The Enigma was one of the first electro-mechanical rotor cipher machines used in World War II. That means that after a single letter is coded, it would change the key for the next letter. ...
Adnan's user avatar
  • 44.5k
79 votes
38 answers
5k views

Uncollapse digits

Task Given a string of English names of digits “collapsed” together, like this: zeronineoneoneeighttwoseventhreesixfourtwofive Split the string back into digits:...
lynn's user avatar
  • 69k
78 votes
66 answers
19k views

Sing Baby Shark

"Baby Shark" is a children's song about a family of sharks. Having long been popular as a campfire song, it has been popularized since the mid-2000s by social media, online video and radio. - ...
njha's user avatar
  • 997
76 votes
62 answers
11k views

Uncomment a COBOL program!

COBOL is a very old language, at the time of writing it is 58 years old. It is so old, in fact, that it has a very interesting quirk: the first six characters of each line are comments. Why is this, ...
LyricLy's user avatar
  • 3,683
75 votes
123 answers
17k views

Print the alphabet without using each vowel

Inspiration: in 1939, a man named Ernest Vincent Wright wrote a novel called Gadsby without using the letter 'e'. Your task is to write a set of (up to 5) programs in any language (which has a text-...
shamp00's user avatar
  • 1,261
75 votes
91 answers
17k views

Build me a brick wall!

Challenge I need help building a brick wall! Throw together some code for me using no input and produce the following output wall shown below: ...
Dylan's user avatar
  • 935
75 votes
61 answers
16k views

Hare Krishna Hare Krishna Krishna Krishna Hare Hare

Recently, I've seen Hare Krishna people with their mantra on the emblem and I've found it may be quite interesting to code golf. The challenge Write the Hare Krishna mantra, i.e.: ...
Dariusz Woźniak's user avatar
75 votes
45 answers
8k views

Happy Birthday V!

Thanks to @KritixiLithos for helping me out with this challenge! V is a programming language that I wrote so that I could use and extend vim for code-golf challenges. The very first commit was on ...
DJMcMayhem's user avatar
  • 59.4k
74 votes
155 answers
14k views

Print X without X (cop's thread)

This is the cop's thread of a cops-and-robbers challenge. You can view the robber's thread here A pretty common beginner style question is to print some string, but there's a catch! You need to do it ...
Wheat Wizard's user avatar
  • 99.6k
74 votes
45 answers
13k views

Code Johnny Code, Code!

Rock-and-roll founding father Chuck Berry sadly passed away today. Consider the chorus of his famous song "Johnny B. Goode": ...
Calvin's Hobbies's user avatar
74 votes
23 answers
8k views

Turtles All the Way Down

Write a program or function that takes in a positive integer and prints or returns a stack of that many ASCII-art turtles, where each turtle is larger than the one above it. Specifically, if the ...
Calvin's Hobbies's user avatar
74 votes
47 answers
4k views

Golfing A Weasel Program

Richard Dawkins in his book The Blind Watchmaker, describes a Weasel program. The algorithm can be described as follows: Start with a random string of 28 characters. Valid characters are all ...
Noelkd's user avatar
  • 1,105
74 votes
12 answers
13k views

Operation Unz̖̬̜̺̬a͇͖̯͔͉l̟̭g͕̝̼͇͓̪͍o̬̝͍̹̻

I'm sure you're all familiar with Z̃͗̇̚͟Ḁ̬̹̈̊̂̏̚L̜̼͊ͣ̈́̿̚G̱̮ͩ̃͑̆ͤ̂̚Õ̷͇͉̺̜̲ͩ́ͪͬͦ͐ ̪̀ͤͨ͛̍̈͢ĝ̭͇̻̊ͮ̾͂e̬̤͔̩̋ͮ̊̈ͭ̓̃n͖͎̘̭̯̳͎͒͂̏̃̾ͯe͕̖̋ͧ͑ͪ̑r̛ͩa̴͕̥̺̺̫̾ͭ͂ͥ̄ͧ͆t͍̻̘̆o͓̥ͤͫ̃̈̂r̹̤͇̰̻̯̐ͮ̈́ͦ͂͞. If not, you can play ...
Joshua's user avatar
  • 3,454
74 votes
12 answers
10k views

Reverse indentation

I've heard that your code can run faster if you indent it in reverse, so that the compiler can process it like a tree design pattern from the very top of the "branches" down. This helps because ...
Doorknob's user avatar
  • 71.6k
73 votes
85 answers
10k views

Output a googol copies of a string

I am interested in seeing programs which don't ask for any input, print a googol copies of some nonempty string, no less, no more, and then stop. A googol is defined as \$10^{100}\$, i.e., 1 followed ...
The Vee's user avatar
  • 869
73 votes
60 answers
5k views

Draw my downslashes

As a programmer, you've probably heard of forward slashes and backward slashes. But have you heard of downslashes? That's when you take a bunch of slashes, connect their ends and draw them going down. ...
DJMcMayhem's user avatar
  • 59.4k

1
2 3 4 5
45