Questions tagged [code-golf]

Code-golf is a competition to solve a particular problem in the fewest bytes of source code. If you want to score by characters instead of bytes, please state this explicitly in the challenge. If source code length is not the primary scoring criterion, consider using another tag instead.

17
votes
3answers
917 views

Write a third order quine

This challenge is an extension of 'Golf a mutual quine'. Using three languages of your choice, create a third order Ouroboros program. That is, in language A, write a program pA which outputs ...
8
votes
2answers
215 views

BWInf 2011, question 5: Twin towns

This is a challenge that was originally a tas for the German Bundeswettbewerb Informatik (federal competition of computer science [?]), a competition for highschool students. As opposed to the ...
26
votes
74answers
12k views

Print a Christmas Tree

The Challenge Print a nice Christmas tree with it's own star at the top using the shortest code possible. The tree star is an asterisk (*) and the tree body is ...
32
votes
36answers
4k views

Is it Christmas?

Challenge Given that Christmas is: December Month 12 Day 25 Every year, determine today's date, and whether or not today is Christmas. If it is Christmas, you must print ...
21
votes
11answers
2k views

Interpret your lang, but not yourself?

There are many challenges that say "interpret X", where X is a simple language. In my opinion, that is way too boring. To give all the procrastinating people on the internet something interesting to ...
8
votes
22answers
1k views

Display Peter's keyboard pattern

Assume an simple keyboard with this layout: 1 2 3 4 5 6 7 8 9 0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z . , ? ! Peter's keyboard pattern can be ...
10
votes
7answers
2k 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 ...
55
votes
17answers
4k views

Tips for golfing in R

I'm looking for tips for golfing in the R statistical language. R is perhaps an unconventional choice for Golf. However, it does certain things very compactly (sequences, randomness, vectors, and ...
3
votes
7answers
697 views

Resolve quadratic equation

Challenge: Write the smallest program (in characters) that resolves quadratic equations i.e. ax² + bx + c = 0 Rules: Given 3 numbers in R comma-delimited on ...
2
votes
2answers
886 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, ...
18
votes
1answer
2k views

Write a code golf problem in which Java wins [closed]

Write a code golf task such that The only input (if any) required by the task is text from standard input, and the only output required by the task is text to standard output. There is exactly one ...
12
votes
3answers
874 views

Implement a Graphing Calculator

There have been many questions involving calculators; however, it does not appear that any involve implementing a graphing calculator. The Challenge You are to write a complete program that takes ...
39
votes
13answers
4k views

Advanced Code Golf - Write a small HTTP server

Your challenge is to write a code-golf HTTP server that accepts GET requests. It obviously doesn't have to be fully featured, but it must serve files from a directory. Rules: The HTTP server must ...
4
votes
1answer
410 views

PCM Wave time stretch

Write the smallest program performs a time stretch operation on a PCM Wave (.wav) file. Rules: Parameter input will by via whatever standard argument mechanism your language comes with, e.g. ...
20
votes
23answers
3k views

Generate excel column name from index

This one comes from a real life problem. We solved it, of course, but it keeps feeling like it could have be done better, that it's too lengthy and roundabout solution. However none of my colleagues ...
-2
votes
1answer
610 views

Try to understand this java code [closed]

The students in my high school computer science class were asked to write the game of nim for a simple project. Most of them found it very easy and finished quickly. However, one student came up with ...
6
votes
2answers
342 views

Unfolding an integer

Given the functions L: (x, y) => (2x - y, y) R: (x, y) => (x, 2y - x) and a number N generate a minimal sequence of ...
5
votes
20answers
2k views

Selective character count (only non-alphanumeric)?

Challenge (Easy) Write a function which takes an argument and returns the number of non-alphanumeric characters found. Challenge (Hard) Write a function which takes an argument and returns the ...
30
votes
3answers
1k views

Build railroad tracks and cheat the government

You are a railroad entrepreneur in the 19th-century United States when trains become popular because they are the most efficient means of transporting large volumes of materials by land. There is a ...
14
votes
9answers
2k 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 ...
2
votes
2answers
858 views

Fastest C/C++ comparison function for an opaque field containing doubles

Description: Write the fastest comparison function for an opaque field containing a double. Here is my example: ...
25
votes
12answers
2k views

Tips for golfing in Scala

What general tips do you have for golfing in Scala? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Scala (e.g. "remove comments" is ...
8
votes
13answers
2k views

Playing the Name Game

Write a program to play the name game. Input Your program should accept a single name as input from the user in some way (e.g read from standard input or as a command-line argument). You can assume ...
8
votes
12answers
981 views

Write a function to decrypt Feynman Challenge Cipher #1

The Feynman Challenge Cipher #1 is as follows: ...
5
votes
3answers
2k views

Create a function for transposing musical chords

Your mission is to create a function for transposing music chords. Copied from SO with permission of the original asker, I just really wanted to see what you guys could do with this one: Since I don'...
5
votes
4answers
444 views

Maclaurin series of Black Box Function

Given a Black Box function ff that takes a single floating-point parameter, write a function M to generate the Maclaurin series ...
32
votes
45answers
6k views

Generate Pascal's triangle

Pascal's triangle is generated by starting with a 1 on the first row. On subsequent rows, the number is determined by the sum of the two numbers directly above it to the left and right. To ...
12
votes
1answer
1k views

Simulate a (gravity-based) billiard-ball-type computer

The Machine A billiard-ball type machine is composed of only the symbols \ _ / along with ...
-4
votes
9answers
331 views

Change a non-floating point number the largest step [closed]

Declare a numeric variable that is not floating point and do an operation that changes the value with the largest amount of difference so the result of the variable is far from the original value. ...
5
votes
14answers
8k views

Implement wc (word count) shortest code wins [duplicate]

Write a stripped down version of the wc command. The program can simply open a file which does not need to be configurable or read from stdin until it encounters the end of file. When the program is ...
13
votes
2answers
1k views

Illuminate a Mirrored Room

Goal In this competition, you are given a random room with one candle inside. The goal is to write the shortest program (this is golf) that determines what parts of the room are illuminated by the ...
14
votes
6answers
3k views

Implement Rijndael's S-box

Rijndael's S-box is a frequently used operation in AES encryption and decryption. It is typically implemented as a 256-byte lookup table. That's fast, but means you need to enumerate a 256-byte ...
5
votes
16answers
2k views

Hexadecimal To Decimal [closed]

Read input of up to 8 characters presented as hexadecimal number and print this number as decimal number. In case that input can not be presented as hexadecimal input it has to print 0 Rules: It is ...
3
votes
4answers
2k views

Solve the knapsack problem

Knapsack Problem (Actually, this is a subset of real knapsack problem.... - there's nothing to optimize!) The knapsack problem is: Given positive integers , and an integer S, find non-negative ...
4
votes
1answer
1k views

Determining the winner of a Chess game

Challenge Being someone who plays far too much chess in his spare time, I thought I'd set a code golf challenge inspired by the game of chess (with a software flavour), for those interested. The ...
11
votes
2answers
953 views

Blockbox that Hex?

Write a program or a function in any programming language that takes a 6 digit hexadecimal input/argument. The input/argument can be 6 values or a 6 character string. Your program should output an ...
22
votes
23answers
3k views

There Was an Old Lady

Your goal is to write a program that prints the following poem exactly as it appears here: ...
6
votes
3answers
339 views

Shana tova umetuka! (Happy Jewish New Year!)

Write the shortest program, in the language of your choice, that takes as input a year on the Hebrew calendar, and outputs the corresponding Gregorian date for Rosh Hashana, in YYYY-MM-DD format. <...
9
votes
1answer
881 views

Optimize matrix chain multiplication

This challenge is to compute the most efficient multiplication order for a product of several matrices. The size of the matrices is specified on a single line of standard input. You should print to ...
11
votes
8answers
1k views

codegolf.com: Saving Time

From codegolf.com (not loading as of Sept 15, 2011) was one that was driving me crazy. Print to STDOUT a clock of an exacting form, reading time from STDIN and marking an ...
5
votes
3answers
400 views

Organize a tournament

Here is a real question somebody asked me. Suppose you have n teams, one terrain. Each team must play each other team exactly once. The number of times a team ...
5
votes
1answer
530 views

Set the chessboard

Objective Given an arbitrary chessboard as standard input (in which each piece is on a square), produce as standard output a list of moves needed to regularize, or set up, the chessboard. The moves ...
11
votes
8answers
2k views

Flag Semaphore Encoder

Your goal is to write a flag semaphore encoder, which will convert a given sentence into the corresponding flag semaphore characters, according to the semaphore system described on Wikipedia. Assume ...
20
votes
10answers
2k views

Exploit “free whitespace”

Suppose a codegolf challenge doesn't count whitespace in the length of your program. Cheat this system by encoding your script into whitespace, and golf a script which decodes and executes embedded ...
15
votes
31answers
6k views

Jolly Jumper Sequence

A sequence of n > 0 integers is called a jolly jumper if the absolute values of the difference between successive elements take on all the values 1 through n-1. So the sequence [4,1,2,4] has absolute ...
6
votes
1answer
553 views

Optimal Othello/Reversi Move

This is a code-golf challenge: Given a specific board in the game of Othello (Reversi), find a move for Black that will capture the maximum number of White pieces. (Obviously, this may not be the ...
13
votes
4answers
641 views

A Mere Bagatelle

The challenge Given a bagatelle board like the one below: ...
19
votes
1answer
977 views

Unique Sudoku Finder

Challenge: Given a Sudoku board on standard input, find the minimum number of numbers added to make the board unique. Specifics/Rules: The input is formatted as follows (all whitespace is ...
11
votes
39answers
3k views

Enumerate all palindromic numbers (in decimal) between 0 and n

Given a non-negative integer n, enumerate all palindromic numbers (in decimal) between 0 and n (inclusive range). A palindromic number remains the same when its digits are reversed. The first ...
10
votes
4answers
992 views

Knock down walls in a maze

Rules: In this game you start at the top of a rectangular grid of size N x M made up of walls and open spaces. The input is N lines of M characters, where a . ...