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, state this explicitly in the challenge. If source code length is not the primary scoring criterion, consider using another tag instead.

learn more… | top users | synonyms

4
votes
2answers
184 views

Solve a 2x2 Eigensystem

For those with a little linear algebra background, the challenge is as simple as this: determine the eigenvalues and eigenvectors of a given complex 2x2 matrix. You may skip ahead to The Challenge for ...
7
votes
10answers
410 views

Print out the first N characters of your code

You should write a program or function that receives a positive integer N as input and prints out the first N characters of your code. If N is larger than the length of your code you should continue ...
13
votes
3answers
420 views

Words within words within words within words . . .

In this pixelated font of uppercase letters of the alphabet, all the characters are 5 units wide and 5 tall. ███ ████ ███ ████ █████ █████ ████ █ █ █████ █ █ █ █ █ █ █ █ █ █ ...
0
votes
1answer
41 views

Implement range function without using numbers in code [duplicate]

You have to create a function range, such that it takes two (integer) arguments a and b (a < b) and returns all the numbers in between them. So: range(5, 10) // should output 6, 7, 8, 9 range(-5, ...
6
votes
1answer
115 views

Confused badminton players

Introduction Jim and Bob are playing badminton doubles against two other players, but mid-game they face a dilemma: After a fast-paced rally they have no idea who has to serve next and where they ...
5
votes
2answers
106 views

Remove a weight so the rest can't be balanced

This code-golf challenge is based on the following puzzle: You have an odd number of tokens whose weights are known whole numbers, and they don't all have the same weight. Show that there's a ...
11
votes
22answers
1k views

String to Binary

This is a code golf challenge. Just like the title says, write a program to covert a string of ascii characters into binary. For example: "Hello World!" should turn into 1001000 1100101 1101100 ...
13
votes
16answers
1k views

Find the substring with the most 1's in a sequence

Introduction I want to find the substring with the most 1's in a sequence of 0's and 1's. Input Your program has two inputs, the sequence and the substring length. The sequence is any number of ...
3
votes
3answers
375 views

Generate all 4-perfect numbers

Your program or function should output all the 36 4-perfect numbers in increasing order separated by newlines. An n positive integer is a k-perfect number (multiply perfect number) if the sum of its ...
-5
votes
2answers
95 views

Make a caeser cipher [on hold]

I love my encryption but I need a program that is dedicated to making a caeser cipher. It will take an input string and will output a ciphered text with the number to decode it. The number can be made ...
23
votes
3answers
666 views
+100

Identity sequences on the Rubik's Cube

A move sequence is a sequence of moves (turns) on a Rubik's Cube (for the notation look down below). Beside the empty move sequence, there are many other other move sequences, that have no effect on ...
6
votes
3answers
350 views

The Great, White, North!

Eh! You know, the problem with us Canadians is that sometimes, after a long day of moose hunting and dam repairing, we forget our way back to our cabins! Wouldn't it be great if our handy laptop ...
-1
votes
6answers
111 views

Double Factorial [duplicate]

Challenge The objective is simple, in the shortest amount of bytes, write a function or program that takes a number and prints its double factorial. The input must be taken from stdin or a function ...
2
votes
1answer
346 views

Billy Lost his Pen

tl;dr [True] Billy got a Stack Overflow pen from Tim Post. Billy was stupid enough to use the pen, knowing that he was not worthy. Billy's friend took the pen apart, so Billy put the pen in a drawer ...
20
votes
7answers
1k views

Cover a Region with Rectangles

Input Your input in this challenge is a list of integer pairs. They represent the southwest corners of unit squares on the plane, and the list represents their union as a subset of the plane. For ...
10
votes
4answers
201 views

H Tree Directories

Programmers are often obsessed with drawing fractals. I think we need a new computer based medium. The H tree is a fairly simple type of fractal made of horizontal and vertical lines. Here it is at ...
14
votes
7answers
569 views

Sum the powers to n

Directions Write a program that, given an input integer n (n >= 0), outputs the smallest positive integer m where: n = a[1]^b[1] + a[2]^b[2] + a[3]^b[3] + ... + a[k]^b[k] a and b are finite ...
5
votes
2answers
280 views

Heaps of trouble

Challenge You must, in the least bytes possible, implement the Binary Heap data structure and each of the following methods that operate on it: A function which takes no arguments and returns an ...
36
votes
14answers
5k views

Into how many pieces can you cut this string?

Consider a piece of string (as in "rope", not as in "a bunch of characters"), which is folded back and forth on the real line. We can describe the shape of the string with a list of points it passes ...
14
votes
2answers
441 views

Winning Strategies for a String Construction Game

Background Alice and Bob play a game called construct a binary word. To play the game, you fix a length n >= 0, a set G of length-n binary words called the goal set, and a length-n string t ...
6
votes
0answers
82 views

Find the Straightest Path in a Maze [duplicate]

In this challenge, your job is to find the straightest path from point A to point B in a two-dimensional maze. This is very similar to finding the shortest path, which has been done to death, but ...
11
votes
1answer
316 views

Score a game of Kingdom Builder

I want to try a new form of code golf here. Similar to bonuses, not all parts of the challenge have to be completed, but each answer has to implement a subset of certain size (and there is a core that ...
19
votes
8answers
2k views

Code Golf Image Downloader

In many image-processing challenges, the post contains images, which must be saved to a file in order to be able to work on the problem. This is an especially tedious manual task. We programmers ...
8
votes
7answers
620 views

Golfing at the Bank

Our new bank needs a teller transaction system but there is a problem. There is only a few hundred bytes of space left on our server, so you will have to write very compact code. Database Thankfully ...
-5
votes
1answer
69 views

Sign that file!h [closed]

You are Bob, who is running for mayor. Of course you want to win the election, so you want to eliminate any negative comments about you. On your system there are a whole bunch of text documents that ...
4
votes
1answer
223 views

Print the fingering for the note on a saxophone

Your challenge is, given a series of notes, print the fingerings that minimize the amount of movements you need to make (explained below). My not standard way of transforming fingerings to text: The ...
8
votes
2answers
319 views

Hereditary Base Change

Background In this challenge, a base-b representation of an integer n is an expression of n as a sum of powers of b, where each term occurs at most b-1 times. For example, the base-4 representation ...
-1
votes
1answer
171 views

“Compile” a simple C program inside a different language [closed]

Your task is to take the following simple C code and make a program which will interpret this code and produce a correct output, and be able to handle small modifications to the original code. The C ...
0
votes
0answers
128 views

Books Algorithm Dealing with Square Digit Sums

A little context: Book has 411 Pages Read a random number of pages on the first day which is unknown Number of pages to read next day is the square of the sum of the digits of the page ...
8
votes
5answers
1k views

All primes from 0 to 1000

Is it possible to make this C code smaller? It prints out all primes from 0 to 1000. C, 89 chars int i,p,c;for(i=2;i<1e3;i++){c=0;for(p=2;p<i;p++)if(i%p==0)c++;if(c==0)printf("%u\n",i);}
36
votes
14answers
4k views

Automate Saving the World

You are Desmond Hume. For the last 3 years, you and your partner, Kelvin, have been slave to a computer that requires a very specific sequence to be entered into it every 108 minutes to save the ...
19
votes
10answers
832 views

0-1 Maximal Phase Counter

Consider an array of bits, say 1 1 1 0 0 0 0 1 0 0 1 0 1 1 1 1 1 0 1 0 We call a contiguous subarray of length ≥ 5 a phase if at least 85% of the bits are the same and the first/last bits are both ...
38
votes
12answers
4k views

Determine dice value from side view

Write program or function which will take left and right value of dice as integers (1-6) and return value on top. Dice layout: +---+ | 1 | +---+---+---+---+ | 2 | 3 | 5 | 4 | ...
28
votes
7answers
1k views

Are these dice nontransitive?

Nontransitive dice are nice little toys that defy our intuition in probability theory. We'll need a few definitions for this challenge: Consider two dice A and B which are thrown at the same time. We ...
7
votes
3answers
377 views

Music: What's the name of this chord?

This is the reverse of Music: what's in this chord?, which is to print the notes in a given chord. This time the input is a list of notes in a chord, and your task is to output which chord it is. ...
24
votes
2answers
979 views

Golf me some cash from the ATM

The task is simple. Get me some 1000, 500 and 100 notes. How ? you might ask. Don't worry, no need of robbing a bank as there is an ATM nearby which accepts your credit card. But your credit limit is ...
8
votes
4answers
573 views

That's almost Lisp!

Challenge Your challenge is to design an interpreter for a lisp-like language, which will from hence forth be coined: GLisp. The program code for GLisp will consist of an arbitrary amount of nested ...
14
votes
3answers
612 views

Build a program to analyze coin flip sequence choices

In a puzzle in an old book of mine, a game is defined in which two players choose sequences of coin flips that they believe will appear first when a coin is repeatedly flipped. (It was actually odd ...
18
votes
9answers
3k views

A Skittish Program

Objective You are to write a program that receives an integer n as input (from the command line), and embeds itself (the program) n directories down the directory tree. Example with n=5: The ...
7
votes
4answers
483 views

Curator's Dilemma

Introduction You are a friend of a curator for an art museum, who has had the recent delight of getting modern art from four artists (some of which may give the curator zero pieces of art, young ...
4
votes
2answers
168 views

Compute the Join and Meet of Partitions

Background In this challenge, a partition of a set S means a collection of nonempty subsets of S, which are mutually disjoint and whose union is S. We say that a partition p is finer than another ...
9
votes
1answer
205 views

Code a Code Slidey Puzzle!

The most recognizable sliding puzzle is the fifteen puzzle. It has a 4 by 4 grid, 15 tiles, and one empty grid space. The tiles can only move into the empty space and must always be in line with the ...
8
votes
18answers
1k views

Convert RGB integer value into RGB values

For example, in traditional web hexadecimal, a certain base-16 number represents an RGB value. For example, 45A19C equals (69,161,156) in RGB. You'll be converting from that number to RGB value, ...
14
votes
8answers
862 views

Jump the Array!

Let's play a one-player game called jump the array. To play, you only need an array of integers, say a. You start at some position i, and on each turn, you jump to a new position. On turn n, if n is ...
28
votes
13answers
2k views

Morse the New Year

This is Weekly Challenge #1. Theme: Audio Processing Your task is to write a program, which writes an audio file to disc (in a format of your choice), which contains the Morse code for 2015, i.e. ...
20
votes
14answers
1k views

Recycling for the New Year

A good resolution for 2015 is to live more sustainably. We'll start by recycling. Recycling code, that is! Your task is to print the number 2015 to STDOUT, with or without trailing newline (and only ...
14
votes
2answers
355 views

Eternal 2014 — PCG.SE New Year’s Puzzle 2015

So, now that it's 2015, and a bunch of answers from last year's puzzle are now starting to produce invalid output, it's time for a question involving the number 2015. Except... why? Wouldn't you like ...
7
votes
11answers
525 views

What year is it?

It is December 2014, and 2015 has almost started. However, it appears not everyone has realized this. But the people of PPCG come to the rescue! Input Your program is given a grid like the one ...
8
votes
1answer
349 views

Bad News, Someone

In the Futurama episode The Prisoner of Benda members of the crew swap bodies with each other, with the catch that no pair of bodies can have their minds swapped more than once. Challenge Write a ...
28
votes
18answers
2k views

Unflatten an Array

This challenge was inspired by a question on Mathematica.SE. Say you've got a nested list/array of some arbitrary structure (the lists at each level don't necessarily have the same length). For ...