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
71
votes
45answers
6k views

Input ∩ Source Code

Intro The challenge is to create a program/function that prints the intersection of its own source code and a given string input. This is code golf and to be more precise: Let ...
62
votes
62answers
8k views

Lossy Sorting (Implement Dropsort)

Dropsort, designed by David Morgan-Mar, is an example of a linear-time "sorting algorithm" that produces a list that is, in fact, sorted, but contains only some of the original elements. Any element ...
54
votes
149answers
7k views

Output your Score!

Challenge: The concept is simple enough: write a full program to output its own code golf score! Output should only be the byte count of your program and a trailing ...
51
votes
38answers
6k views

Spoonerise words

Given two words, spoonerise them by switching their initial consonant clusters. Fewest bytes wins. ...
46
votes
19answers
5k views

Lever Simulator 2015

Why a Simulator? Kids these days don't have the time nor the ambition to actually go and stack boxes on the see-saw or play around with balancing physical objects. This leaves lots of room in the ...
46
votes
58answers
3k views

Print the f × f times table

Your task is to print the hexidecimal times table: ...
34
votes
38answers
4k views

Determinant of an Integer Matrix

Given a square integer matrix as input, output the determinant of the matrix. Rules You may assume that all elements in the matrix, the determinant of the matrix, and the total number of elements in ...
32
votes
5answers
2k views

Chain reaction of bombs

Introduction: Before the task, here is what every element does on the map: Plain land (X): This does nothing. Destroyed land (...
30
votes
11answers
1k views

Print, Increment, Decrement, Alias - Interpret Prindeal

Prindeal (pronounced prin-dee-al) is a new esoteric programming language that only has four commands: print, increment, decrement, and alias. Despite its minimalism, complex mathematical operations ...
29
votes
24answers
4k views

How Many Rectangles in the Grid?

Well, although this challenge turned out to be a huge success, it also turned out to be very trivial to solve. Therefore, for those of looking for more of a challenge, I created a sequel to this ...
28
votes
25answers
4k views

Index of a multidimensional array

Lower level languages, such as C and C++ actually have no concept of multidimensional arrays. (Other than vectors and dynamic arrays) When you create a multidimensional array with ...
25
votes
49answers
3k views

Factorial digit sum

The challenge is to calculate the digit sum of the factorial of a number. Example Input: 10 Output: 27 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800, and the sum of ...
23
votes
32answers
2k views

Convert a number to Hexadecimal

Challenge Here's a simple one. Write a function or program when given a number in base 10 as input, it will return or print that number's value in Hexadecimal. Examples ...
21
votes
20answers
5k views

Create a sudoku solution CHECKER

Create a Sudoku solution CHECKER There are oodles of Sudoku SOLVERS here, but I want you to create a solution CHECKER as small as humanly possible (code-golf). A valid entry will be able to either ...
19
votes
23answers
7k views

Can Jimmy hang on his rope?

Yet another Jimmy challenge by his original father. See these other lovely challenges. As you all know, recently we've been seeing challenges related to Jimmy on platforms. Now, Jimmy is an acrobat ...
13
votes
7answers
7k views

Find the minimum edit distance between two strings

Explanation The edit distance between two strings is a function of the minimum possible number of insertions, deletions, or substitutions to convert one word into another word. Insertions and ...
64
votes
58answers
9k views

Output a googol copies of a string

I am interested in seeing programs which don't ask for any input, print a googol copies of some nonempty string, no less, no more, and then stop. A googol is defined as 10^100, i.e., 1 followed by a ...
42
votes
24answers
6k views

Draw the Sawtooth Alphabet

A simple one today. Write the shortest program that draws a "sawtooth alphabet" given a positive integer for the height. You must write the name of your programming language when you come to the ...
30
votes
23answers
2k views

Incrementing Numbers, Over Multiple Sessions

Good Evening Golf Agents, Your mission is on behalf of notorious entertainment giant Eviltronic Arts. As part of their nefarious plan for world enslavement and entertainment, they must sell as many ...
30
votes
19answers
2k views

Convert number to a base where its representation has most “4”s

Inspired by this. There is a number, given as either integer, string or array of digits (your choice). Find the base in which the representation of the number will have most "4"s and return that base. ...
29
votes
56answers
5k views

“Multiply” two strings

This was inspired by a function I recently added to my language Add++. Therefore I will submit an short answer in Add++ but I won't accept it if it wins (it wouldn't be fair) Don't you hate it when ...
26
votes
4answers
2k views

Golf Me An OOP!

Golf Me An OOP! Two important components of object-oriented programming are inheritance and composition. Together, they allow for creating simple yet powerful class hierarchies to solve problems. ...
25
votes
11answers
1k views

Tips for Golfing in Go

What general tips do you have for golfing in Go? I'm new to Code Golfing and looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Go. Please ...
22
votes
6answers
1k views

Generate the shortest De Bruijn

A De Bruijn sequence is interesting: It is the shortest, cyclic sequence that contains all possible sequences of a given alphabet of a given length. For example, if we were considering the alphabet A,...
22
votes
43answers
3k views

Shortest power set implementation

Problem definition Print out the powerset of a given set. For example: [1, 2, 3] => [[], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]] Each element is to ...
20
votes
38answers
5k views

Additive Persistence

The shortest code to pass all possibilities wins. In mathematics, the persistence of a number measures how many times a certain operation must be applied to its digits until some certain fixed ...
17
votes
14answers
2k views

We do tower hopping

Task Given an array of non-negative integers a, determine the minimum number of rightward jumps required to jump "outside" the array, starting at position 0, or ...
17
votes
68answers
9k views

Pi Calculation Code Golf [closed]

The Challenge You must calculate pi in the shortest length you can. Any language is welcome to join and you can use any formula to calculate pi. It must be able to calculate pi to at least 5 decimal ...
12
votes
9answers
2k views

Evaluate the nth hyperoperation

I do realise that this is a bit math-y, but - here goes. In mathematics, the hyperoperation sequence is an infinite sequence of arithmetic operations (called hyperoperations) that starts with the ...
8
votes
17answers
3k views

Multiply without multiply [closed]

Write the fastest (best big-O) and smallest multiplication algorithm for positive integers, without using multiplication operators. You are only allowed addition, subtraction, logical functions (AND, ...
7
votes
12answers
257 views

Tips for golfing in Factor

What general tips do you have for golfing in Factor? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Factor (e.g. "remove comments" is ...
58
votes
39answers
5k views

User Appreciation Challenge #1: Dennis ♦

I got the spontaneous idea of making a series of challenges of users that have helped and continue to help the PPCG community be an enjoyable place for everyone, or maybe just specifically for me. :P ...
36
votes
19answers
3k views

Bracket Expansion!

Your challenge is to expand some brackets in a program's input as shown: Find a string s between two matching brackets [ and ], ...
35
votes
32answers
2k views

Manage Trash So

It's become somewhat of a tradition in PPCG that some users temporarily change their names by an anagram (a new name formed by reordering the letters of the old). Sometimes it gets difficult to find ...
32
votes
9answers
3k views

Balance a set of weights on a seesaw

Balancing Act Overview Given an input of 3 single-digit positive integers representing a set of weights, output an ASCII representation of a seesaw with the weights placed on it so that it is in ...
30
votes
16answers
6k views

Multiply two numbers without using any numbers

You are given as input two strings representing positive integers in base 10, such as "12345" and "42". Your task is to output a ...
29
votes
8answers
6k views

Print the American Flag!

Special Independence Day (USA) themed challenge for you today. You must write a program that prints this ascii-art representation of The American Flag. ...
27
votes
25answers
3k views

Find the next 1-sparse binary number

A positive integer N is K-sparse if there are at least K 0s between any two consecutive 1s in its binary representation. So, the number 1010101 is 1-sparse whereas 101101 is not. Your task is to ...
27
votes
6answers
2k views

Can you Meta Quine?

Similar to other quine puzzles (more specifically, this one), write a program that produces the source for itself. Here's the new twist: The code produced should NOT be identical to the source. ...
26
votes
29answers
2k views

Ordering a list

Summary Given a list of integers, return the index each integer would end up at when sorted. For example, if the list was [0,8,-1,5,8], you should return ...
26
votes
35answers
6k views

Mode (most common element) of a list

Write a snippet to calculate the mode (most common number) of a list of positive integers. For example, the mode of d = [4,3,1,0,6,1,6,4,4,0,3,1,7,7,3,4,1,1,2,8] ...
24
votes
26answers
2k views

Surround a string with hashes

I've already made this in Python, but it seems that it could be shortened a lot: ...
24
votes
20answers
2k views

Imitate an ordering

Given two lists of numbers, a source and a pattern, reorder the source to match the relative ordering of the pattern. Any two entries of the reordered source should compare the same way as the entries ...
24
votes
45answers
3k views

Non Unique Elements

Write a program which finds the non-unique elements of an array of signed integers. The resulting array can be in any order. Your answer may be a snippet which assumes the input to be stored in a ...
22
votes
10answers
1k views

Roll the Alphabet into a Spiral

Write a program or function that, when given n, will print a spiral n characters long made up of the Latin alphabet ...
22
votes
4answers
1k views

Cryptographic quine variant

Create a program that prints the MD5 sum of its source in the form: MD5 sum of my source is: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx No cheating - you can't just read ...
20
votes
10answers
2k views

Can maze be solved?

The puzzle Print 0 if a maze n*m can not be solved Print 1 if a maze n*m can be solved (in 1 or more ways) (so I'm not asking for paths but if it's possible to solve!!!) Input array(2d): ...
20
votes
20answers
4k views

Eiffel Towers: Create a large “A” from “A”s

Create a function which given a number of lines n, makes a bigA. The horizontal bar of bigA ...
18
votes
3answers
2k views

Regex in reverse - decompose regular expressions

The Problem I have a bunch of regular expressions that I need to use in some code, but I'm using a programming language that doesn't support regex! Luckily, I know that the test string will have a ...
17
votes
4answers
3k views

Rotate an ASCII art image

Out of all of the ASCII characters, it is easy to tell that some of them form groups that are rotations of the same basic character. For example, V > ^ <. ...

1
5 6
7
8 9
64