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
28
votes
22answers
4k views

Speed of Lobsters

From the subreddit r/SpeedOfLobsters: Edit the text of an image to create a new phrase This meme format/style is pretty self-explanatory. Simply have a browse through the subreddit if you need more ...
-1
votes
0answers
82 views

The Changing Quine [duplicate]

the goal here is to make a proper quine that outputs its source code and changes the source code to another quine that does the same thing. after some runs, which doesn't have to be two, the source ...
21
votes
32answers
1k views

Print a conversion table for (un)signed bytes

Your task: Print or return a conversion table with every byte from 00 to ff's value as an unsigned integer, to its value as a ...
41
votes
11answers
5k views

The first published picture of the Mandelbrot set

Here’s the picture of the first published picture of the Mandelbrot set. Use the fewest bytes possible to write a program or function that outputs the following. A trailing new line is permitted. ...
17
votes
13answers
3k views
+100

Landau logarithm

Related: Landau's function (OEIS A000793) Background Landau's function \$g(n)\$ is defined as the largest order of permutation of \$n\$ elements, which is equal to \$\max(\operatorname{lcm}(a_1,a_2,\...
2
votes
0answers
97 views

Compute the minimal and maximal subset of a set of sets [closed]

Let S be a set of sets, for example S = {{A},{B},{A,B}}. A maximal subset, Max, is an element of S such that no other set in S ...
7
votes
5answers
590 views

Does this JavaScript function support keyword arguments?

JavaScript has no direct support for keyword arguments, but it supports argument object destructuring. It is standard to use a destructed final argument for keyword arguments. Here is an example: <...
14
votes
8answers
2k views

Is my triangle on the lattice?

Write a program or function which takes three positive integers \$a, b, c\$ and returns/outputs one value if there is, and a different value if there isn't, a triangle on the square lattice, whose ...
3
votes
0answers
327 views

Solve a Cubic Equation [closed]

Input Your program will take in the integer coefficients of the equation \$ax^3+bx^2+cx+d=0\$ as inputs (a, b, c, and d). Output All real solutions of the input equation, with an accuracy of at ...
9
votes
1answer
264 views

Win a KQ vs K endgame

Win a K vs KQ endgame Summary The goal of this challenge is to create a program or function which will win a Chess game with a King and Queen against a lone King. The user will specify three squares, ...
20
votes
5answers
726 views

The Caged Circles

This problem will have you analyzing circles drawn on the grid, with the gridlines drawn at integer values of \$x\$ and \$y\$. Let \$\varepsilon\$ be a very small number (think, \$\varepsilon = 0.0001\...
8
votes
3answers
465 views

Validating a Battleship board

Do you know the game Battleship? Well, I want to play with my little brother, but before we can begin we need to set up our ships on the board. This is your input. Now, we need to check that the ships ...
3
votes
2answers
345 views

Minimal Pairing

Your program should take two lists, where each entry (a positive integer) represents the number of members of some group, as input. These lists will have the same sum but may have different lengths. ...
17
votes
13answers
630 views

Sub-string Extractor with Specific Keywords

Challenge The goal of this challenge is to make a function that takes an input string, a start keyword and a end keyword. The output extracted result is from (but excluded) the given start keyword to (...
20
votes
19answers
3k views

Draw an ASCII hexagon of side length n

Given a positive integer \$n\$ output an ASCII hexagon with diagonal side length \$n\$, as pictured (note there are \$2n\$ _ characters on the top edge) Examples: \$...
27
votes
10answers
2k views

Help Stack Exchange transpose tables

Stack Exchange doesn't know how to transpose tables. Let's help. Given a markdown table, transpose it. Input assumptions: There will be at least two rows (including header) and two columns Either all ...
13
votes
20answers
1k views

Linear integer function generator

Inspired by a recent challenge involving Fibonacci numbers in which OEIS was mentioned, I would like to present a challenge of creating a function that generates a wide array of different linear ...
22
votes
18answers
964 views

Interpret Interval Notation

Interval notation is a way to write complicated range bounds more conveniently and concisely than writing an inequality. The challenge, should you choose to accept it, is to write a program or ...
18
votes
5answers
1k views

Find a sequence in the binary digits of π

Given a binary sequence of finite length, find the starting position where this sequence first appears in the binary digits of π (after the decimal). You can assume that an answer exists for any input ...
11
votes
5answers
563 views

Ellipsoid surface area

Related: Ellipse circumference Introduction An ellipsoid (Wikipedia / MathWorld) is a 3D object analogous to an ellipse on 2D. Its shape is defined by three principal semi-axes \$a,b,c\$: $$ \frac{x^2}...
24
votes
13answers
4k views

How long till Halley's Comet returns?

Halley's Comet is the only comet that may appear (i.e. become visible to the naked eye on Earth) twice in a human lifetime. The orbital period of Halley's Comet is not constant: it has varied between ...
13
votes
11answers
1k views

Golfing Advent of Code 2020, Day 3

I thought it'd be interesting to turn AoC day 3 puzzle into a Golfing Challenge, so here it is. Task Find the number of # you'd encounter in an 11x11 grid (...
17
votes
17answers
2k views

Vandalizing Marquees

A marquee is a low-tech board that allows customizable letters. For example, here is a marquee: SALE ON SNEAKERS However, someone might come along and vandalize it ...
8
votes
13answers
366 views

Von Neumann Neighborhood

Your goal is to make a function that takes the coordinates of a cell in 2D space and a distance \$r\$ and returns the coordinates of all cells in the input coordinate's von Neumann neighborhood of ...
6
votes
15answers
786 views

Prime generating function

Background The Python code ((((((((n%35)^11)*195)|53)&181)+n)%168)*n)+83 produces 74 distinct primes for \$0 \le n \le 73\$. This code also works in Java. The ...
23
votes
14answers
2k views

Pascal's Fibonacci Triangle

What do you get when you cross Pascal's Triangle and the Fibonacci sequence? Well, that's what you have to find out! Task Create a triangle that looks like this: ...
20
votes
27answers
962 views

Partial sums of the Kempner series

The Kempner series is a series that sums the inverse of all positive integers that don't contain a "9" in their base-10 representations (i.e., \$\frac{1}{1} + \frac{1}{2} + \frac{1}{3} + .. +...
23
votes
12answers
1k views

Bedevil your hangman opponent

Task You are playing Hangman, and your opponent uses a simple but effective strategy: Each turn, from the remaining letters, they guess the letter that appears most frequently across all possible ...
16
votes
14answers
1k views

Split a number in every way possible way within a threshold

Task Given a positive integer number and a threshold, split into every possible way without generating any numbers above the threshold. Examples Input: 15008 Threshold: 400 Valid Output: ...
2
votes
1answer
134 views

Twist on words to numbers [closed]

The Goal The goal of this question is to put a twist on this question. Your answer should be able to convert an array of words associated with integers into those integers. As an extra challenge, ...
30
votes
2answers
1k views

Golf the smallest sphere!

Inspired by this challenge, as well as a problem I've been working on Problem: Given a non-empty set of points in 3D space, find the diameter of the smallest sphere ...
13
votes
7answers
618 views

Generalised Taxicab Numbers

\$\newcommand{T}[1]{\text{Ta}(#1)} \newcommand{Ta}[3]{\text{Ta}_{#2}^{#3}(#1)} \T n\$ is a function which returns the smallest positive integer which can be expressed as the sum of 2 positive integer ...
24
votes
25answers
2k views

Based Palindromes

A palindromic number, as a refresher, is any number which reads the same forward as backwards. However, what about palindromes in other bases? Input Any integer b ...
17
votes
16answers
4k views

I don't like curry

I don't like curry. Help me reverse the effects of this evil question - Make me some curry - by uncurrying functions. Task Given a blackbox curried function, output its uncurried equivalent. The ...
23
votes
2answers
1k views

Eye test - How many squares are in this picture?

The picture: Sick of the same old grid where the answer is simply a square pyramidal number? Accept the challenge and write a program that given a positive integer \$n\$ counts how many squares are ...
11
votes
17answers
1k views

Polynomial Laplace transform

This is a repost of this challenge, intended to revamp it for looser I/O formats and updated rules You are to write a program which takes an integer polynomial in \$t\$ as input and outputs the ...
6
votes
3answers
333 views

Golf me a polygonal loader

Codidact post, CGCC Sandbox, Codidact Sandbox Given three positive integers as input, animate an ascii-art polygonal loading symbol on the screen. Intro You will be given three inputs, \$n\$, \$l\$, ...
4
votes
5answers
177 views

Strobogrammatic Numbers [duplicate]

Strobogrammatic Numbers Definition A number which is rotationally symmetrical, i.e., it'll appear the same when rotated by 180 deg in the plane of your screen. The following figure illustrates it ...
27
votes
37answers
2k views

Jelly's Untruth

Jelly has an "untruth" atom: . This takes a non-empty array of positive integers and returns a Boolean array with 1s at the indexes in the input. For ...
13
votes
8answers
1k views

How Many Atoms?

How Many Atoms? Write the shortest code that when given a chemical formula as input, outputs the total number of atoms in the formula. Input A chemical formula in any reasonable format. Each chemical ...
37
votes
31answers
4k views

Find the “Bittiest” Number [closed]

The Challenge Given a list of integers, the "bittiest" number among them is the one with the most bits on - that is, the largest amount of bits set to 1. Write a function (or a program) that ...
25
votes
21answers
992 views

Generate newspaper page number sets

A newspaper is made of several sheets; for the purposes of this question, each sheet of newsprint holds four pages of the final newspaper. Here is an example of three sheets of newsprint making up a ...
10
votes
10answers
722 views

Find the number of ways to climb a stairway

Challenge: Find the number of ways to climb some stairs with n steps and with some limitations. You should be able to run the tests below on TIO https://tio.run/ without timing out. – 60 seconds. (...
8
votes
8answers
182 views

Squarefree Palindromes [closed]

Create the shortest function, program, or expression that calculates a sequence of squarefree palindromic numbers. A squarefree number is one which is not evenly divisible by a square number (i.e. ...
23
votes
9answers
853 views

Animal-Alphabetical Sequence

The Animal-Alphabetical Sequence is an infinite string of letters built accordingly to the following procedure: Start with the letter A; Replace each letter with ...
15
votes
4answers
897 views

(Almost) Solve Fermat's Last Theorem

It's a well-known fact that Fermat's Last Theorem is true. More specifically, that for any integer \$n \gt 2\$, there are no three integers \$a, b, c\$ such that $$a^n + b^n = c^n$$ However, there are ...
13
votes
12answers
865 views

Compute the Redwolf Checksum™ of some data

I will preface this by saying that I made this for fun; I have absolutely no formal knowledge on cryptography or error correction. Do not use this algorithm in anything remotely important. I was kind ...
-1
votes
2answers
115 views

increment a binary number without arithmetic manipulations [closed]

Input: binary string Output: binary string that represents the binary input + 1 Example: Given 10111 as an input, output 11000 ...
0
votes
1answer
99 views

Convert all the newlines in a file from \r\n to \n [duplicate]

Inspired by what I'm doing at work right now. Your program should take one parameter, the path to the file It should convert all the windows style newlines (\r\n) to unix style (\n) and write the ...
28
votes
28answers
2k views

Ken Iverson’s Favourite APL Expression?

Ken Iverson, 1920–2020 Let's implement his favourite expression: Given a row of Pascal's triangle, compute the next row. This can for example be computed by taking the input padded with a zero on the ...

1
2 3 4 5
202