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
0answers
53 views

Double-slit Quine

Objective: Code two programs where each of the programs outputs both source codes interlaced per character like a zipper, a Double-slit Quine. The output from a Double-slit Quine is starting ...
7
votes
6answers
294 views

Character counts in source code

Write a program that outputs a list of the number of occurrences of each unique character in its source code. For example, this hypothetical program {Source_Print_1}; should produce this output: ; 1 ...
13
votes
3answers
301 views

Determine the Dimensions of a Rotated Rectangle

This Stack Snippet draws an aliased white rectangle on a black background given parameters for its dimensions, position, angle, and the grid dimensions: <style>html ...
0
votes
1answer
74 views

Code Golf that outputs Code Golf [duplicate]

This might be a bit weird, and maybe way easier than I thought, or, on the other hand, next to impossible. The challenge is this: Create a code (either a program or a function) that it's output is ...
13
votes
7answers
2k views

Where should I put my restaurant?

You are the owner of a restaurant. You are opening in a new area in Cartesia where there is only one main road, known as the y-axis. You want to place your restaurant such that you minimize the total ...
8
votes
0answers
82 views

Matchstick Equations

Your task in this challenge is to analyize a given "Matchstick Equation" like this one... ... and to find out whether it can be turned into a valid equation by rearranging the matches. If so, you ...
18
votes
9answers
711 views

Calculating Collatz Cousins

Define the function f(n) for a positive integer n as follows: n / 2, if n is even 3 * n + 1, if n is odd If you repeatedly apply this function to any n greater than 0, the result always seems to ...
23
votes
6answers
2k views

Write A Program That Outputs Its Mirror Level

There are 95 printable ASCII characters: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ In the Consolas font (the Stack Exchange code ...
6
votes
6answers
458 views

Recursive Prime Factorization

Your job is to take the prime factors of a number taken from input (omitting any exponents equal to 1) then take the prime factors of all of the exponents, and so on, until no composite numbers ...
5
votes
0answers
173 views

Settlers of Catan - Longest Road!

This is an endgame board of Settlers of Catan: Background: The roads (the long stick pieces) and the settlements (and cities) are rendered by the little huts. We encode the placement of these ...
14
votes
2answers
217 views

Fix the Braces, etc

Your mission, should you choose to accept it, is to add the minimum number of parentheses, braces, and brackets to make a given string (containing only parentheses, braces, and brackets) have correct ...
17
votes
12answers
841 views

Expand an encoded string

There's the classic run length encoding and decoding. input output a3b2c5 aaabbccccc And that's fairly straight forward and done before. The challenge is to also account for a non-standard ...
12
votes
3answers
650 views

Is there a shorter way to get user input in python?

This is not a challenge. I'm wondering if it's at all possible to get user input into two separate variables in python (2 or 3) with less than 19 bytes. These are all the shortest I can get: ...
36
votes
10answers
2k views

Fissile Numbers

I found this sequence while working on Evolution of OEIS, but never got around to posting it as an answer. After writing a reference implementation in Mathematica, I thought this is a fun exercise to ...
11
votes
1answer
178 views

Save the Geese from Extinction

The species of geese known as Alex A are known for residing in triangular grids consisting of 64 cells: (Picture taken from this unrelated Project Euler problem.) We'll label each cell with the ...
5
votes
2answers
218 views

Generalized integer casting in Python

Background I have a string in Python which I want to convert to an integer. Normally, I would just use int: >>> int("123") 123 Unfortunately, this method is not very robust, as it only ...
12
votes
4answers
350 views

Packing Wood Pieces

There are two pieces of wood. Both consist of a straight body and some extra blocks below the body. An example piece with extra blocks at (0-indexed) positions 0,4,7,9,10: XXXXXXXXXXX X X X XX ...
12
votes
5answers
314 views

Permutations of the Fifteen Puzzle

The Challenge Consider the following diagram of the Fifteen Puzzle in its solved state: _____________________ | | | | | | 1 | 2 | 3 | 4 | |____|____|____|____| | | | | | ...
10
votes
1answer
354 views

XKCD Bracket Probabilities

Today's XKCD is a sports-tournament style bracket, where the contestants are well-known names, put into groups of possibly confusing names. Give the probability that a given contestant will win the ...
19
votes
23answers
2k views

Counting leap years

This challenge is quite simple. You will take an input which will be a year from 1801 to 2400, and output if it is a leap year or not. Your input will have no newlines or trailing spaces: 1954 You ...
9
votes
3answers
366 views

Sourcecode selfie

Objective: A guru once said a perfect code selfie is best shot diagonally from upper left corner. A code selfie is almost like a Quine - but rotated 45 degree clockwise. Your mission is to code a ...
16
votes
0answers
165 views

Let's build a race car track!

Introduction My niece wants to make a race car track. She has wooden parts that fit together to form the track. Each part is square shaped and contains a different shape. I'll use the pipe drawing ...
3
votes
1answer
153 views

Minimum of a Polynomial in Python

What is the shortest amount of code that can find the minimum of an inputted polynomial? I realize that you can import packages like Numpy and others, but using only user defined functions, what is ...
27
votes
5answers
929 views

Compute the Resistance of a 4 Band Color Coded Resistor

Resistors commonly have color coded bands that are used to identify their resistance in Ohms. In this challenge we'll only consider the normal 4-band, tan, axial-lead resistors. We'll express them as: ...
13
votes
9answers
835 views

Split as number, join as string, repeat

Consider the process of: Taking a non-negative integer N. e.g. 27. Spliting it into integers N - floor(N/2) and floor(N/2) (a 'bigger' and 'smaller' half) and writing them in that order. e.g.27 ...
4
votes
0answers
152 views

Stone Maze Chess solver [on hold]

Background: Every war eventually comes to an end, but the end is never absolute. The Stone Maze Chess scenario takes place after a game of chess is finished. The enemy King is dead and the pieces is ...
25
votes
7answers
1k views

Multiplication by Self-Modification

...at least for some definition of "self-modification". The Task In this challenge, your task is to write three strings A, B and C that satisfy the following properties. The string B has length at ...
31
votes
14answers
2k views

Temperature Converter

This is a byte sized challenge where you have to convert an input temperature in one of the three units (Celsius, Kelvin and Fahrenheit) to the other two. Input You would be provided with a ...
7
votes
3answers
207 views

Number of ways to sum [1..n] with [n+1..2n] such that each sum is prime

Let n > 0. Let X = [1..n] and Y = [n+1 .. 2n]. Define a(n) as the number of permutations p of Y such that every element of X + p(Y) is prime. For example: n = 2 X = [1,2] Y = [3,4] p0(Y) = [3,4] ...
13
votes
7answers
1k views

What is the Probability that a Knight Stays on Chessboard?

Given the size of the chess board and initial position of the knight, calculate the probability that after k moves the knight will be inside the chess board. Note: The knight makes its all 8 ...
33
votes
8answers
2k views

Clarence the Slow Typist

Introduction Clarence is a data entry clerk who works at an internet service provider. His job is to manually enter the IP addresses of all of the ISP's customers into the database. He does this ...
6
votes
3answers
220 views

Write a self replicating program that stops replicating after “printing” “Hello world!” with the filenames

Write a self replicating program, in the source code filename H.*, contianed in an empty folder then manually compile and run or just run the program if your chosen language is dynamic, and it should ...
5
votes
9answers
547 views

Take first letter of each word, leave spaces and punctuation

Shrink each word in a string of group of strings to single letters delineated by spaces or punctuation. Example I'm a little teapot, short and stout. Here is my handle, here is my spout. When I get ...
13
votes
5answers
749 views

It's election time!

It's time... to count the votes! Today there are local elections in my entire country. Here, the number of seats for each party is decided using the D'Hondt method. Your goal is to implement a ...
17
votes
2answers
300 views

Finding the Deadlock

Finding the Deadlock When programming a multithreading application one must take good care to avoid deadlocking the various threads when accessing shared resources. A deadlock occurs when a thread ...
2
votes
1answer
79 views

Gode-Colf: Wipping Flords around [duplicate]

Here is another short string related code-golf. You must write a full program that reads a string (from STDIN or as command line arguments, as long as you specify which) and wips the flords around ...
0
votes
0answers
61 views

Shortest program to write to a file and open it with the browser [closed]

Create program to write to a new file and open it with a web browser. The file must have a text box and perform addition, subtraction, multiplication, parentheses and exponentiation. Must follow order ...
6
votes
2answers
157 views

Tips for golfing in K

K is a programming language in the APL family designed by Arthur Whitney. While the official interpreter is closed-source and commercial, a trial version with a workspace limit of 32 bits of ...
15
votes
5answers
505 views

ASCII Art of the Day #3 - Chinese Shrines

In today's episode of AAOD, we are going to construct a Chinese Shrine of varying heights. Consider the following examples for height (N) 1 to 6 N = 1: . | . ]#[ . \_______/ ...
18
votes
9answers
1k views

Sum in each dimension

You are given a multi-dimensional array of integers. Each dimension has a fixed size (so that it would be always rectangular if it is 2D). Your program should calculate the sums in each dimension and ...
-4
votes
5answers
175 views

Return every N-th word of a string

Your goal is to write a program that, given a number N and a string as input, will return a string containing every Nth word of the original string, starting from the first word. Sample ...
12
votes
1answer
176 views

Find the Fenceposts

Background An atomic bomb has exploded near the fencepost factory! Since fenceposts are essential for the survival of our civilization, we must rescue as many as possible. We are sending ...
17
votes
8answers
629 views

Formatting a Lisp-like Syntax

Background (Based on a true, heart-wrenching story) In my time, I've played around with Lisp and similar languages often. I've written with them, ran them, interpreted them, designed them, and made ...
15
votes
5answers
377 views

Scale up a Diamond Tiling

Any regular hexagon can be tiled with diamonds, for instance like so: ______ /_/_/\_\ /_/\_\/\_\ /\_\/_/\/_/\ \/_/\_\/_/\/ \_\/_/\_\/ \_\_\/_/ We'll consider the above a tiling of size 1 ...
9
votes
23answers
1k views

Count the number of vowels in each word of a string

This is a rather easy challenge. Challenge Input will contain a string (not null or empty) of maximum length 100. Output the number of vowels in each word of the string, seperated by spaces. Rules ...
22
votes
22answers
2k views

Caesar equivalence

Two strings are "Caesar equivalent" if the distance (counting up) between the corresponding characters are the same. Yes, I made this term up. Here's an example: "Abc" and "Cde" are equivalent ...
29
votes
8answers
3k views

ASCII Art of the Day #2 - Flow Snakes

I came across this really nice snow-flake like ASCII fractal by Michael Naylor [citation needed but not found]. Just like a fractal, it grows exponentially in size with each order/iteration. Below are ...
6
votes
16answers
1k views

Stripping off extra spaces from a string

You are given a string. Output the string with one space per words. Challenge Input will be a string (not null or empty), surrounded with quotes(") sent via the stdin. Remove leading and trailing ...
34
votes
11answers
3k views

ASCII Art of the Day #1 - Double Knot

Write a full program or a function that takes a positive integer N as input via STDIN/command line/ARGV or function arguments and prints an ASCII double knot corresponding to the N to STDOUT. The ...
42
votes
22answers
3k views

Check if words are isomorphs

Two words are isomorphs if they have the same pattern of letter repetitions. For example, both ESTATE and DUELED have pattern abcdca ESTATE DUELED abcdca because letters 1 and 6 are the same, ...