code-golf

Code Golf: Musical Notes

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...

Code Golf: Reversi

OK, here's a rather elaborate code golf challenge: Implement a game of Reversi (Othello). The game should display the current state of the game-board and allow players at a single computer to alternately input moves. Incorrect input and disallowed moves must be caught, but can be ignored silently. The game must end when no more moves c...

Is there a language designed for code golf?

I am not really a fan of code golf, but I have to wonder, is there an esoteric language designed for it? I mean a language with following properties: Common programs may be expressed in very short amount of characters It uses ASCII character set effectively (for example, common operators are not identifiers, so they don't have to be ...

Code Golf: Playing Cubes

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...

CodeGolf: Brothers

Hi guys, I just finished participating in the 2009 ACM ICPC Programming Conest in the Latinamerican Finals. These questions were for Brazil, Bolivia, Chile, etc. My team and I could only finish two questions out of the eleven (not bad I think for the first try). Here's one we could finish. I'm curious to seeing any variations to the co...

Code Challenge: 2D Array Search

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 ...

Code Golf: Spider webs

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...

Does codegolf make a better programmer - or is it even useful?

I have kept an eye on quite a few of the code golf questions on stack overflow, now i am a programmer constantly learning and developing (As i think is natural) but it bugs me to create code in as few code strokes as possible, is it really useful? it's almost un-readable and un-manageable, other than maybe the challenge or "fun" is code ...

Code Golf: Hourglass

The challenge The shortest code by character count to output an hourglass according to user input. Input is composed of two numbers: First number is a greater than 1 integer that represents the height of the bulbs, second number is a percentage (0 - 100) of the hourglass' capacity. The hourglass' height is made by adding more lines to...

How to convert numbers to words in Erlang?

I found this interesting question about converting numbers into "words": http://stackoverflow.com/questions/309884/code-golf-number-to-words I would really like to see how you would implement this efficiently in Erlang. ...

Insertion Sort Code Challenge

My task for you this time is to implement an insertion sort algorithm. Sure, everyone and his dog can do it; but how easy is it to do in the fewest characters? One must take an array (or suitable alternative in your language) of 32-bit integers and sort them by value via the insertion sort method, then return the sorted array as a copy ...

Code Golf: Sierpinski's Triangle

The challenge The shortest code, by character count to output an ASCII representation of Sierpinski's Triangle of N iterations made from the following ASCII triangle: /\ /__\ Input is a single positive number. Test cases Input: 2 Output: /\ /__\ /\ /\ /__\/__\ Input: 3 Output: /\ ...

Running a fastest-algorithm competition

I'd like to run competitions like code golf competitions, but the winner would have the fastest algorithm, not the smallest code. One fair way to measure speed of an algorithm is to use a neutral virtual machine, like Java's JVM. Is there an easy way to know the total number of JVM instructions executed? (If the entry uses multiple t...

oneliner scramble program

It's that time of year again that programmers want to shuffle a list such that no element resides on its original position (at least in the Netherlands, we celebrate Sinterklaas and pick straws for deciding who writes who a poem). Does anyone have a nice Python single statement for that? So, input example: range(10) Output example: [2,...

Code Golf: Permutations

input: array of unique integers, sorted output: all permutations. edit: output order is not important, as long as it's correct :-) example: [2, 6, 9] output: [ [2, 6, 9], [2, 9, 6], [6, 2, 9], [6, 9, 2], [9, 2, 6], [9, 6, 2] ] ...

Code Golf: Fractran

The Challenge Write a program that acts as a Fractran interpreter. The shortest interpreter by character count, in any language, is the winner. Your program must take two inputs: The fractran program to be executed, and the input integer n. The program may be in any form that is convenient for your program - for example, a list of 2-tup...

Code Golf: Running Water

The challenge The shortest code by character count to identify and mark water depressions in the ASCII representation of a land from input. Input will be an ASCII representation of a landscape, having hills, valleys and flat lands. The program should simulate what the landscape would look like if if was flooded - filling all valleys wi...

Code Golf: Perfect Tic-Tac-Toe

Given a tic-tac-toe board as input, where the game may already be started: | | -+-+- |X| -+-+- | | Output a tic-tac-toe board with the best possible move for the player whose next turn it is. You can assume a well-formed board (you won't have just 3 Os): | |O -+-+- |X| -+-+- | | The only acceptable moves here are corners, si...

Code-Golf: What is the shortest program that compiles and crashes?

This is a little bit of fun. Can you devise the shortest program which compiles but does nothing but immediately crash when executed? Wherefore by "crash" we mean that the program stops with an error condition (a core dump for example). Is there a language that crashes faster (7 chars) than C using a gcc compiler? [I leave this answer f...

Turing Machine Code Golf

Ok guys, today's goal is to build a Turing machine simulator. For those that don't know what it is, see the Wikipedia article. The state table we are using today is found at the end of the Formal Definition that's part of that page. The code will take a sequence of "0" and "1" string characters, an integer representing the character tha...