Questions tagged [code-golf]

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, please state this explicitly in the challenge. If source code length is not the primary scoring criterion, consider using another tag instead.

Filter by
Sorted by
Tagged with
8
votes
6answers
201 views

Church Subtraction

Church Subtraction Lambda calculus has always been a fascination of mine and the emergent behaviors of passing functions into each other is delightfully complex. Church numerals are representations ...
11
votes
6answers
367 views

Billiard balls collision

Given the 2-dimensional positions and velocities of a pair of billiard balls right before impact, calculate their velocities after a perfectly elastic collision. The balls are assumed to be ideal ...
20
votes
13answers
1k views

Implement a Stopwatch

Implement a simple digital Stopwatch, which will display the time elapsed in seconds and minutes, as described below. Important Please read both Display and Controls sections ! Display Time ...
38
votes
38answers
7k views

Print all 2 letter Scrabble Words

The Challenge: Print every 2 letter word acceptable in Scrabble using as few bytes as possible. I have created a text file list here. See also below. There are 101 words. No word starts with C or V. ...
14
votes
8answers
918 views

Averages of Angles

Story, or why we are doing this. None. This exercise is completely pointless ... unless you are Stephen Hawking. The Challenge Given a list of angles, find the average of those angles. For example ...
5
votes
23answers
391 views

Talk interpreter

"Talk" is a baroquified accumulator-based language that is created in response to Dennis's quote on talk.tryitonline.net. ...
32
votes
19answers
6k views

Church Booleans

Church booleans A Church boolean is a function that returns x for true and y for false where ...
409
votes
750answers
123k views

“Hello, World!”

So... uh... this is a bit embarrassing. But we don't have a plain "Hello, World!" challenge yet (despite having 35 variants tagged with hello-world, and counting). While this is not the most ...
13
votes
21answers
533 views

Tex Quotes(UVa 272)

Given a string, replace all left-double-quotes into two backticks and all right-double-quotes into two single-quotes. Left-quotes means the quotes that starts a quote. Right-quotes means the quotes ...
31
votes
31answers
3k views

Numbers with multiple runs of ones

Task Find the set of numbers such that the binary representation contains two or more runs of 1 separated by at least one 0. ...
75
votes
40answers
10k views

Cops and Robbers: Reverse Regex Golf

Note: This challenge is now closed. Any future cops' submission will not be considered for the accepted answer. This is to ensure that no one can post a very simple regex in the future that only ...
8
votes
2answers
246 views

Count the number of a number in the picture area

Your goal is to write a full program or function that takes 5 positive integers and a string with an image filename as input [X1,Y1], [X2,Y2], N, image.jpg in any ...
34
votes
52answers
4k views

ROT-13 transform standard input

The challenge: To read an input of arbitrary length and produce the ROT13 of the input. All characters besides A-Z should be copied to the output verbatim, and case should be preserved if possible. ...
34
votes
51answers
5k views

Zeroes at the end of a factorial

Write a program or function that finds the number of zeroes at the end of n! in base 10, where n is an input number (in any ...
11
votes
54answers
2k views

Round towards zero

This is a simple task. Given a positive or negative real number, round it to the next whole integer closer to zero. The challenge Take input through any reasonable form (stdin, function, etc.) of ...
22
votes
30answers
4k views

A program that deletes itself

If a compiled language is used, the program must delete the compiled executable (but need not delete the source file). If an interpreted language is used, the program must delete the source file. My ...
14
votes
21answers
1k views

Start from ones

Given a strictly positive integer n, follow these steps: Create an array A with n 1s. If A only has one element, terminate. Otherwise, starting from the first element, replace each pair of A with its ...
13
votes
14answers
1k views

triplegolf - not only the source code length counts!

The goal of this challenge is to write a program where the length of the following three are exactly the same: the length of the source code the length of the output it prints to the standard output ...
5
votes
6answers
447 views

The Knight's estate

And then the King said: You fought bravely, Knight, and your deed will not be forgotten for centuries. For your valor I grant you this castle and the lands around it. Things rush me, and I can not ...
35
votes
24answers
3k views

Draw me a domino

Challenge Given two digits 0-9 as input, output a domino (from the double-nine domino set) with these number of pips (dots) on the two faces. The ten possible faces look like this (separated by pipes)...
48
votes
40answers
14k views

Shortest code in your language to persist a string across a reboot

Your Programs: You'll write two programs (both in the same language). The storage program takes a string from STDIN and stores it somewhere persistent (see below) and then exits without error. The ...
181
votes
109answers
23k views

I'm not the language you're looking for!

Isn't it annoying when you find a piece of code and you don't know what language it was written in? This challenge attempts to somewhat solve this. Challenge You will have to write a program that ...
14
votes
24answers
8k views

Remove a letter to make a palindrome

Problem Let's say that a word is almost a palindrome if it is possible to remove one of its letters so that the word becomes a palindrome. Your task is to write a program that for a given word ...
52
votes
14answers
6k views

Who was president of the USA?

Challenge Write a program that takes as input a day from April 30, 1789 to August 21, 2019 and returns as output who was president of the USA that day. Notes For the list of US presidents, the ...
22
votes
40answers
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 ...
203
votes
322answers
42k views

Golf you a quine for great good!

Using your language of choice, golf a quine. A quine is a non-empty computer program which takes no input and produces a copy of its own source code as its only output. No cheating -- that means ...
12
votes
8answers
2k views

Print the first 128 prime numbers without using any reserved words

The obvious solution would be to just print them as a string, but is it possible to write a shorter code? Requirements: No input should be processed, and the output should be in the form of ...
30
votes
30answers
3k views

Greatest common substring

Create a program or function which takes a list of strings as input, and outputs the longest string that is a substring of all input strings. If there are several substrings of equal length, and no ...
15
votes
16answers
3k views

Tips for Golfing in T-SQL

What general tips do you have for golfing in T-SQL? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to T-SQL. Please post one tip per ...
21
votes
10answers
887 views

Nothing like a good ol' game of ModTen

Disclaimer: ModTen is a fictional card game which was created for the sole purpose of this challenge. The rules of ModTen ModTen is played with a standard 52-card deck. Because the full rules are ...
48
votes
40answers
6k views

Undress a string

We already now how to strip a string from its spaces. However, as proper gentlemen/ladies, we should rather undress it. Undressing a string is the same as stripping it, only more delicate. Instead ...
41
votes
182answers
12k views

Add two numbers

Input: Two integers. Preferably decimal integers, but other forms of numbers can be used. These can be given to the code in standard input, as arguments to the program or function, or as a list. ...
81
votes
261answers
16k views

Simple cat program

One of the most common standard tasks (especially when showcasing esoteric programming languages) is to implement a "cat program": read all of STDIN and print it to STDOUT. While this is named after ...
10
votes
13answers
1k views

Irish Snap: Variant Rules

Introduction Recently, me and a couple of my friends decided to play some cards, and one of them suggested the game 'Irish Snap', which was the inspiration for this challenge. However, I later learnt ...
14
votes
12answers
1k views

Circle intersection area

Description : Given x and y positions of two circles along with their radii, output the ...
12
votes
15answers
1k views

Binning in time

The task in this challenge is to put elements of an array into time bins. The input will be a non-decreasing array of positive integers representing the time of events, and an integer which represents ...
34
votes
16answers
6k views

Count to 100 in Danish

Print all the numbers from 0-100 in the right order using the Danish way of counting How they count Like English, they have dedicated words for 0-20, 30, 40 and 100 Instead of saying ...
38
votes
68answers
5k views

Am I divisible by double the sum of my digits?

Given a positive integer as input, your task is to output a truthy value if the number is divisible by the double of the sum of its digits, and a falsy value otherwise (OEIS A134516). In other words: ...
21
votes
60answers
8k views

!I!n!s!e!r!t! !n!b!e!t!w!e!e!n!

Posted from here. This challenge is highly "distilled" from this question. Special thanks to @Akababa! In this task, you should insert an exclamation mark at the start of the string and after every ...
22
votes
1answer
635 views
+200

Optimize Compiler for simple Reverse Polish Notation Programming Language

Description Imaginary programming language (IPL) uses Polish Reverse Notation. It has the following commands: i -- input number and push it to the stack o -- non-destructive output top of the stack ...
17
votes
30answers
2k views

Numbers Decrease while Letters Increase

Randomly inspired by Numbers Increase While Letters Decrease Given a list of mixed letters and integers (e.g., ['a', 2, 3, 'b']) increase the letters by one ...
63
votes
19answers
7k views

Just repeat yourself

Write a program that outputs Do not repeat yourself! Your program code must respect the following constraints : its length must be an even number each ...
16
votes
4answers
2k views

Fancy String Replace

let S, a and b each represent a string Goal: Write a standard string replace function where ...
28
votes
29answers
2k views

The Lucky House

There's a minigame in Super Mario 3D World known as the Lucky House. It consists of a slot machine with 4 blocks. Each block may be one of 5 different icons (Flower, Leaf, Bell, Cherry or Boomerang) ...
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 ...
90
votes
48answers
13k views

In Honor of Adam West

Adam West passed away, and I'd like to honor his memory here on PPCG, though I doubt he knew of our existence. While there are many, many different things that this man is known for, none are more ...
53
votes
50answers
10k views

How much code would a codegolf golf if a codegolf could golf code?

Write a function or program that takes two words as input and outputs variants of the popular English tongue-twister "How much wood would a woodchuck chuck if a woodchuck could chuck wood?". The ...
16
votes
11answers
1k views

Generate a US License Plate

Given one of the following as input: AK,AR,AS,AZ,CA,CT,DC,FL,GA,IL,IN,IA,KS,KY,LA,MD,MI,MN,MS,NV,NH,NJ,NM,NY,NC,ND,MP,OH,OK,OR,PA,PR,RI,SC,TN,TX,UT,VT,VA,WA,WI (...
30
votes
34answers
7k views

The cat ate your input again!

Create a cat program, a.k.a a program that takes an input and prints it. ...Except, the program will randomly take characters away from your input and print that instead. Each character in the input ...
10
votes
7answers
230 views

Crossing sequences

Crossing Sequences Given a list of positive integers A, call it an increasing sequence if each element is greater than or equal to the previous one; and call it a ...