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
13 votes
10 answers
1k views

How much do you win in the Bingo Golf Flax Lottery?

The challenge, should you accept it, is to determine how much you win in the Bingo Golf Flax Lottery. Based on but not equal to the BingoFlax lottery The input is two lists of numbers (positive non-...
Kjetil S's user avatar
  • 5,887
5 votes
6 answers
409 views

Find a fraction with the smallest denominator

Input Two non-negative floating point numbers \$x < y\$. You can assume they are close enough to each other that there is no integer between \$x\$ and \$y\$. Output A fraction with the smallest ...
Simd's user avatar
  • 2,896
18 votes
15 answers
2k views

Validate a CPF number

Every Brazilian citizen has a national identification number associated with them, named CPF. This number has 11 digits (formatted as XXX.XXX.XXX-XX) and it's validated by the following (real) ...
enzo's user avatar
  • 2,083
-6 votes
4 answers
286 views

Print "abracadabra" with 7 different alterations

Abracadabra is a magic word. To make it even more magical, let's make several alterations to how it may be written: Change the casing for any subset of characters; for example: ...
anatolyg's user avatar
  • 13.5k
1 vote
0 answers
144 views

Exact Sum of 1/2 to 1/n [duplicate]

Consider the sequence 1/2, 1/3 + 1/2, 1/4 + 1/3 + 1/2, and so on. In mathematical symbols, this is $$S(n)=\sum_{m=2}^{n+1}\frac{1}{m}$$ where S is the function that makes the sequence. Outputting this ...
Jakav's user avatar
  • 335
4 votes
7 answers
411 views

Heart plus diamond is spade-and-club: table puzzle

I found this YouTube video with a table on it showing some card suits with ampersands. You might not understand what it is about, but I still want to make a challenge about it. The input is two suits, ...
3-1-4-One-Five's user avatar
24 votes
15 answers
3k views

"Perfect" an array

Given an n non-negative integers, how many numbers must be changed so that each number x appears x times? You cannot add or remove elements, only replace them with other numbers. For example: ...
Larry Bagel's user avatar
  • 4,163
10 votes
12 answers
1k views

Counting Collinear Points

Given two points \$(x_1, y_1)\$ and \$(x_2, y_2)\$ with integer coordinates, calculate the number of integer points (excluding the given points) that lie on the straight line segment joining these two ...
vengy's user avatar
  • 2,163
12 votes
5 answers
1k views

Implement a typeface based on a 3x3 bitmap matrix

Input A single-character string containing an uppercase or a lowercase letter from the English alphabet. Alternatively, you may handle only uppercase or only lowercase letters as input. Output This ...
enzo's user avatar
  • 2,083
8 votes
11 answers
2k views

Shortest path to open a letter lock

This quite literally came to me in a dream. A common combination padlock design has letters on the dials so you can set the combination to a word. Unfortunately, I can't read, but I can count. ...
pacman256's user avatar
  • 3,750
11 votes
20 answers
5k views

Calculate 500 digits of e

Write a program to calculate the first 500 digits of the mathematical constant e, meeting the rules below: It cannot include "e", "math.e" or similar e constants, nor may it call ...
Simd's user avatar
  • 2,896
9 votes
3 answers
473 views

Coin sequence probability

Given two strings containing only 0 and 1, decide the probability that first appears earlier as a consecutive substring in an ...
l4m2's user avatar
  • 23.8k
6 votes
7 answers
725 views

Displaying Inky the ghost from Pac-Man using ANSI escape codes

Challenge Display Inky the ghost from Pac-Man using only ANSI escape codes. Here's a text representation of the image ...
vengy's user avatar
  • 2,163
0 votes
0 answers
85 views

Shortest way to print the first 20 numbers in the fibbonacci sequence with python3 [duplicate]

I was wondering if it was possible to make this code even shorter than it already was. f=lambda x:f(x-1)+f(x-2) if x>1 else 1 [print(f(i))for i in range(20)] ...
Eric Pan's user avatar
10 votes
6 answers
920 views

Unnecessary Fluff

Following the great advice (what do you mean it's not advice?!) on Adding unnecessary fluff we can devise the following task: Take a list of positive integers and a positive integer \$m\$ as input. ...
Command Master's user avatar
16 votes
2 answers
583 views

Construct this point

Given a constructible point \$(x, y) \in \mathbb R^2\$, output the steps required to construct \$(x, y)\$ Constructing a point Consider the following "construction" of a point \$(\alpha, \...
caird coinheringaahin g's user avatar
23 votes
12 answers
6k views

How long is this string, really?

In most programming languages, the string Hello, World! can be represented as "Hello, World!". But if you want to ...
emanresu A's user avatar
  • 37.8k
8 votes
11 answers
1k views

How many Carlitz compositions are there?

OEIS sequence A003242 comprises the numbers of Carlitz compositions for any given positive integer. This is the number of integer partitions of the integer for which no two adjacent parts are equal. ...
Nick Kennedy's user avatar
  • 21.1k
18 votes
31 answers
2k views

Is this number tetrahedral?

Happy New Year 2024! 2024 is a tetrahedral number. A tetrahedral number is a number that can be represented in the form \$n(n+1)(n+2)/6\$ for some positive integer \$n\$. Or, equivalently, they are ...
alephalpha's user avatar
8 votes
7 answers
817 views

Bloons TD 6 Ordered Upgrade Paths

Background The monkeys need your help again organizing their defense and have asked you, Benjamin the code monkey, to create a program that will list all tower upgrade options as they appear in your ...
qwr's user avatar
  • 12.1k
6 votes
13 answers
660 views

Output all the different counts of points

Consider a 10 by 10 grid of points at integer coordinates. Given a coordinate (x, y) of one of the points in the grid and a radius r, some of the points in the grid will fall inside a circle of ...
Simd's user avatar
  • 2,896
7 votes
10 answers
682 views

Official Tetris Piece Ordering

Classic Tetris was often a difficult game to play. One problem was that you could only work with the Tetris piece you were given, so if you had an awkward board, it would sometimes be difficult to ...
vxpr's user avatar
  • 71
19 votes
11 answers
1k views

Name the Dutch ancestor

The Dutch system for naming one's ancestors is a lot more interesting than the English version. For English, the sequence goes "parent", "grandparent", "great-grandparent"...
KeizerHarm's user avatar
  • 1,363
13 votes
12 answers
4k views

The worst spaghetti code

Objective Write a full program that works exactly like the flow chart below. Each output, which is an integer, shall be through stdout, followed by a line feed. ...
Dannyu NDos's user avatar
  • 5,941
19 votes
9 answers
973 views

Output an infinitely proportional sequence

In this challenge, an infinitely proportional sequence is defined as a infinite sequence of positive integers such that: All positive integers are contained infinitely many times within the sequence. ...
emanresu A's user avatar
  • 37.8k
-4 votes
4 answers
246 views

golf a range with modulus and subtraction

if you have a range of numbers with values missing, eg l=[1,2,9,10,99], you can always use modulus and subtraction to make all the numbers in the list cover a ...
guest4308's user avatar
  • 397
7 votes
12 answers
954 views

Can their first appearance happen together?

Given two non-empty 01 strings, check if there is string containing both given strings, and their first appearance end at same position. Test cases: ...
l4m2's user avatar
  • 23.8k
8 votes
6 answers
628 views

How many points this side of the line

Input An integer n and a pair of distinct integer valued (x, y) coordinates on the boundary of the grid. The coordinates are indexed from 1. For example, n=10 and (1,2), (10, 7). The points will ...
Simd's user avatar
  • 2,896
7 votes
3 answers
194 views

Inscribe a maximal regular polygon into a square image

You want to draw a regular polygon but you have limited space! In this challenge, you should draw a polygon with n sides which is as big as possible for a given square container image. I found ...
anatolyg's user avatar
  • 13.5k
10 votes
6 answers
733 views

Convert from Spoken Binary

This is an exact inverse of the question Convert to Spoken Binary. This introduction is copied from there. Introduction In the video the best way to count, binary is proposed as the best system of ...
Tbw's user avatar
  • 1,475
7 votes
11 answers
771 views

Convert tiers between credit rating system

Related: Sort these bond ratings Credit rating agencies assign ratings to bonds according to the credit-worthiness of the issuer. The rating business is mostly controlled by "Big Three" ...
matteo_c's user avatar
  • 6,300
16 votes
6 answers
1k views

Convert to Spoken Binary

Introduction In the video the best way to count, binary is proposed as the best system of counting numbers. Along with this argument is a proposal on how to say numbers in this system. First, we give ...
Tbw's user avatar
  • 1,475
12 votes
10 answers
1k views

Format Datetime in 30-Hour Clock Time

Input a datetime, format the datetime in YYYY-MM-DD HH:mm:ss format using 30-hour clock time. The 30-hour clock time works as: After 6 a.m., it is same as 24-hour ...
tsh's user avatar
  • 34.7k
21 votes
18 answers
6k views

Am I vaccinated?

Disclaimer: the content of this post is not medical information and should not be used for any medical purpose, as it is deliberately oversimplified for the purpose of the challenge. There are several ...
Someone's user avatar
  • 1,580
16 votes
2 answers
280 views

Translate Japanese hiragana into the flick input method

The flick input method is a way of inputting Japanese kana on a modern smartphone. It is arranged in a 12-key layout, with the following labels: あかさ たなは まやら 小わ、 ...
bigyihsuan's user avatar
  • 9,338
18 votes
24 answers
2k views

Test whether a sequence is bitonic

You know what a monotonic sequence is: each element is bigger than its predecessor (monotonically rising) or as its successor (monotonically falling). Bitonic means you have two arms of the sequence, ...
Philippos's user avatar
  • 2,501
2 votes
0 answers
164 views

Golf a PSK31 modulator

Given a string of ASCII text as input, encode it in BPSK31 using Varicode. You may either output an audio file in any common format, or play the audio over the device speakers. You may output at any ...
Someone's user avatar
  • 1,580
12 votes
5 answers
436 views

Maximal linear sublists

In this challenge you will write code to take a list of positive integers and output all maximal linear sublists. A sublist is is a list which can be created by deleting values from the the input ...
Wheat Wizard's user avatar
  • 98.5k
6 votes
3 answers
558 views

Find the sum of the numbers on the circle

Consider an \$n \times n\$ grid and a circle of radius \$r \leq \sqrt{2} n\$ with its center in the top left. In each square there is an integer from the range -3 to 3, inclusive. For a given radius, ...
Simd's user avatar
  • 2,896
4 votes
6 answers
437 views

Cell`s Life #1: Simulate a plant cell

What am I? As a plant cell, your program/function/etc. must undergo photosynthesis: When the input is 6CO2+6H2O+light in any order, output ...
W D's user avatar
  • 390
6 votes
4 answers
245 views

Is it stuck in a counting loop? [duplicate]

Given a list of non-negative integers the function \$f\$ replaces every integer with the number of identical integers preceding it (not necessarily contiguously). So ...
Wheat Wizard's user avatar
  • 98.5k
1 vote
3 answers
288 views

Yin-Yang Table Generator [closed]

I want an n*n table that is filled with black or white and the following conditions are satisfied in it: All cells of a 2*2 square in this table should not be the same color. All black and white ...
Shahnazi2002's user avatar
20 votes
32 answers
3k views

Iteratively sort a list

Given a list of Integers greater than zero, Sort each of the unique values in ascending order, then repeat the process on the remaining duplicate values and append. Example: ...
pacman256's user avatar
  • 3,750
7 votes
6 answers
381 views

Output 5-line calendar

Given year, month and optionally weekday of 1st, output the calendar of the month. The first week should remain nonempty. For empty cell, fill it with the date where it's supposed to be, in last or ...
l4m2's user avatar
  • 23.8k
4 votes
4 answers
578 views

I baked you a pie!

There is an asdfmovie video about a pie flavoured pie. Someone also made an edited version with more pies, so I created this challenge. The input is a positive integer. The code should first output ...
3-1-4-One-Five's user avatar
21 votes
24 answers
4k views

Implement a simple stack language

In this challenge, you implement an interpreter for a simple stack-based programming language. Your language must provide the following instructions: push a positive number pop two numbers and push ...
RubenVerg's user avatar
  • 792
13 votes
7 answers
2k views

Auto-golf an esolang

The lack of a social life drove a poor nerd into inventing another superfluous esolang called !+~%. For no good reason it initializes the accumulator with ...
Philippos's user avatar
  • 2,501
15 votes
19 answers
2k views

Output an image

Interestingly, although there are challenges that work with images, there is no challenge to simply output an image. This is that challenge Goal: output an image in the shortest possible code. Output: ...
Jakav's user avatar
  • 335
6 votes
0 answers
277 views

Solve the word problem*

In this challenge you will receive a list of positive integers \$W\$ called a word, and a square symmetric matrix \$M\$. Your task is to determine if the word can be turned into the empty list by ...
Wheat Wizard's user avatar
  • 98.5k
0 votes
15 answers
679 views

Smallest integer \$n\$ such that \$\frac{\sqrt{\log_2{n}}}{(\log_2 {\log_2 n})^2} > 1\$

Write code that outputs the smallest integer \$n > 5\$ such that \$\frac{\sqrt{\log_2{n}}}{(\log_2 {\log_2 n})^2} > 1\$. Your code may have at most one digit in its source code. You can use ...
Simd's user avatar
  • 2,896