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

learn more… | top users | synonyms

14
votes
25answers
2k views
+50

Generate a Stack Exchange Favicon

Do you recognize the PPCG logo? it looks like this, when you do an ascii art of it. +---+ |PCG| +---+ v Now, In this Code Golf, You will make a code, that makes logos for other sites, similar to ...
55
votes
21answers
10k views

The kitten command

A kitten is much like a cat. Some of the main differences are cuteness, lack of intelligence, and size. Similarly, the cat command is different from the kitten command. Fortunately, there is only one ...
23
votes
19answers
1k views

Detriplicate a string

A lot of languages have built-in ways to get rid of duplicates, or "deduplicate" or "uniquify" a list or string. A less common task is to "detriplicate" a string. That is, for every character that ...
31
votes
17answers
4k views

One Ring to rule them all. One String to contain them all

Objectives: Output a String which contains every positive integer strictly below 1000. The obvious answer would be to concatenate every one of them, and that would create a String of 2890 characters (...
186
votes
448answers
40k 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 ...
53
votes
103answers
10k views

“99 Bottles of Beer”

Write a program that outputs the lyrics to 99 Bottles of Beer, in as few bytes as possible. Lyrics: 99 bottles of beer on the wall, 99 bottles of beer. Take one down and pass it around, 98 bottles ...
76
votes
142answers
13k 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 ...
48
votes
45answers
6k views
+100

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 ...
14
votes
8answers
833 views

Find numbers within the Copeland–Erdős constant

Background The Copeland–Erdős constant is the concatenation of "0." with the base 10 representations of the prime numbers in order. Its value is 0.23571113171923293137414... See also OEIS A033308. ...
41
votes
24answers
4k views

Polar Bear, Polar Bear, what do you hear?

The text of the children's book Polar Bear, Polar Bear, What Do You Hear? has a very simple pattern. You might use the text to teach introductory programming concepts. My son was quickly bored by ...
-22
votes
20answers
405 views

Reverse a 1-dimensional array

Note: This challenge is not the same. Challenge Believe it or not, we haven't got ONE challenge for reversing one-dimensional arrays (although we've got one for n-dimensional ones)! This should ...
25
votes
22answers
3k views

How many IP addresses are in a given range?

Inspired by... Networking - How can I work out how many IP addresses there are in a given range? Write a program or function that takes two strings as input, each being an IPv4 address ...
24
votes
49answers
3k views

Longest Common Prefix of 2 Strings

Write a program that takes 2 strings as input, and returns the longest common prefix. This is code-golf, so the answer with the shortest amount of bytes wins. Test Case 1: "global" , "glossary" "glo"...
48
votes
156answers
9k 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 ...
22
votes
24answers
2k views

Write a program that reverses the name of its source file

In a single file, write a program that requires no input and produces no output. When run it should reverse the name of the file it is contained in, regardless of what the name is, without altering ...
26
votes
15answers
1k views

Remove duplicated & switched case

Goal The goal of this challenge is: given a string as input, remove duplicate pairs of letters, if the second item in the pair is of opposite capitalization. (i.e. uppercase becomes lowercase and ...
5
votes
4answers
255 views

Semi-decide Post's Correspondence Problem

The Post's Correspondence Problem (PCP) gives you a list of pairs of strings, P_1 ... P_n. Your task is to find a k, and some sequence of k indices such that fst(P_i1) ... fst(P_ik) = snd(P_i1) ... ...
32
votes
36answers
3k views

Output the alphabet, the ALPHABET, or just a character

The challenge is simple: Write a function or program that takes an input x, and outputs the lower case alphabet if x is part of the lower case alphabet, outputs the upper case alphabet if x is part ...
14
votes
8answers
2k views

Remove single line and multiline comments from string

Goal Using the programming language of your choice, write the shortest program to eliminate comments from a string representing a C program. Input The string can be... given as a function ...
23
votes
22answers
2k views

Which ghosts are missing?

In this challenge, given a list of ghosts from Pac-Man, you must output which ghosts are missing. You must do it in as few bytes as you can Input Input will consist of a string or list, which will ...
26
votes
42answers
4k views

Lithp Tranthlator

My friend made a lisp translator the other day, that is to say it took a string and converted s=>th and S=>Th. It was quite long and I thought that it could be golfed. So the task is to make a ...
13
votes
41answers
2k views

Generate alphabet with 4 copies of each letter

Note that this is not the same as Print the alphabet four times. This task is to write a program to generate four copies of each letter of the English alphabet, one letter per line, on standard ...
14
votes
6answers
372 views

Generalization of abbreviations

Given an input of a list of words and their abbreviations, output the pattern by which the abbreviations can be formed. Let us take the example input of potato ptao puzzle pzze as an example (that ...
17
votes
10answers
1k views

What exactly was your question?

Introduction When you are given a boring text, you just want to get it over with as quick as possible. Let's observe the following text: Ens colligi timenda etc priorem judicem. De quascunque ii at ...
22
votes
31answers
3k views

Reverse a string while maintaining the capitalization in the same places

The goal here is to simply reverse a string, with one twist: Keep the capitalization in the same places. Example Input 1: Hello, Midnightas Example Output 1: SathginDim ,olleh Example Input 2: .Q ...
23
votes
30answers
5k views

What is the most frequent word?

What is the most frequent word? Given a sentence, your program must make it's way through it, counting the frequencies of each word, then output the most used word. Because a sentence has no fixed ...
21
votes
18answers
2k views

Unzip some numbers

Your task is to create a program or function that generates a zipper with a length of 10 lines. Each line of the zipper is represented by two dashes --: -- -- -- -- -- -- -- -- -- -- The program/...
15
votes
26answers
1k views

Convert n strings of m length to m strings of n length

Write a program that, given any 'n' number of strings of 'm' length, returns 'm' number of 'n'-length strings, with this condition: Every new string should contains the letters at the same index of ...
8
votes
6answers
813 views

TUT language translator

Text may be translated to a written version of TUT language by replacing each letter by the corresponding "TUT word", as given in the following table (adapted from the linked article)*: a e h ...
17
votes
13answers
446 views

Directory calculation

For this challenge, you will be given an absolute path, and a "new" path (which can be absolute or relative), and you need to return the final path. For example, if your current directory was /var/...
21
votes
24answers
3k views

#Hashtag_or_not

In this code golf, You will verify Hashtags! #What_your_code_should_do Input a string. output truthy value if it is a valid hashtag, and falsy value if not. We define a string as a valid Hashtag if....
14
votes
20answers
786 views

Select the word around the given index in a given string

In Windows, when you perform double-click in a text, the word around your cursor in the text will be selected. (This feature has more complicated properties, but they will not be required to be ...
8
votes
7answers
319 views

Write a program to display directory treehouse

Given a directory (such as C:/), given from stdin or read from a file, produce a directory tree, with each file/folder indented based on its depth. Example If I have a C:/ drive which only contains ...
29
votes
44answers
3k views

Is it a pangram?

Write a function or program that takes as its input a string and prints a truthy value if the string is a pangram (a sequence of letters containing at least one of each letter in the English alphabet) ...
44
votes
18answers
9k views

Can Pac-Man Eat This String?

In the arcade version of the game, Pac-Man eats pac-dots. However, in this challenge, he's hungry for alphanumeric characters and punctuation in a string. Your task is to create a function that feeds ...
9
votes
3answers
374 views

Find the paths!

You must write a program or function. The input is a 'map' of numbers. You can choose to take the map as either a string with new line characters (\n) or a 2D array of strings. All maps are 5 ...
21
votes
7answers
842 views

I programming puzzles, il code golf

Background The Italian definite article (corresponding to English the) has seven different forms: l', il, lo, gli, i, la, le. Which one to use depends on three variables: Gender: masculine / ...
13
votes
4answers
311 views

Interpret the Pig series

Given an input of a Pig, SickPig, DeadPig, QuinePig, or DeafPig program, choose one of those "languages" randomly and interpret the input as that "language." First, randomly choose between one of the ...
16
votes
83answers
3k views

Full Width Text

Full width text is text that has a space after every character, including the last one. For instance, the first sentence of this question becomes: F u l l w i d t h t e x t i s t e x t t h ...
38
votes
26answers
3k views

Check if a UUID is valid without using regexes

Given a string input, write a program that prints a truthy value to STDOUT or equivalent if the input is a valid UUID, without using regexes. A valid UUID is 32 hexadecimal digits, displayed in ...
23
votes
20answers
973 views

N Slab Slanted Slash Cake

Write a program or function that takes in a positive integer N. When N is 1, output /\ \/ When N is 2, output /\/\ \/ / / / \/ When N is 3, output /\/\/\ \/ / / / / / \/ / / / \/ When N is 4,...
20
votes
28answers
3k views

24 and 12 Hour Times

Write a program or function with no input that prints or returns this string of 24-hour and 12-hour times: 00:00 12:00am 01:00 1:00am 02:00 2:00am 03:00 3:00am 04:00 4:00am 05:00 5:00am 06:00 6:...
25
votes
32answers
2k views

Duplicate & switch case

The goal is, having taken a string as input, duplicate each latin letter and "toggle" its case (i.e. uppercase becomes lowercase and vice-versa). Example inputs & outputs: Input Output bad ...
21
votes
21answers
1k views

Post-determined Array Sorting

Input: An array containing three integers: 0, 1 and 2 in any order (i.e. [2, 0, 1]) And a string of length >= 2 only containing alphabetic letters (both lower- and uppercase) and digits (i.e. a1B2c3)...
23
votes
15answers
3k views

A Geometrical Challenge

Everybody loves geometry. So why don't we try and code golf it? This challenge involves taking in letters and numbers and making shapes depending on it. The Input The input will be in the form of (...
33
votes
16answers
3k views

Determine the “Luck” of a string

Given a string, return that string's "luck". A string's luck, as I completely just made up for the purpose of this challenge, is an integer, determined as so: The base luck for a string is 1. For ...
3
votes
3answers
339 views

Do not repeat yourself

Inspired by this challenge Given a number m, output a program that prints out the string Do not repeat yourself. Now for the challenging part: Each program the original code prints out has to have ...
1
vote
3answers
268 views

Random word-sentence-story generator

This question got me nostalgic: Build a word generator! In the '80s I wrote a simple word generator in under 42kB (code and working memory) that would take a collection of strings and use them to ...
15
votes
1answer
243 views

Can I live here?

In the game Terraria, one of the game mechanics involves building houses so that an NPC can move in. There is a strict set of rules for what counts as a valid house or not. Here is the list of rules: ...
23
votes
1answer
406 views

Domain Name Appraisal

Domain name trading is big business. One of the most useful tools for domain name trading is an automatic appraisal tool, so that you can easily estimate how much a given domain is worth. ...