Questions tagged [string]

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

Filter by
Sorted by
Tagged with
21 votes
51 answers
4k views

Run Length Decoding

Write the shortest code in the language of your choice to perform run length decoding of the given string. The string will be supplied as input on stdin in the form ...
Coding man's user avatar
  • 1,321
2 votes
21 answers
1k views

string length comparer [closed]

this program has to take two strings and compare their length, then tell you which one is longer (string-a or string-b) and by ...
Math chiller's user avatar
0 votes
3 answers
5k views

javascript: smallest code to convert seconds to time [closed]

Given seconds like 11728, write the smallest javascript function that returns a string like 3hrs. 15min. 28sec. ...
AwokeKnowing's user avatar
7 votes
13 answers
835 views

Replace letters by their rank, keeping punctuation intact

The problem is simple. Given a string such as Hello World! the program would output 8-5-12-12-15 23-15-18-12-4-!. Any delimiters ...
Taka's user avatar
  • 83
12 votes
3 answers
3k views

Parse a Python string literal

The challenge is to parse a string like Python does and print the contents of the string. Input (command-line argument or stdin): a string literal (e.g. "hello") (...
flornquake's user avatar
  • 1,568
-5 votes
2 answers
598 views

Strings: Microsoft interview

You are given an array of strings , you have to construct a single array containing all of them so that the same array of strings can be reconstructed from the large array. The strings may contain any ...
user227541's user avatar
15 votes
1 answer
2k views

Fix unbalanced brackets [duplicate]

Consider the alphabet A ="()[]{}<>". Think of the characters in the alphabet as opening and closing brackets of 4 different types. Let's say that a string ...
Vladimir Reshetnikov's user avatar
28 votes
5 answers
3k views

Shortest common superstring

Given a list of strings s_0, s_1, ..., s_n find the shortest string S that contains each of ...
Zakharia Stanley's user avatar
3 votes
7 answers
2k views

Alien Name Generator [closed]

Task Write a function to generate names of aliens and their worlds, so that the output is of the form: Greetings Earthfolk, I am ____ of the planet _____. "...
Lucas's user avatar
  • 188
13 votes
7 answers
4k views

Reverse words without changing capitals or punctuation

Create a program with the lowest amount of characters to reverse each word in a string while keeping the order of the words, as well as punctuation and capital letters, in their initial place. By "...
nasonfish's user avatar
  • 263
3 votes
4 answers
355 views

Count characters in lo..ol and print a phrase [duplicate]

Assuming 'lol' with a variavle number of 'o's. Print a the following phrase: What does 1st, 2nd, 3rd, 4th ... 'o' stand for? Examples: ...
Maciej Goszczycki's user avatar
14 votes
10 answers
1k views

Create a Twitter Parser

Introduction You use Twitter (let's pretend, if not), where you are limited to 140 characters per individual tweet you care to share with the world. If you wanted to tweet to your followers Abraham ...
Gaffi's user avatar
  • 3,617
29 votes
55 answers
4k views

The world ends in ed

Taken straight from the ACM Winter Programming Contest 2013. You are a person who likes to take things literally. Therefore, for you, the end of The World is ed; the last letters of "The" and "World" ...
beary605's user avatar
  • 4,310
14 votes
14 answers
1k views

Output code-sized Lorem Ipsum [closed]

Output the same length of Lorem ipsum your code is! Rules: Code can't be identical to output No compression libraries Shortest program in two weeks wins No network usage, file reading and other ...
randomra's user avatar
  • 20.8k
11 votes
2 answers
971 views

Email validation

Write a function or program to validate an e-mail address against RFC 5321 (some grammar rules found in 5322) with the relaxation that you can ignore comments and folding whitespace (...
Peter Taylor's user avatar
  • 43.1k
14 votes
22 answers
2k views

Finding the most 'unique' word

Using you language of choice, write the shortest function/script/program you can that will identify the word with the highest number of unique letters in a text. Unique letters should include any ...
Gaffi's user avatar
  • 3,617
10 votes
5 answers
699 views

Arbitrary-Length Ternary Squarefree Words

A string is squarefree if it contains no substring twice in a row. It is possible to have an arbitrarily long squarefree word using a 3-letter alphabet. Write a program which accepts a positive ...
cardboard_box's user avatar
23 votes
28 answers
2k views

Cambridge Transposition

I'm sure most, if not all, of you have come across this at some point or another: Aoccdrnig to a rscheeachr at Cmabrigde Uinervtisy, it deosn't mttaer in waht oredr the ltteers in a wrod are, the ...
jdstankosky's user avatar
  • 1,554
4 votes
13 answers
1k views

Find The Least Common Characters

Given a string, find the 10 least common alpha-numeric characters within that string. Output should be formatted with numbers left-padded with spaces so they look like this: ...
beary605's user avatar
  • 4,310
6 votes
12 answers
970 views

Ode-cay Olf-gay

Write a program which accepts a sentence into stdin, and writes that sentence to stdout in pig latin. Here are some test cases which your program should handle: ...
Strigoides's user avatar
  • 1,205
-9 votes
2 answers
2k views

Implementing a Traffic Light Checker [closed]

A three-color traffic light must switch lights in the following order: red, green, yellow, red. To indicate when crossing slowly without a stop is permitted, the yellow signal may be flashed. To ...
BOWS's user avatar
  • 99
1 vote
2 answers
349 views

Storing a DNS name as compactly as possible in memory (preferably in C#) [closed]

What is the most compact way to encode/save DNS names in memory? For example, storing "www.google.com" as a string in .NET will result in the object being encoded as UTF-16, and it will consume twice ...
makerofthings7's user avatar
34 votes
6 answers
12k views

Balance chemical equations!

Bernd is a high school student who has some problems in chemistry. In class he has to design chemical equations for some experiments they are doing, such as the combustion of heptane ...
FUZxxl's user avatar
  • 10.1k
12 votes
27 answers
2k views

Removing unique elements from string

I came upon this question, because it seems to be very common use-case to find unique characters in string. But what if we want to get rid of them? Input contains only lower case alphabets. Only ...
user14742's user avatar
  • 239
16 votes
28 answers
2k views

Shorten text with Run Length Encoding

Shorten (or not) text using run length encoding Input: heeeello woooorld Output: 1h4e2l1o 1w4o1r1l1d Read lines from stdin. Print to stdout. Stderr is of course discarded. Assume there are ...
mroman's user avatar
  • 1,518
19 votes
30 answers
3k views

Print custom alphabet

The Challenge Display the alphabet from a given letter read from console input. If the letter is uppercase, you have to display the alphabet uppercased. The alphabet printed must end in the precedent ...
Averroes's user avatar
  • 4,087
5 votes
7 answers
501 views

Finding variables in code

Given some code in your language as a string, find and display all the variable names. Examples in pseudocode: ...
beary605's user avatar
  • 4,310
5 votes
6 answers
886 views

Detecting loops in in in strings

Given a string, mark which parts in the string repeat in box brackets, and write how many times it does so before the box. Example:st st st Hello ThereThere ...
beary605's user avatar
  • 4,310
25 votes
17 answers
2k views

Topographic Strings

Here is some example input, so I can explain what the problem is: ((1 2)(3 (4 5) moo)) (i (lik(cherries)e (woohoo))) Think of this line of text as a topographic ...
beary605's user avatar
  • 4,310
14 votes
38 answers
5k views

Remove vowels without using too many different characters

The challenge is to remove vowels (a, e, i, o, u) from string from STDIN (yes, I know, simple). You can expect that your program will be not ran with any arguments in ...
Kamila Borowska's user avatar
74 votes
122 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,251
28 votes
68 answers
8k views

Is string X a subsequence of string Y?

Given strings X and Y, determine whether X is a subsequence of Y. The empty string is regarded as a subsequence of every string. (E.g., '' and ...
r.e.s.'s user avatar
  • 3,112
17 votes
11 answers
8k views

Find the minimum edit distance between two strings

Explanation The edit distance between two strings is a function of the minimum possible number of insertions, deletions, or substitutions to convert one word into another word. Insertions and ...
Peter Olson's user avatar
  • 7,732
2 votes
3 answers
180 views

all occurences of each line from a file in another file for each line in the first file

This is a code golf problem: Say you have two files, one file s and one file h. The problem is that for each line l of s you should produce a list that contains all lines of h that contain l. By "...
Wes's user avatar
  • 121
5 votes
4 answers
590 views

Implement Oplop

Oplop is an algorithm to generate website specific passwords based on a master password and a keyword. It is described here: http://code.google.com/p/oplop/wiki/HowItWorks There's an online ...
skeevey's user avatar
  • 4,365
11 votes
8 answers
1k views

ASCII ruler generation

The challenge is to generate an ASCII character count ruler in the following format: ...
user2398029's user avatar
-2 votes
2 answers
3k views

Conversion to palindrome with minimal points used

Input: a word (2-100 characters) Convert this word to a palindrome: delete character - 13 points add character - 12 points increase character - 5 points ('d' > 'e') decrease character - 4 points ('n'...
e-MEE's user avatar
  • 123
7 votes
1 answer
711 views

String manipulation

The challenge is to manipulate strings using basic Vim-like commands Input: A string of text to be transformed. The input alphabet is [a-z]. A string of legal commands Output: The transformed ...
Pubby's user avatar
  • 1,249
54 votes
49 answers
26k views

Outputting ordinal numbers (1st, 2nd, 3rd)

I would like to generate (as a return result of a function, or simply as the output of a program) the ordinal suffix of a positive integer concatenated to the number. Samples: ...
Nicole's user avatar
  • 643
22 votes
24 answers
2k views

Find columns where all characters are the same

I came across this question on SO and thought it'd make a nice golf challenge. So here it is: Challenge: Write a program that reads a sequence of character strings, one per line, and outputs a list ...
Ilmari Karonen's user avatar
22 votes
9 answers
10k views

Generating PBM bitmap files from ASCII text

The PBM (Portable BitMap) format is a very simple ASCII black and white bitmap format. Here's an example for the letter 'J' (copy-pasted from the wikipedia link): P1 # This is an example bitmap of ...
ChristopheD's user avatar
  • 1,719
4 votes
14 answers
1k views

Write the shortest code to match a tail-repeating string where one character falls off the head in each repetition

In this code-golf, you will attempt to match a string that is tail-repeating with one character falling off the head on each iteration. The code needs to be able to accept a string, and return to the ...
Thomas Dignan's user avatar
-8 votes
8 answers
1k views

Smple way to get min & max

You will take a set of input numbers, and output the minimum and maximum of the set. You can either write two programs, with 1 program doing each function, or one combined program. Here's an example ...
linuxrules94's user avatar
11 votes
11 answers
3k views

Check if a string is a shuffle of twins

Explanation Two strings can be shuffled by interspersing their letters to form a new string, much like two piles of cards can be shuffled to form a single pile. For example, the strings ...
Peter Olson's user avatar
  • 7,732
4 votes
2 answers
1k views

Decompose a String

Challenge You are to write the shortest complete program that takes a string as input from STDIN and decomposes it as far as possible, and prints the composition to STDOUT. To decompose a string, ...
PhiNotPi's user avatar
  • 29k
15 votes
9 answers
4k views

Write a function that returns past tense of given verb

Challenge Write a function which takes an argument which is a verb, and returns the past tense of the verb. (Assume that the verb is regular) Past tense Note: consider y as neither consonant nor ...
JiminP's user avatar
  • 3,472
9 votes
7 answers
1k views

Program to Spoonerise words [duplicate]

A spoonerisation is swapping the first letter/pronounceable syllable of two or more words. Example: A lack of pies = A pack of lies. Bad salad = Sad ballad (ish) :) Challenge: Write a program to ...
Alex Coplan's user avatar
59 votes
82 answers
8k views

How to randomize letters in a word

According to some controversial story, the odrer of ltteres in a wrod deos not mttaer much for raednig, as lnog as the frist and lsat lteter macth with the orignial wrod. So, for fun, what would be ...
Tomalak's user avatar
  • 941
13 votes
9 answers
839 views

Soundex function

Write the shortest function to generate the American Soundex code for a surname only containing the uppercase letters A-Z. Your function must produce output consistent with all the linked page's ...
PleaseStand's user avatar
  • 5,587
17 votes
17 answers
4k views

Indent a string using given parentheses

Given the following input to the program: List of block start characters List of block end characters A string to format format the string with the blocks delimited by the two character sets ...
Prashant Bhate's user avatar