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
0 votes
20 answers

How Many Paint Tins Do I Need?

Task Take in 3 inputs. The length of the wall, the height of the wall and the coverage of the paint. Output how many tins of paint are required. Output Since there's no way to purchase ...
14 votes
11 answers

Which skill to train?

Story (skip, if you prefer the naked task): You need five skills for an imaginary sport: Speed, strength, endurance, accuracy and tactics. If you achieve a score in each of these disciplines, you can ...
53 votes
66 answers

Multiplicative persistence

Multiplicative Persistence Multiply all the digits in a number Repeat until you have a single digit left As explained by Numberphile: Numberphile "What's special about 277777788888899?" ...
-12 votes
2 answers

Bingo Cards PDF

Write code to generate a PDF file containing 6 bingo cards. Winner is the one that uses the shortest code and needs no actions except for installing a library and running the code. (No Save As PDF). ...
16 votes
10 answers

How many light changes will a 7-segment display need?

Problem Assume you have a single 7-segment display without a decimal point, so 7 "lines" that can be labelled A through G as seen here. This display will only show the numbers from 0 to 9 ...
57 votes
57 answers

Count without 3

Background When I was in elementary school, we used to play a game in math class that goes as follows. All kids sit in a big circle and take turns counting, starting from 1. However, the following ...
4 votes
2 answers

Convert real numbers between factoradic and positive integer bases

This prompt asked you to convert back and forth to factoradic, but is very limited in scope (only decimal integers from 0 to 10!-1). Your task in this challenge is to reach just a bit further and ...
27 votes
18 answers

Create Bernard from Desmos

Background In the online graphing calculator Desmos, there is a certain shape that appears in the lower left portion of the graph in many high detail graphs, which the Desmos community has dubbed &...
27 votes
72 answers

Minimum excluded number

This is intended to be an easy, bite-size code-golf. The mex (minimal excluded number) of a finite collection of numbers is the smallest non-negative integer ...
-3 votes
1 answer

Bingo Cards SVG Code [duplicate]

Generate the contents of an SVG file containing 6 bingo cards. Winner is the one that uses the shortest code. A qualifying answer has an output that can be directly pasted in a blank to get the ...
14 votes
16 answers

Finding the power sandwich

Introduction Finding the closest power to a number is a common enough problem. But what if you need both the next-highest and next-lowest power? In this challenge you must find the closest powers to a ...
77 votes
167 answers

Diagonal Alphabet

Given no input, your task is to generate the following: ...
9 votes
3 answers

Get the Bible verse

Write a program that accesses Project Gutenberg's KJV Bible, either from a file called pg10.txt in the working directory or in any other way that is typical for the ...
29 votes
47 answers

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 ...
28 votes
37 answers

Remove Spaces, Maintaining Capitalization

Your input will be an English sentence, phrase, or word. It will only contain a-zA-Z' -,.!?. Your task is to take the input, remove spaces, and then redistribute ...
19 votes
38 answers

Print the Christmas alphabet

Write a program to print or return one of these strings verbatim: abcdefghijkmnopqrstuvwxyz ABCDEFGHIJKMNOPQRSTUVWXYZ Notice that there is no L.
13 votes
21 answers

German pharmacy payment

Your task is to calculate the amount you have to pay for prescribed medication at a pharmacy in Germany. The amount is simply based on the full price of the item, which will be your input. It is a ...
11 votes
18 answers

Percentage of work days in a month

Given a year and a month, find out the percentage of work days in said month. Work days are Monday through Friday with no regard to holidays or other special things. The Gregorian calendar is used. ...
18 votes
9 answers

Limited letter renderer: BIOPD

There have of course been challenges to render ASCII art fonts here and there. This challenge doesn't add anything to those. In contrary, it subtracts from them for a good reason. If you allow all ...
15 votes
19 answers

Last Week Day Of The Month

Introduction This challenge was inspired by a seemingly simple task requested at work that couldn't easily be done in Microsoft Teams. At least not from what we could find! Task Your task, if you ...
242 votes
450 answers

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 ...
36 votes
63 answers

Backwards Alphabet Triangle

Without taking any input, output this exact text: ...
66 votes
60 answers

Determine your language's version

Your challenge is to write a polyglot that works in different versions of your language. When run, it will always output the language version. Rules Your program should work in at least two versions ...
-3 votes
34 answers

Print A-Z and their alphabet index without using 1,2,4,6

You need to print A-Z like this: ...
5 votes
20 answers

Find all numbers between 2 and 100 co-prime to a given number

Your program will be given a number as input. Your challenge is to output all the numbers between 2 and 100 inclusive that are co-prime to the given number. (Two numbers are co-prime if their GCD is 1....
16 votes
25 answers

Sums of 100 Rolls of Two Six Sided Dice

Suppose you have two six-sided dice. Roll the pair 100 times, calculating the sum of each pair. Print out the number of times each sum occurred. If a sum was never rolled, you must include a zero or ...
85 votes
222 answers

Sum of all integers from 1 to n

I'm honestly surprised that this hasn't been done already. If you can find an existing thread, by all means mark this as a duplicate or let me know. Input Your input is in the form of any positive ...
67 votes
140 answers

Reverse stdin and place on stdout

Requirements: Take an input on stdin including new lines / carriage returns of unlimited length (only bounded by system memory; that is, there is no inherent limit in the program.) Output the reverse ...
26 votes
58 answers

Is it a pure word?

Introduction A pure word (or perfect word), as defined by me, is a word where the sum of the position in the alphabet of each letter in the word is perfectly divisible by the total length of the word. ...
47 votes
92 answers

Determine if all decimal digits are unique

Deleted questions on Stack Overflow sometimes make for great golf material. Write a function that takes a nonnegative integer as input, and returns true if all the digits in the base 10 ...
172 votes
486 answers

Implement a Truth-Machine

A truth-machine (credits goes to this guy for coming up with it) is a very simple program designed to demonstrate the I/O and control flow of a language. Here's what a truth-machine does: Gets a ...
28 votes
4 answers

Never trust a mastermind

You probably know the game mastermind: The player tries to guess a code of 4 slots, with 8 possible colors - no duplicates this time. Let's call those colors A through H, so possible solutions could ...
147 votes
78 answers

Interpret brainfuck

Write the shortest program in your favourite language to interpret a brainfuck program. The program is read from a file. Input and output are standard input and standard output. Cell size: 8bit ...
64 votes
54 answers

Display the Hacker Logo

You may have heard of the "Hacker Logo", also called the "Hacker Emblem". It looks like this: This is a pattern from a mathematical simulation called the Game of Life. The glider is the simplest Life ...
15 votes
15 answers

Extract a string from a given string

You are given a string and two characters. You have to print the string between these characters from the string. Input Input will first contain a string (not empty or ...
34 votes
70 answers

Sum the array times n, except the last

I've been posting relatively hard challenges recently, so here goes an easy one. Task Given an array \$A\$ and a number \$n\$, calculate the sum of all numbers of \$A\$ multiplied by \$n\$, except the ...
17 votes
34 answers

Rudin-Shapiro sequence

The Rudin-Shapiro sequence is a sequence of \$1\$s and \$-1\$s defined as follows: \$r_n = (-1)^{u_n}\$, where \$u_n\$ is the number of occurrences of (possibly overlapping) \$11\$ in the binary ...
4 votes
2 answers

Shortest C code to display argv in-order

I recently tried to produce the shortest C code possible to display all its command line arguments (which are stored in argv). I ended with a relatively small piece of code, and I was wondering if ...
26 votes
45 answers

Does the nth char equal the nth from last char?

Inspired by Does the start equal the end Given a string s and an integer n, output a truthy/falsey as to whether the ...
29 votes
51 answers

All together now

Given a list of digits 1 through 9, output whether each digit is grouped together as a single contiguous block. In other words, no two of the same digit are separated by different digits. It's OK if a ...
23 votes
30 answers

They call me Inspector Morse

A string is dot-heavy when its morse representation contains more dots than dashes. For example, the letter E is a single dot, which means it is Dot-heavy. Input The input string will only contain ...
8 votes
25 answers

Make an inversedict

Input A dictionary with string keys and string values. Output The 'inversedict' of this dictionary. How to make an inversedict An inversedict is a dictionary with string keys and string array ...
12 votes
27 answers

Sort list by types

Rules You will receive as input a list that contains integers and strings. Your task is to move all of the strings to the end of the list and all of the integers to the beginning of the list. This is ...
11 votes
6 answers

Tips for golfing in Retina

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

Electron Configuration

In atomic physics and quantum chemistry, the electron configuration is the distribution of electrons of an atom in atomic orbitals. For example, the electron configuration of the neon atom is 1s2 2s2 ...
30 votes
57 answers

Find i^n, given n

The Challenge In as few characters as possible, find the value of \$i^n\$, given \$n\$, a positive integer greater than 0. This should be outputted as a String. For those that don't know, \$i\$ is ...
43 votes
69 answers

Consecutive 1-Bits are Incremented

Given a pattern (string or array format) of Bits : [0,1,1,1,0,1,1,0,0,0,1,1,1,1,1,1] The tasks is to replace any number of consecutive 1-Bits with an ascending ...
20 votes
3 answers

Counting universal n-ary logic gates

Background A classical logic gate is an idealized electronic device implementing a Boolean function, i.e. one that takes a certain number of Boolean inputs and outputs a Boolean. We only consider two-...
106 votes
54 answers

I copied my password to the clipboard! Can you delete it?

Following the best security practices, I keep a plain text file with my passwords on my hard drive. In fact, I just copied and pasted one of them to access my PPCG account. In a lucid moment, I decide ...
121 votes
405 answers

Print a 10 by 10 grid of asterisks

Background This is a standard textbook example to demonstrate for loops. This is one of the first programs I learnt when I started learning programming ~10 years ago. Task You are to print this exact ...

2 3 4 5