I just came across this little problem on UVA's Online Judge and thought, that it may be a good candidate for a little code-golf.
The problem:
You are to design a program to assist an architect in drawing the skyline of a city given the locations of the buildings in the city. To make the problem tractable, all buildings are rectangular...
Here's my (code golf) challenge:
Take two arrays of bytes and determine if the second array is a substring of the first. If it is, output the index at which the contents of the second array appear in the first. If you do not find the second array in the first, then output -1.
Example Input:
{ 63, 101, 245, 215, 0 } { 245, 215 }
Expecte...
The challenge
The shortest code by character count, that will input a string using only alphabetical characters (upper and lower case), numbers, commas, periods and question mark, and returns a representation of the string in Morse code.
The Morse code output should consist of a dash (-, ASCII 0x2D) for a long beep (AKA 'dah') and a dot...
The challenge
The shortest code by character count to generate a wave from the input string.
A wave is generated by elevating (line-1) a higher character, and degrading (line+1) a lower character. Equal characters are kept on the same line (no elevating or degrading done).
Input is made of lower case characters and numbers only, lett...
I challenge you to write a mathematical expression evaluator that respects PEMDAS (order of operations: parentheses, exponentiation, multiplication, division, addition, subtraction) without using regular expressions, a pre-existing "Eval()"-like function, a parsing library, etc.
I saw one pre-existing evaluator challenge on SO (here), b...
(Edit: What is Code Golf: Code Golf are challenges to solve a specific problem with the shortest amount of code by character count in whichever language you prefer. More info here on Meta StackOverflow. )
Code Golfers, here's a challenge on string operations.
Email Address Validation, but without regular expressions (or similar parsin...
The challenge
The shortest code by character count to generate seven segment display representation of a given hex number.
Input
Input is made out of digits [0-9] and hex characters in both lower and upper case [a-fA-F] only. There is no need to handle special cases.
Output
Output will be the seven segment representation of the inpu...
In Google Code Jam 2009, Round 1B, there is a problem called Decision Tree that lent itself to rather creative solutions.
Post your shortest solution; I'll update the Accepted Answer to the current shortest entry on a semi-frequent basis, assuming you didn't just create a new language just to solve this problem. :-P
Current rankings:
...
The challenge
The shortest code by character count to input a 2D representation of a board, and output 'true' or 'false' according to the input.
The board is made out of 4 types of tiles:
# - A solid wall
x - The target the laser has to hit
/ or \ - Mirrors pointing to a direction (depends on laser direction)
v, ^, > or < - The la...
What are your favourite short, mind-blowing snippets in functional languages?
My two favourite ones are (Haskell):
powerset = filterM (const [True, False])
foldl f v xs = foldr (\x g a -> g (f a x)) id xs v -- from Hutton's tutorial
(I tagged the question as Haskell, but examples in all languages - including non-FP ones - are welco...
I'm interested in learning a new language.
Does anyone know of a website with the same program (maybe a Hello World) written in several different languages (maybe 10-15 or so), so that I can get an idea of how the syntaxes compare.
...
After having had code-golf contests on ordinary mathematical expressions, I just thought it would also be quite interesting how short an evaluation function for postfix notation (RPN) can be.
Examples for RPN:
1 2 + == 3
1 2 + 3 * == 9
0 1 2 3 + + - 2 6 * + 3 / 1 - == 1
3 2 / 2.0 + == 3.5
To make things shorter, only +, -, * and /, a...
The challenge
The shortest code by character count that will generate a beehive from user input.
A beehive is defined a a grid of hexagons in a size inputted by the user as two positive numbers greater than zero (no need to validate input). The first number (W) represents the width of the beehive - or - how many hexagons are on each ro...
The challenge
The shortest code by character count, that will output musical notation based on user input.
Input will be composed of a series of letters and numbers - letters will represent the name of the note and the number will represent the length of the note. A note is made of 4 vertical columns. The note's head will be a capital...
How should I implement the classic bubble sort algorithm? I'd particularly like to see a C++ implementation, but any language (even pseudocode) would be helpful.
P.S. Not a homework.
...
The challenge
The shortest code by character count, that will output playing bricks tower series according to user input.
The input will be a series of numbers (positive, negative and zero) that represents the height of the current cube tower following their index. A height of 0 means no tower and is spaced.
A cube tower is composed o...
I have been starting to write scripts to do some simple work in modifying existing code files - mostly finding some block of text, and making a few changes based on regular expressions within that block.
These are the kinds of tasks that are beyond simple sed (or even awk) style search and replace or modify in a stream. Basically one o...
Ok this one is like my previous array searching challenge but with a twist.
You must build a function to search one 2d array (or suitable equivalent in your language) of 32-bit integers for another, and return the X and Y index that the second array exists within the first. If the second array does not completely and contiguously exist ...
The challenge
The shortest code by character count to output a spider web with rings equal to user's input.
A spider web is started by reconstructing the center ring:
\_|_/
_/ \_
\___/
/ | \
Then adding rings equal to the amount entered by the user. A ring is another level of a "spider circles" made from \ / | and _, an...
A friend just brought by 1,000 lines of USA shipping addresses. (Excel.) I've read this into a Ruby program via CSV::.
Now I would like to check the mailing addresses for sanity. It doesn't have to be a perfect check. Her shipping contractor will be using a UPS program of some sort and we are just trying to minimize the number of addres...