Questions tagged [code-golf]

Code-golf is a competition to solve a particular problem in the fewest bytes of source code.

Filter by
Sorted by
Tagged with
-2
votes
1answer
665 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 ...
10
votes
3answers
385 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
3k 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
2k 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
3k 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
887 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: ...
26
votes
15answers
3k 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 ...
10
votes
14answers
3k 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
1k views

Write a function to decrypt Feynman Challenge Cipher #1

The Feynman Challenge Cipher #1 is as follows: ...
5
votes
4answers
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
467 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 ...
39
votes
62answers
8k 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
337 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. ...
6
votes
14answers
9k 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 ...
19
votes
9answers
4k 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
5answers
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 ...
5
votes
2answers
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
988 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 ...
26
votes
31answers
4k 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
356 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
942 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
413 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 ...
6
votes
1answer
552 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 ...
12
votes
9answers
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
30answers
7k 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
611 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
684 views

A Mere Bagatelle

The challenge Given a bagatelle board like the one below: ...
19
votes
1answer
1k 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 ...
13
votes
47answers
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 ...
11
votes
4answers
1k 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 . ...
77
votes
6answers
36k views

Hard code golf: Regex for divisibility by 7

Matthias Goergens has a 25,604-character (down from the original 63,993-character) regex to match numbers divisible by 7, but that includes a lot of fluff: redundant parentheses, distribution (...
15
votes
7answers
1k views

What comes next?

Given a space-separated list of integers, your task is to find the next integer in the sequence. Each integer in the sequence is the result of applying a single mathematical operation(...
19
votes
9answers
2k views

Choose Your Own Adventure

Choose Your Own Adventure books are a form of interactive literature where the reader must make decisions that affect the outcome of the story. At certain points in the story, the reader has multiple ...
9
votes
7answers
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 ...
71
votes
38answers
19k views

Shortest Game of Life

Conway's Game of Life is the classic example of cellular automation. The cells form a square grid and each has two states: alive or dead. On each turn, each cell simultaneously updates according to ...
7
votes
3answers
3k views

Lights Out - Find the solution

(This code golf task is related to Code-Golf: Lights Off!. The same puzzle is used, but the task is different.) Introduction "Lights Out" is a puzzle in which you should switch off all ...
10
votes
6answers
2k views

Enumerate all binary trees with n nodes

Given an integer n, enumerate all possible full binary trees with n internal nodes. (Full binary trees have exactly 2 children on every internal node). The tree structure should be output as a pre-...
9
votes
7answers
2k views

Generating BF-code with single purpose

I'd like to see you create code (in any programming language) that output working BF (Brain***k) code. Your program have a single character input on stdin. The input should be one digit ("0", "1", "2",...
4
votes
5answers
3k views

C: Output “tomorrow's date”

I'm a code golf novice, but I'm eager to give it a go. My challenge is: Write the shortest program in C which takes in a date D as input and outputs the date ...
17
votes
4answers
2k views

Wordsearch Solver

Given a list of words and a grid of letters, find all the words in the grid and remove any letters which are not part of any of the words. The words could be forwards, backwards, up, down or diagonal. ...
-4
votes
11answers
454 views

Text Statistics: Return a list/array of the number of occurrences of each character used in a text file, including spaces, tabs, and new lines [closed]

Generic Lorem Ipsum: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris felis dolor, bibendum at tincidunt vel, imperdiet eget libero. Cras vel felis purus. Phasellus a vestibulum ...
12
votes
3answers
424 views

Session-Saving Quine

Inspired by this question. Create a program that prompts the user to store some data, and when the program is quitting, spit out the program itself, except the session data changed. The user then ...
55
votes
71answers
7k 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 ...
4
votes
12answers
852 views

Multiples of 67 in a constructed array of arrays?

A triangle-shaped table is constructed such the first row is "1, 3, 5, 7, ..., 99" Each subsequent row has the following properties: One less element than the row above Each element is the sum of ...
5
votes
4answers
310 views

Generate a JavaDoc comment [closed]

I'm too lazy to write a JavaDoc comment myself, there's a lot of typing and it is mostly boilerplate. Write a program to generate a JavaDoc comment with $ as a ...

1
203 204
205
206 207
211