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

2
votes
2answers
113 views

Ordering an array of negatives, zero and positives integers with one iteration

Take an array of integers containing negative numbers, positive numbers and zeros. Group it with one iteration and in place such that all of the negative numbers come first, followed by all of the ...
4
votes
0answers
69 views

Logical Dot Shapes

The Game Recently, much of my time has been taken up by an addicting game on my phone, called Logic Dots, which inspired me to write this challenge. It's easier to explain the rules if I show you the ...
7
votes
5answers
1k views

Magnetic Sculptures… in Space!

Background This is a continuation of my earlier challenge, where the task was to compute the shape of a sculpture obtained by dropping magnets into a huge pile. Good news: the eccentric artist liked ...
0
votes
0answers
159 views

Rise and Shine! [duplicate]

Challenge The challenge is to create a program which takes a date, a latitude, and a longitude, and prints the time of the sunrise on that date for the given location. The program must work for any ...
9
votes
8answers
336 views

Binary encryption

This is based on xkcd #153. Make a program or named function which takes 2 parameters, each of which is a string or a list or array of bytes or characters. The second parameter will only contain ...
0
votes
1answer
59 views

Automated Bulls and Cows Player [duplicate]

This is a code golf challenge to see the shortest implementation of an automated guesser in the pen and paper game bulls and cows. The game works as follows: A (usually 4 digit) secret code with ...
13
votes
2answers
180 views

Maximally extend integer intervals

Suppose you are given a set of non-intersecting intervals of integers [a1,b1],[a2,b2],[a3,b3],...,[aN,bN]. (Where [a,b] is the set of integers greater than or equal to a and less than or equal to b.) ...
21
votes
16answers
2k views

Shortest Unique Substrings

Input An alphanumeric string s. Output The shortest string that occurs exactly once as a (contiguous) substring in s. Overlapping occurrences are counted as distinct. If there are several ...
-5
votes
5answers
95 views

Shortest code special string sort

Objective/Restrictions: May only be answered with programming language that has function syntax (or procedure, method, lambda, macro, statement grouping and labelling) . Create a function with at ...
4
votes
3answers
294 views

Code Golf: Gibberish Echo

This is my first code golf challenge, as such I am not entirely certain if it is suitable as a Code Golf challenge, but it's all a learning experience. The challenge is that in as few characters as ...
4
votes
0answers
74 views

Resistent counter [duplicate]

You just have to ouput exactly all the numbers from 1 to 10 separated by spaces. Your programme should work all the times even if a random character is deleted before compiling/interpreting. This is ...
0
votes
0answers
46 views

Date Parameter Calculation (full year + individual months) [on hold]

Shortest way to calculate start/end dates for the past year and for each of the past 12 months individually. There will be a start/end for each of the 12 months and a start/end for the full year ...
3
votes
0answers
168 views

Chess Light Solver

Challenge Write a solver for the Chess Light puzzle game, in the smallest amount of code. The input will be a representation of a chessboard, how in yours is up to you. My examples below is textual, ...
10
votes
5answers
688 views

How many ways to write N as a product of M integers?

Given an integer N, count how many ways it can be expressed as a product of M integers > 1. Input is simply N and M, and output is the total count of distinct integer groups. Meaning you can use an ...
10
votes
22answers
2k views

Generate the Stöhr sequence

I am learning Ruby and wrote my first nontrivial code to solve this problem. The challenge is to generate the first n elements of the Stöhr sequence, S, which is defined as follows: S[0] = 1 ...
5
votes
4answers
315 views

Write a binary counter in quine

Write two code fragments, which we will call s_zero and s_one. Program (l, n) consists of l copies of s_zero and s_one corresponding with the digits of n in binary, padded with s_zero on the left. ...
10
votes
2answers
387 views

Trucks in a parking lot

There are P parking spaces in a parking lot, though some spaces are occupied by cars represented by octothorpes # while the free spaces are dots .. Soon there arrive T trucks, each of which will take ...
5
votes
2answers
399 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 ...
13
votes
13answers
2k 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 ...
14
votes
3answers
643 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
50 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
141 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 ...
6
votes
2answers
130 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 ...
14
votes
17answers
2k 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
465 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
100 views

Make a caeser cipher [closed]

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 ...
26
votes
3answers
814 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
364 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
114 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
353 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
203 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
594 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
442 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 ...
9
votes
7answers
665 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
74 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
225 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
322 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
175 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
129 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
833 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 | ...