rosetta-stone

Code Golf: Code 39 Bar Code

The challenge The shortest code by character count to draw an ASCII representation of a Code 39 bar code. Wikipedia article about Code 39: http://en.wikipedia.org/wiki/Code_39 Input The input will be a string of legal characters for Code 39 bar codes. This means 43 characters are valid: 0-9 A-Z (space) and -.$/+%. The * character w...

File Fix-it codegolf (GCJ 2010 1B-A)

Last year (2009), the Google Code Jam featured an interesting problem as the first problem in Round 1B: Decision Tree As the problem seemed tailored for Lisp-like languages, we spontaneously had an exciting codegolf here on SO, in which a few languages managed to solve the problem in fewer characters than any Lisp variety, using quite a...

Code Golf: 1x1 black pixel

Recently, I used my favorite image editor to make a 1x1 black pixel (which can come in handy when you want to draw solid boxes in HTML cheaply). Even though I made it a monochrome PNG, it came out to be 120 bytes! I mean, that's kind of steep. 120 bytes. For one pixel. I then converted it to a GIF, which dropped the size down to 43 ...

Generate all the ways to intersperse a list of lists, keeping each list in order.

Given a list of lists like this [[1,2,3],[a,b,c,d],[x,y]] generate all permutations of the flattened list, [1,2,3,a,b,c,d,x,y], such that the elements of each sublist occur in the same order. For example, this one is okay [a,1,b,2,x,y,3,c,d] but this one is not [y,1,2,3,a,b,c,x,d] because y must occur after x, that being how x a...

Code Golf: Phone Number to Words

Guidelines for code-golf on SO We've all seen phone numbers that are put into words: 1-800-BUY-MORE, etc. What is the shortest amount of code you can write that will produce all the possible combinations of words for a 7 digit US phone number. Input will be a seven-digit integer (or string, if that is simpler), and assume that ...

Code Golf: Diamond Pattern

The challenge The shortest code by character count to output a a pattern of diamonds according to the input. The input is composed of 3 positive numbers representing the size of the diamond and the size of the grid. A diamond is made from the ASCII characters / and \ with spaces. A diamond of size 1 is: /\ \/ The size of the grid c...

Code Golf - Banner Generation

When thanking someone, you don't want to just send them an e-mail saying "Thanks!", you want to have something FLASHY: Input: THANKS!! Output: TTT H H AAA N N K K SSS !!! !!! T H H A A NNN K K S !!! !!! T HHH AAA NNN KK SSS !!! !!! T H H A A N N K K S T H H A A N N K K SSS !!! !!! Write a program to genera...

Other ternary operators besides ternary conditional (?:)

The "ternary operator" expression is now almost equivalent to the ternary conditional operator: condition ? trueExpression : falseExpression; However, "ternary operator" only means that it takes three arguments. I'm just curious, are there any languages with any other built-in ternary operators besides conditional operator and which o...

Code Golf: Zigzag pattern scanning

The Challenge The shortest code by character count that takes a single input integer N (N >= 3) and returns an array of indices that when iterated would traverse an NxN matrix according to the JPEG "zigzag" scan pattern. The following is an example traversal over an 8x8 matrixsrc: Examples (The middle matrix is not part of the input...

Code Golf: Rotating Maze

Code Golf: Rotating Maze Make a program that takes in a file consisting of a maze. The maze has walls given by '#'. The maze must include a single ball, given by a 'o' and any number of holes given by a '@'. The maze file can either be entered via command line or read in as a line through standard input. Please specify which in your s...

What are some pieces of code that exemplify the power/functionality/style of their language of implementation?

I don't mean to say that any turing-complete programming language can be less powerful than another in terms of computation, but using "terseness" instead would not fufill the entire meaning of my question. Power in my mind is a combination of terseness and clarity. ...

IP addresses range

Given an IP address and mask like 192.168.10.30/24 on STDIN, return the matching range of addresses. i.e. input : 192.168.10.30/24 output: 192.168.10.0-192.168.10.255 input : 127.0.0.0/31 output: 127.0.0.0-127.0.0.1 libraries/packages/... are NOT allowed ...

Code golf: Word frequency chart

The challenge: Build an ASCII chart of the most commonly used words in a given text. The rules: Only accept a-z and A-Z (alphabetic characters) as part of a word. Ignore casing (She == she for our purpose). Ignore the following words (quite arbitary, I know): the, and, of, to, a, i, it, in, or, is Clarification: considering don't: ...

Code golf: "Color highlighting" of repeated text

(Thanks to greg0ire below for helping with key concepts) The challenge: Build a program that finds all substrings and "tags" them with color attributes (effectively highlighting them in XML). The rules: This should only be done for substrings of length 2 or more. Substrings are just strings of consecutive characters, which may inc...

Code Golf: 2D Platformer

The Challenge Reach the end of the level! Bonus points if you hit each of the (C)oin blocks exactly 2 times. Disallowed Hard coding the command sequence in any way. Your favorite "One character language" that happens to do exactly one thing, which is solving this golf. How To Your program receives the level below(without lin...

Code Golf: Pig Latin

Challenge: Take a sentence of input of any length and convert all the words in that sentence to pig latin. If you do not know what pig latin is please read Wikipedia: Pig Latin. Specifications: Assume all words are separated by spaces and all sentences either end with a exclamation, question mark or period. Do not use the variant for...

Code Golf: Four is magic

The puzzle A little puzzle I heard while I was in high school went something like this... The questioner would ask me to give him a number; On hearing the number, the questioner would do some sort of transformation on it repeatedly (for example, he might say ten is three) until eventually arriving at the number 4 (at which point he wo...

Find the next number in a sequence

This has been a programming problem which has interested me for a while. You give the program a squence of numbers seperated by commas. It then finds a suitable formula from these numbers to find the next number in the sequence. In: 1,2,3,4,5 Out: 6 In: 2,4,6,8 Out: 10 In: 10,8,6,4 Out: 2 I'm not sure if this problem is much more c...

Code golf: Digital clock

Possible Duplicate: Code Golf: Seven Segments The task: Write the smallest possible program (least number of characters) that takes input in the hh:mm format and outputs this as a digital clock (seven-segment display). Sample input: 19:27 Sample output: _ _ _ | |_| . _| | | _| . |_ | Sample input: 11:...

Code Golf: The Unisex Restroom Simulation

Background The unisex restroom problem is a classical synchronization problem in computer science. The general class of problems that this simulates is as follows: If you have k types of threads that need to execute tasks using n shared resources, and at any time only one thread type may be using the resources, then it's a generalizati...