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

11
votes
8answers
280 views

Generate the set of prepend-append permutations in lexicographically sorted order

Define a prepend-append sequence of length n to be a permutation of the numbers 1, 2, ..., n that can be generated by the following procedure: Start with the number 1. For each number from 2 to n, ...
13
votes
4answers
200 views

Rubik's Cube Scrambles

Your task is to create a random sequence of moves, which can be used to scramble a Rubik's Cube. Such a scramble is made up of exactly 25 moves. Each move consist of of the letters UDRLFB optionally ...
6
votes
3answers
134 views

Identifying Sequences for Cellular Automata

Background For the purposes of this challenge, an n-state cellular automaton is simply a binary function f that takes two numbers from the state set {0, 1, ..., n-1} as inputs, and returns another ...
6
votes
2answers
178 views

ICS Maritime Flag alphabet

The International Code of Signals flag alphabet is used by ships for communication, particularly for static signals. Your challenge is to write a program or function that will take a string from ...
15
votes
7answers
308 views

Evaluate a chain of inequalities

Write code to evaluate whether a chain of inequalities is true or false. An example input is the string 3<=4!=9>3==3 This is true because each of its components is true: (3<=4) and (4!=9) ...
11
votes
16answers
264 views

Bookkeeping for the Sex Bob-ombs (check if a running sum ever gets too low)

Believe it or not, the Sex Bob-ombs have become a world famous band and are currently on world tour! As their bookkeeper you must oversee their day to day finances and provide regular reports. Every ...
8
votes
0answers
119 views

Golf a Particular Region of the Mandelbrot Set

The Wikipedia article on Kolmogrov complexity gives the excellent example that an image of a region of the Mandelbrot set takes millions of bits to represent as a bitmap, but would take far fewer bits ...
11
votes
1answer
218 views

Write a Kolmogorov Complexity Solver

The Kolmogorov complexity of a string S is the length of the shortest program P, written in some programming language L, whose output is exactly S. (Yes, the real definition is more formal but this ...
19
votes
21answers
980 views

Home on the Range of Lists

This challenge is simply to return a list of lists of integers, similar to the Python range function, except that each successive number must be that deep in lists. Rules: Create a program or a ...
31
votes
14answers
3k views

Shotgun Numbers

The Shotgun numbers are a sequence with a rather simple definition but some interesting structure. Start with the natural numbers: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ...
18
votes
4answers
2k views

Pure Sourcery - Shaping programs that output the digits 0 through 9

Here's a pixelated 5 by 7 font for the digits 0 through 9: .███. █...█ █...█ █...█ █...█ █...█ .███. ..█.. ███.. ..█.. ..█.. ..█.. ..█.. █████ .███. █...█ ....█ ...█. ..█.. .█... █████ .███. █...█ ...
5
votes
0answers
194 views

HTML2JSON Converter

Edit I have posted a 250 lines reference implementation for review at CR, discussing the major class of the code. Download the complete Visual Studio 2013, .NET 4.5 source code (10 kB) from my ...
23
votes
17answers
2k views

Construct a Ladder

Introduction I want to build a ladder. For this, I have scavenged from the junkyard two long boards with holes in them, and I want to place the steps into these holes. However, the holes are not ...
12
votes
4answers
405 views

ASCII Ice Cream

Write a program or function that takes in a positive integer N, and prints or returns an N×N ASCII art string whose top half is a semicircle made of ('s and whose bottom half is a downward-pointing ...
3
votes
0answers
129 views

Word search puzzle generation

Given a list of strings, find the smallest square matrix that contains each of the initial strings. The strings may appear horizontally, vertically or diagonally and forwards or backwards like in ...
6
votes
0answers
275 views
+50

Longest common substring

This challenge is about writing code to solve the following problem. Given two strings A and B, your code should output the start and end indices of a substring of A with the following properties. ...
18
votes
20answers
4k views

The Staircase Challenge

Your work is to recreate this piece of art: _____ | | | | _____| ...
7
votes
4answers
329 views

Prelude Syntax-Checker

Prelude is an esoteric programming language, which has very few, but unusual, restrictions on what constitutes a valid program. Any block of printable ASCII text ("block" meaning that lines of ...
19
votes
2answers
268 views

Water held in a hexagonal rod scuplture

I have bunch of hexagonal rods glued together into an odd sculpture. The rods are 1 to 99 centimetres (cm) long and 1 square cm in cross-section area. All rods are glued on a hexagonal face to at ...
12
votes
1answer
108 views

Analyzing Collatz-like sequences

We define a Collatz-like sequence s with 4 positive integers: n starting value d > 1 divisor m > 1 multiplier i increment (In the original Collatz sequence d = 2 m = 3 and i = 1.) Given ...
23
votes
32answers
3k views

Check whether letters of word are in alphabetical order

Write a function/program that accepts a string of lower/uppercase letters [A-Za-z] as input, that checks whether the occuring letters are unique and in alphabetical order (ignoring lower and ...
1
vote
0answers
52 views

Solve a Date Shift Cipher [duplicate]

Introduction In this challenge you will be solving date shift ciphers. Here is a general overview of what a date shift cipher is. To encode a message, you first must make a key. A key in a date shift ...
7
votes
7answers
240 views

Pseudo-cyclic Number Evaluator

For the purposes of this challenge, let's define a cyclic number as an integer that passes the basic part of Midy's Theorem, but not necessarily the extended theorem. This means: the digits in the ...
15
votes
16answers
2k views

From 0 to 2^n - 1 in POPCORN order

... Ah sorry, no popcorn here, just POPCNT. Write the shortest program or function which takes in a number n and output all integers from 0 to 2n - 1, in ascending order of number of 1 bits in the ...
20
votes
2answers
325 views

Golf Down the PPCG Usernames

A comment I made in chat and the ensuing conversation inspired me to make this challenge. Am I the only one referred to by initials around here? We are all about golfing things down. We can have ...
11
votes
6answers
725 views

Solve a Diagonal Burrows-Wheeler transform

Introduction In this challenge you will be solving diagonal Burrows-Wheeler transforms. Here is a general overview of what a diagonal Burrows-Wheeler transform is. To encode a message, you first must ...
4
votes
1answer
139 views

Find a numeric coincidence when representing numbers in various bases

Recently, when doing some code-golf challenge, I came up with with two solutions, in 69 and 105 bytes. It's a remarkable coincidence, because: 69 (decimal) = 105 (octal) 69 (hexadecimal) = 105 ...
11
votes
3answers
316 views

Dollar Divisibility and Perfect Change

I have $15 in my pocket. Likewise, I am in a store which doesn't give change. While browsing, I spot an item that costs $10 (tax included). Can I buy that item without losing any money? In this ...
7
votes
2answers
234 views

Paeth-transform arrays

One of the key parts of PNG's compression algorithm is the Paeth transformation, which transforms the image in a way that makes it compress better (usually). In this challenge, your task is to write a ...
7
votes
5answers
179 views

Almost Lexicographical List Comparison

Input Two lists A and B of nonnegative integers. Output Either 1, 0, or -1, depending on whether A is larger than, equal to, or smaller than B with respect to the twisted lexicographical ordering ...
44
votes
16answers
5k views

Sierpinskified Code

Write a rectangular block of text that when arranged into a Sierpinski carpet, using same-sized blocks of spaces for the empty portions, creates a program that outputs the iteration number of the ...
8
votes
6answers
300 views

List the Cases of Two Finnish Nouns

Introduction In this challenge, your task is to correctly list the cases of two Finnish nouns. The twist is that you may use one of the listings as a guide to produce the other. The Nouns We use ...
7
votes
1answer
1k views

Python 3 - Tried Golfing My Assignment

Note: This isn't as much a golfing challenge; it is more so asking for golfing suggestions. Recently I had a Python assignment for my web development class, in order to check whether we could code. ...
14
votes
16answers
2k views

Different Way Forward

Given a list of integers produce a Forward Difference at a specified order/depth. For the list of integers: (10, 18, -12, 4, 8, -3, -5, 67, 9, 14) The Forward Differences at the various ...
13
votes
11answers
882 views

Random Golf of the Day #3: Integer Partitions

About the Series First off, you may treat this like any other code golf challenge, and answer it without worrying about the series at all. However, there is a leaderboard across all challenges. You ...
19
votes
6answers
1k views

A Mnemonic for Remembering 23940

The major system is a mnemonic device for converting numbers into words so they can be memorized more easily. It is based on how words sound phonetically, but to keep things simple for the challenge ...
17
votes
2answers
831 views

Vim - surround comment line with comment character

Today I realised that I often like to define sections in my code like so: #################### # Helper Functions # #################### But that it's tedious to do. Assuming I have a line such as ...
2
votes
1answer
169 views

count number of valid, unique sequences for moving on a 1xn board [closed]

There's a board with n squares in a horizontal row. You start in the leftmost square, and roll a 3-faced dice. 3 possible outcomes for a single roll of the die: Left: you move 1 step to the left, ...
10
votes
1answer
195 views

Generate a Davenport-Schinzel Sequence

Background A Davenport-Schinzel sequence has two positive integer parameters d and n. We will denote the set of all Davenport-Schinzel sequences for given parameters by DS(d,n). Consider all ...
3
votes
3answers
248 views

Noel Constant's idiotically simple investment system

Noel Constant did it without genius and without spies. His system was so idiotically simple that some people can't understand it, no matter how often is is explained. The people who can't ...
20
votes
12answers
2k views

Reading Code in 8 Ways to Output 8 Numbers

The English language and most programming languages are written and read from left-to-right, top-to-bottom, but that needn't be the case. In fact for the block of text ABC DEF I can think of eight ...
18
votes
2answers
468 views

Help me procrastinate on my computer repairs!

This challenge is brought to you by real (and tragic) inspiration. Recently, the number row on my keyboard has been a bit sporadic. The keys 1-9 work sometimes--but other times they have no result. As ...
11
votes
7answers
1k views

Finding prime numbers without using “prime characters”

Your task, if you choose to accept it, is to write a program/function that accepts an integer N as input. The program/function should output/return a list of the first N prime numbers. But here's the ...
11
votes
4answers
419 views

Identifying the triangles

Counting the amount of triangles in a picture is a task commonly used in brain tests. You are given a picture that contains shapes consisting of triangles. You then must find all possible triangles in ...
1
vote
0answers
146 views

LCD Numbers - get my lost 190 bytes back [duplicate]

Years ago I read the "Best of Ruby Quiz" book by James Edward Gray II (also available online by now). For problem 2 in the book (which is problem 14 on his original RubyQuiz site), he mentions a ...
9
votes
7answers
617 views

fourth grade math homework for the week: a most inefficient traveling salesman

My daughter had the following assignment for her math homework. Imagine six friends living on a line, named E, F, G, H, J and K. Their positions on the line are as indicated (not to scale) below: ...
1
vote
0answers
59 views

Weighted distribution [closed]

Your code should: Take in a set of values, each value should be given a weighted percentage. In a loop, up to 1000 iterations, each value should be incremented by one each time it is returned, ...
8
votes
5answers
293 views

Total number of topological sorts

For a given DAG (directed acyclic graph), each of its topological sorts is a permutation of all vertices, where for every edges (u,v) in the DAG, u appears before v in the permutation. Your task is ...
30
votes
12answers
3k views

Decode a Heat Map

Heatmaps Consider a rectangular room, on whose ceiling we have a thermal camera pointing downward. In the room, there are some number of heat sources of intensity 1-9, the background temperature ...
12
votes
6answers
598 views

Iterated Divisor Twist

Definitions Let m and n be positive integers. We say that m is a divisor twist of n if there exists integers 1 < a ≤ b such that n = a*b and m = (a - 1)*(b + 1) + 1. If m can be obtained from n ...