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
12
votes
1answer
188 views

Polygons in a cube

Inspired in part by this Mathologer video on gorgeous visual "shrink" proofs, and my general interest in the topic, this challenge will have you count regular polygons with integer ...
18
votes
24answers
3k views

Write a program that uses all printable non-alphanumeric ASCII symbols

In particular, use each of these symbols at least once in your source code: ! " # $ % & ' () * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~ Symbols ...
86
votes
45answers
16k views

Sleep for 1000 years

Some sleep commands implement a delay of an integer number of seconds. However, 232 seconds is only about 100 years. Bug! What if you need a larger delay? Make a ...
15
votes
37answers
1k views

Lolololololololololololol

Let us take a break from the brain-wrecking questions and answer some of the simpler ones You have recently read something extremely funny, and want to express your laughter to the world! But how can ...
14
votes
23answers
2k views

Create an Accurate How-To Article

Here is an easy-intermediate challenge for anyone interested! What is that? A thing me and brother do a bit too often is this: One of us has a problem and asks the other to explain how to do certain ...
16
votes
31answers
3k views

Randomly pick one number that is different than two other random numbers

Two random numbers A and B have been generated to be either 1, 2, or 3 your job is to randomly pick a third number ...
17
votes
28answers
3k views

Calculate prime gaps

Finding primes is a programming rite of passage and very frequently the first serious program someone creates (usually with trial division). But primes alone are already worn out. A next far more ...
14
votes
10answers
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 ...
26
votes
25answers
1k views

Find the sum of all possible base representations

The objective of this challenge is to write a program to convert an inputed string of what can be assumed as containing only letters and numbers from as many bases between 2 and 36 as possible, and ...
51
votes
78answers
9k views

Do n and n^3 have the same set of digits?

Given a number n (0 <= n <= 2642245), check if n and n3 have the same set of digits, and output a truthy or falsey value accordingly. For example, let's check the number 100. 1003 is 1000000. ...
7
votes
0answers
61 views

Distance between point and line segment [closed]

Given a point and a line segment in the plane, output the Euclidian distance between them, that is the distance between the given point and the nearest point on the line segment. This nearest point ...
14
votes
18answers
1k views

Find the Inverse Neighbor Pairs

Definition We say a pair of integers \$(a,b)\$, where \$0<a<b<N\$ and \$N\$ is an integer larger than 4, is an inverse neighbor pair respect to \$N\$ if \$ab\equiv1\text{ }(\text{mod }N)\$ ...
13
votes
13answers
1k views

Finding the most 'unique' word

Using you language of choice, write the shortest function/script/program you can that will identify the word with the highest number of unique letters in a text. Unique letters should include any ...
6
votes
7answers
460 views

Generate lists in which every sublist has a unique element

The problem is defined as follows: Create a function that takes an integer and returns a list of integers, with the following properties: Given a positive integer input, n, it produces a list ...
10
votes
13answers
482 views

Fibonacci distribution validator

Related: Hello world!!! Fibonacci distribution Create a program that returns True if a given input meets the following specifications, and False otherwise: The count of numeric characters (0-9) in ...
21
votes
21answers
1k views

Shortlex predecessor

Please note the special scoring for this challenge. Given a non-empty string made of a-z, output the string immediately before it in the shortlex order. Shortlex ...
52
votes
53answers
6k views

Swap the Alphabet

In this challenge, you will be "reversing" the alphabet or swapping a-z with z-a. This is commonly known as the Atbash cypher. ...
46
votes
15answers
5k views
+100

A naturally occurring prime generator

There are quite a large number of prime generating functions. Pretty much all of them are constructed and are based on the sieve of Eratosthenes, the Möbius function or the Wilson's theorem and are ...
14
votes
21answers
1k views

Double Prime Words

Consider a word/string of length \$n\$, only including the letters A-Z, a-z. A word/string is a double prime word if and only if n is prime and the sum of the letters, s, is also prime, using their ...
37
votes
22answers
13k views

Deciphering XKCD colors

Randall Munroe (author of XKCD) held a survey to give names to colors. The main outcome is a list of names for the 954 most common RGB monitor colors. For ease of programming, here is the list in ...
9
votes
12answers
1k views

Find the largest contiguous prime in a string

In fairness, this is based on a StackExchange question - but its a good question. The challenge is fairly simple: Take a string of numerals Find and print the largest contiguous prime number in the ...
30
votes
32answers
5k views

Guess my password (cops' thread)

Inspired by this challenge, which got closed. This is meant to be an easier, but no less interesting version of that. This is the cops thread of a cops-and-robbers challenge. For the robbers thread, ...
22
votes
17answers
4k views

My array should equal this, but it doesn't!

Given an array of integers a which contains n integers, and a single integer x; remove the fewest amount of elements from ...
6
votes
13answers
794 views

Replace letters by their rank, keeping punctuation intact

The problem is simple. Given a string such as Hello World! the program would output 8-5-12-12-15 23-15-18-12-4-!. Any delimiters ...
17
votes
22answers
1k views

Get the Systematic Chemical Symbol

Background The systematic chemical symbol is defined as such for \$ 118 < n < 1000 \$: The first letter corresponds to the first digit, capitalized. The second letter corresponds to the second ...
20
votes
42answers
3k views

Converting Strings to Decimals (Gone Wrong)

What? Many programming languages, both practical and esoteric, have functions, methods, etc to convert a given string to a decimal number. This is how the process might work: For each character in ...
16
votes
20answers
981 views

Find relevant digit groupings

Recently, my reputation was 25,121. I noticed that each digit grouping (i.e. the numbers separated by commas) was a perfect square. Your challenge is, given a non-...
10
votes
12answers
618 views

A Megachess Board

You want to create a square chessboard. Adjacent tiles must alternate black and white like a standard chessboard, and the bottom left corner can be either black or white. Your program will take in ...
12
votes
6answers
641 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 (...
38
votes
39answers
4k views

The Rien Number

The Champernowne constant is a number that is constructed by concatenating the first n numbers, with n tending to infinity. It ...
20
votes
29answers
1k views

Make String Waves

Given a string as input, output the string with the following algorithm applied: ...
10
votes
14answers
296 views

Golf a bijection \$\mathbb{N}^n\to\mathbb{N}\$

Your task is to write a program which implements a bijection \$\mathbb{N}^n\to\mathbb{N}\$ for \$n \ge 1\$. Your program should take \$n\$ natural numbers as input, in any acceptable method (including ...
35
votes
10answers
2k views

Help me recognise my monster

Background The computer game NetHack dates from 1987, before the use of graphics in computer games was widely established. There are lots of monsters in the game, and potentially a lot need to fit on ...
23
votes
19answers
2k views

Is this a winning *Frustration* configuration?

Frustration is a solitaire card game which is played by calling out the sequence: “Ace”, “Two”, “Three”, ... , "Nine", "Ten", “Jack”, “Queen”, “King”, “Ace”, “Two”, etc. With each call, you ...
24
votes
23answers
4k views

Golf to find Boring numbers

If an integer has a digit/sequence of digits in it which repeats continuously (You will understand why I said "continuously") 5 or more times, we call It "Boring". For example, <...
16
votes
30answers
7k views

Calculate pi to 5 decimals

This comes from http://programmers.blogoverflow.com/2012/08/20-controversial-programming-opinions/ "Given that Pi can be estimated using the function 4 * (1 – 1/3 + 1/5 – 1/7 + …) with more terms ...
17
votes
15answers
2k views

Implement Smokey's !!/alive command

Note: SmokeDetector is a bot that detects spam and offensive posts on the network and posts alerts to chat. What to implement Smokey's !!/alive command uniformly ...
0
votes
13answers
389 views

Implement Smokey's !!/coffee command. (Part 2)

Like the previous SmokeDetector challenge? This one is for you too ;) Note: SmokeDetector is a bot that detects spam and offensive posts on the network and posts alerts to chat. What to implement ...
158
votes
18answers
27k views

Is My Swipe Pattern Legal?

Most Android smartphones allow the user to use a swipe pattern to open their phone: Certain patterns are legitimate, and others are impossible. Given an input swipe pattern, return a truthy or falsy ...
36
votes
17answers
3k views

Is it a digit haiku?

We can read 13576870234289 digit-by-digit in English, and it makes a haiku: one three five seven six eight seven zero two three four two eight nine We say it's a &...
13
votes
6answers
417 views

Can I print my picture on {A,B,C}{0-10} paper?

The task is to find the smallest paper size on which it is possible to print a picture of the dimensions given in milimetres. The image will be printed without margins. Input: Two integers (bigger ...
11
votes
10answers
1k views
+200

Curve Stitching

Curve stitching is the process of "stitching" together multiple straight lines in order to create a curve, like so: For an explanation of curve stitching, visit this website. We will be drawing our ...
12
votes
5answers
2k views
+200

Polynomial Long Division

Implement polynomial long division, an algorithm that divides two polynomials and gets the quotient and remainder: (12x^3 - 5x^2 + 3x - 1) / (x^2 - 5) = 12x - 5 R 63x - 26 In your programs, you will ...
35
votes
30answers
4k views

How many times, are they multiples?

You are given three parameters: start(int), end(int) and list(of int); Make a function that returns the amount of times all the numbers between start and end are multiples of the elements in the list....
10
votes
23answers
1k views

Shorten text with Run Length Encoding

Shorten (or not) text using run length encoding Input: heeeello woooorld Output: 1h4e2l1o 1w4o1r1l1d Read lines from stdin. Print to stdout. Stderr is of course discarded. Assume there are ...
14
votes
14answers
362 views

Repetend length in 1/n [duplicate]

This problem is based on non-terminating, repeating decimal points. Let \$n\$ be any positive integer \$(n > 1 \text{ and } n < 10000)\$, say \$7\$. Then, \$1/n = 1/7 = 0.142857142857142857...\$ ...
21
votes
27answers
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 ...
-10
votes
1answer
355 views
+100

Red screen in FIVE bytes or less (msdos)

Your program is supposed to create a full red screen in MSDOS. The source of the binary (.com file) must be 5 bytes or less. No wild assumptions, the binary must work in MsDos, DosBox, and FreeDos ...
27
votes
20answers
2k views

Calculate the inverse of a matrix

Somehow, we don't yet have a challenge for finding the inverse of an arbitrarily-sized square matrix, despite having ones for 3x3 and 4x4, as well as a more complex version. Your task is, given a ...
46
votes
138answers
14k views

Output programming language name

Challenge: In the programming language of your choice, take no input and output your programming language's name. Fair enough, right? Restrictions: You can't use any character that is included in ...

1
2 3 4 5
200