Questions tagged [string]
A competition to solve a particular problem through the usage and manipulation of strings.
2,143
questions
4
votes
13
answers
986
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:
...
6
votes
12
answers
958
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:
...
-8
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 ...
1
vote
2
answers
342
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 ...
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 ...
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 ...
15
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 ...
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 ...
5
votes
7
answers
496
views
Finding variables in code
Given some code in your language as a string, find and display all the variable names.
Examples in pseudocode:
...
5
votes
6
answers
875
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
...
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 ...
13
votes
31
answers
4k
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 ...
73
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-...
27
votes
66
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 ...
17
votes
11
answers
7k
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 ...
2
votes
3
answers
171
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 "...
5
votes
4
answers
581
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 ...
11
votes
8
answers
1k
views
ASCII ruler generation
The challenge is to generate an ASCII character count ruler in the following format:
...
-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'...
7
votes
1
answer
701
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 ...
53
votes
49
answers
24k
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:
...
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 ...
21
votes
9
answers
9k
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 ...
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 ...
-7
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 ...
11
votes
9
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 ...
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, ...
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 ...
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 ...
57
votes
75
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 ...
13
votes
9
answers
831
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 ...
17
votes
17
answers
3k
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 ...
10
votes
5
answers
695
views
Simple Tag Parser
This is a model of a forgiving HTML parser. Instead of parsing HTML and extracting attributes, in this code golf, the tag parser will be simple.
Write a function that parses a tag structure and ...
48
votes
79
answers
8k
views
Answer to life, the universe, and everything
Task
Given a String as input, your task is to output 42 only if the input String happens to be exactly the following :
...
21
votes
46
answers
2k
views
Detect rotated strings
Read two strings from stdin.
Output Yes if one string is a rotated version of the other.
Otherwise output ...
91
votes
158
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 ...
-3
votes
9
answers
397
views
Mixed up output [duplicate]
Write a function or program that outputs the following lines <input> time:
...
8
votes
1
answer
1k
views
Random Sentence Generator
Write the shortest program you can in any language that reads a context-free grammar from and the number of sentences to produce from stdin, and generates that many ...
12
votes
15
answers
715
views
Finish a symmetrical map
You are given one-quarter of a map that is symmetrical over the x- and y-axes as input. The program should print the complete map.
The map can contain the following characters: ...
18
votes
37
answers
2k
views
Sum of integers in string, separated by non-numericals such as 'a' and 'Y'
Create a program which sums all integers found in a string which is set as a variable in the program (thus, the program doesn't have to handle any input). The integer numbers are separated by non-...
24
votes
20
answers
2k
views
Chris Pine's "Deaf Grandma"
I'm a mentor at RubyLearning and one of the exercises we give to our students is the "Deaf Grandma" exercise from Chris Pine's book "Learn to Program". Here's the description:
Write a Deaf Grandma ...
65
votes
130
answers
11k
views
Reverse stdin and place on stdout
Requirements:
Take an input on stdin including new lines / carriage returns of unlimited length (only bounded by system memory; that is, there is no inherent limit in the program.)
Output the reverse ...
25
votes
35
answers
2k
views
Finding "sub-palindromes".
The shortest code that finds all unique "sub-palindromes" of a string, that is: any substring with length > 1 that is a palindrome.
eg.1
...