Questions tagged [string]
A competition to solve a particular problem through the usage and manipulation of strings.
2,070
questions
501
votes
923
answers
172k
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 ...
390
votes
44
answers
56k
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 ...
368
votes
1
answer
115k
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, ...
218
votes
62
answers
18k
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 ...
192
votes
61
answers
30k
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 ! ...
183
votes
381
answers
65k
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 ...
182
votes
29
answers
23k
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:
...
167
votes
163
answers
55k
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 ...
165
votes
127
answers
32k
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 ...
140
votes
87
answers
23k
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 ...
127
votes
200
answers
33k
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 ...
123
votes
40
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 ...
117
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 ...
115
votes
70
answers
27k
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 ...
103
votes
310
answers
20k
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 ...
102
votes
90
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:
...
102
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,...
95
votes
34
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 ...
93
votes
54
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, ...
91
votes
165
answers
21k
views
"99 Bottles of Beer"
Write a program that outputs the lyrics to 99 Bottles of Beer, in as few bytes as possible.
Lyrics:
...
91
votes
14
answers
19k
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 ...
90
votes
145
answers
12k
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 ...
89
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 ...
88
votes
165
answers
15k
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 ...
87
votes
111
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 ...
86
votes
64
answers
7k
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 ...
86
votes
40
answers
13k
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
...
85
votes
212
answers
17k
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 ...
85
votes
28
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.
...
85
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:
...
84
votes
136
answers
27k
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:
...
80
votes
95
answers
12k
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:
mainly because this language ...
77
votes
66
answers
18k
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. - ...
77
votes
58
answers
13k
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 ...
76
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:
...
76
votes
37
answers
12k
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-...
75
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. ...
75
votes
36
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:...
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 ...
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 ...
73
votes
44
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 ...
73
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":
...
73
votes
29
answers
6k
views
2016 Time Capsule String: How Versatile Is Your Language?
About a year ago on Dec 31, 2015, I had the idea that:
We should make a time capsule string. Everybody gets to add one character and next new years we'll see who can make the best program out of all ...
72
votes
119
answers
16k
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-...
72
votes
155
answers
13k
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 ...
72
votes
49
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, ...
70
votes
10
answers
6k
views
Rock, Polyglot, Scissors
Write a program that is a polyglot in three languages that plays rock–paper–scissors.
The input for any version of the program is always one of the strings rock or ...
70
votes
56
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.
...
70
votes
12
answers
7k
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 ...
69
votes
57
answers
14k
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.:
...