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
4 votes
8 answers
63 views

Swap letter cases

Given a string containing only printable ASCII (codepoints 0x20 to 0x7E), write the shortest program or function that swaps the cases of A-Z and ...
bigyihsuan's user avatar
  • 9,028
17 votes
24 answers
2k views

Strings without twin letters

Consider an arbitrary set of letters \$L\$. It may either be \$\{A, B, C\}\$, \$\{M, N, O, P\}\$, \$\{N, F, K, D\}\$, or even contain all the 26 letters. Given an instance of \$L\$ and a positive ...
enzo's user avatar
  • 1,941
8 votes
5 answers
674 views

Compute the phat-fingered double-bit-flip distance

Recall from this challenge that a phat-fingered double-bit flip or phatflip is defined as follows: Given a nonnegative integer in binary representation a phat-fingered double-bit-flip or phatflip for ...
loopy walt's user avatar
  • 16.6k
1 vote
1 answer
623 views

Compiler for LaTeX

Problem: Given a string representing a mathematical expression with constants (pi, e, psi, i), basic arithmetic operations (+, -, *, /), parentheses, fractions, and exponentiation, write a program or ...
3.14's user avatar
  • 373
10 votes
13 answers
1k views

Enumerate the Phat-fingered-lights-out numbers

Even though the concept of phat-fingered-lights-out number should be pretty self-explanatory here is a definition: Given a nonnegative integer in binary representation a phat-fingered double-bit-flip ...
loopy walt's user avatar
  • 16.6k
9 votes
4 answers
672 views

Find the Chess960 starting positions from its integer ID

Chess960, a.k.a. Fisher random chess, is a variation of the game of chess. In classic chess the starting positions are always the same. In chess960 they vary. Before each game of chess960 one random ...
Kjetil S's user avatar
  • 5,857
15 votes
20 answers
2k views

Spot The Difference

Challenge Generate two \$16 \times 16\$ grids, each initially filled with "@" symbols and spaces. Each cell in the grids should be independently filled with an "@" or a space, with ...
vengy's user avatar
  • 1,613
4 votes
2 answers
311 views

Compact Binary Representation

Background Often, when storing a number in binary with some maximum, we simply round the maximum to the next power of two then allocate the number of bits nececairy to store the whole range. Lets call ...
mousetail's user avatar
  • 12.4k
12 votes
16 answers
2k views

The primitive circle problem

Challenge The primitive circle problem is the problem of determining how many coprime integer lattice points \$x,y\$ there are in a circle centered at the origin and with radius \$r \in \mathbb{Z}^+ \...
vengy's user avatar
  • 1,613
25 votes
22 answers
1k views

Remove falsy rows and columns

Your challenge is to, given a matrix of nonnegative integers, remove all rows and columns that contain a 0. For example, with this matrix: ...
emanresu A's user avatar
  • 37.1k
11 votes
15 answers
946 views

Compute maximum excluding the current position

Given an array of integers A, the task is to output another array B of the same length so that B[i] is the maximum over A for every index that is not i. That is \$B[i] = \max_{i' \ne i} A[i']\$. ...
Simd's user avatar
  • 2,760
-7 votes
1 answer
231 views

Print Goodbye World instead of Hello World

Make a cat program, with a catch. The program must refuse under all circumstances to output "Hello World", instead outputting "Goodbye World", with matching spacing (but matching ...
Devsman's user avatar
  • 137
16 votes
14 answers
3k views

TYPOGLYCEMIA - Cna Yuo Raed Tihs?

What is Typoglycemia? Typoglycemia is a term that refers to the phenomenon where readers are able to understand text even when the letters in the middle of words are jumbled, as long as the first and ...
vengy's user avatar
  • 1,613
18 votes
11 answers
2k views

Is it a valid ARM immediate value?

Exposition In this challenge, I am talking about ARM assembly language. ARM is a 32-bit RISC processor; I'll use instruction set up to architecture v6. To load a constant ("immediate") value ...
anatolyg's user avatar
  • 13.4k
14 votes
13 answers
1k views

Counting rankings

There is a competition with \$n\$ participants in total. Alice is one of the participants. The outcome of the competition is given as a ranking per participant with a possibility of ties; e.g. there ...
Bubbler's user avatar
  • 74.9k
0 votes
0 answers
232 views

How quickly can you type this string?

Given a string consisting of only printable ascii (letters, numbers, symbols, and spaces), how many keystrokes are required minimally to type out this string from scratch? That is, current text is ...
Alan Breadel's user avatar
  • 3,843
16 votes
25 answers
2k views

What and where is the max?

This small challenge derives from my annoyance at discovering that numpy doesn't have a built in function for it. Input An n by m matrix of integers. Output The maximum value in the matrix and the 2d ...
Simd's user avatar
  • 2,760
3 votes
5 answers
354 views

Generate a sequence of \$n\$ consecutive composite numbers

Definitions The common methods to generate consecutive composites are $$\overbrace{(n+1)! + 2, \ (n+1)! + 3, \ \ldots, \ (n+1)! + (n+1)}^{\text{n composites}}$$ $$\overbrace{n!+2,n!+3,...,n!+n}^{\text{...
vengy's user avatar
  • 1,613
1 vote
8 answers
276 views

Alternating Random Series Sum To \$N\$ [closed]

Challenge Given a positive integer \$N \ge 3\$, generate an alternating series of \$N\$ random numbers within the range \$[1, N]\$, such that their sum equals \$N\$. Expressed mathematically as $$N = ...
vengy's user avatar
  • 1,613
-1 votes
8 answers
1k views

Number of cigarettes that can be made from a given number of butts

Assumption A cigarette can be made by combining four cigarette butts. Cigarette butts last infinitely until smoked. Explanation Say you have 31 butts. That means, you can make 7 cigarettes from 28 ...
Siddharth Singh's user avatar
8 votes
3 answers
150 views

3D Hide & Seek Word Puzzle - Seeker edition

Your code-golf challenge is to find all occurences of a word in the 3d matrix. There is no restriction on I/O format. In the samples below, the word is presented, then a blank line, then the 2-...
Sny Smartie's user avatar
-2 votes
1 answer
170 views

Solving Reverse Polish Notation with GolfScript and Eval Function

I am exploring a unique approach to the classic problem of Reverse Polish Notation on code.golf. Unlike the conventional solutions, my focus lies on leveraging the ...
Golfscript-Noob's user avatar
5 votes
4 answers
419 views

3D Hide & Seek Word Puzzle

Challenge Create a 3D word puzzle where the cube's dimensions match the length of the input word. The uppercase word (A-Z) must be validly placed within the cube in one of the fixed orientations: ...
vengy's user avatar
  • 1,613
4 votes
5 answers
588 views

Double-reduce a sequence of integers

Consider a function \$r\$ where $$ r(i,k)= \begin{cases} L_{i+1}-L_i, & \text{if}\ k =0\ \text{ (1st reduction)} \\ r(i,0)-r(\lfloor \log_2{k} \rfloor,k-2^{\lfloor \log_2{k} \rfloor}) & \text{...
enzo's user avatar
  • 1,941
3 votes
1 answer
188 views

Output intervals for the optimal subarrays

Consider an array A of integers of length n. The k-max subarray sum asks us to find up to \$k \leq 3\$ (contiguous) non overlapping subarrays of A with maximum sum. If A is all negative then this ...
Simd's user avatar
  • 2,760
12 votes
20 answers
1k views

Modular Equivalence

Given two numbers \$x,y > 2, x≠y \$ output all integers \$m\$ such that $$ x + y \equiv x \cdot y \pmod m $$ $$ x \cdot y > m > 2 $$ Input Two integers Output A list of integers Test cases <...
pacman256's user avatar
  • 3,310
13 votes
19 answers
1k views

The TAK function (easy mode)

The TAK function is defined as follows for integers \$x\$, \$y\$, \$z\$: $$ t(x, y, z) = \begin{cases} y, & \text{if $x \le y$} \\ t(t(x-1,y,z), t(y-1,z,x), t(z-1,x,y)), & \text{otherwise} \...
Bubbler's user avatar
  • 74.9k
9 votes
7 answers
593 views

Possible moves in Othello/Reversi

Othello/Reversi is a board game in which players take turn placing pieces of a color (dark or light) on the 8x8 board. The possible moves are positions where there are one or more pieces of the ...
Yousername's user avatar
  • 3,930
12 votes
7 answers
1k views

Horsey sightseeing

A knight's tour is a sequence of moves of a knight on a chessboard such that the knight visits every square only once. For those who are not aware of how knights in chess work, knights are capable of ...
totallyhuman's user avatar
  • 16.7k
2 votes
0 answers
246 views

Implement the simplest functional programming language

The goal of this challenge is to compare how well different programming languages support functional programming, by seeing how much code it takes to implement BLC8, the simplest functional ...
John Tromp's user avatar
  • 1,176
7 votes
4 answers
365 views

Busy Letters & Evil CEOs

Imagine you are given an array/string containing \$5\$ letters of the English alphabet, with each letter having any value from A to Z (inclusive). Every day, each letter will perform a job, which can ...
Trivaxy's user avatar
  • 337
9 votes
11 answers
2k views

Solve a squared cryptarithm

Inspired by Greg Martin's "Shiny cryptarithm" puzzle. A cryptarithm is a game consisting of a mathematical equation among unknown numbers, whose digits are represented by letters of the ...
enzo's user avatar
  • 1,941
18 votes
7 answers
1k views

The TAK function

The TAK function is defined as follows for integers \$x\$, \$y\$, \$z\$: $$ t(x, y, z) = \begin{cases} y, & \text{if $x \le y$} \\ t(t(x-1,y,z), t(y-1,z,x), t(z-1,x,y)), & \text{otherwise} \...
Bubbler's user avatar
  • 74.9k
7 votes
3 answers
341 views

Relaxing Romans

The Roman numeral for 499 is usually given as CDXCIX which breaks down as CD + XC + IX = 400 + 90 + 9 where numerals like ...
doubleunary's user avatar
  • 1,388
16 votes
11 answers
1k views

Find the finest building blocks

Given a string \$X\$ we will say two strings, \$a\$ and \$b\$, are building blocks of \$X\$ if \$X\$ can be made by concatenating some \$n\$ \$a\$s with \$m\$ \$b\$s in any order. For example the ...
Wheat Wizard's user avatar
  • 97.6k
13 votes
20 answers
2k views

Complete a Mystery Sequence

Given a sequence of three integers, determine if the sequence is arithmetic (of the form [a, a+d, a+2*d]) or geometric (of the form ...
nyxbird's user avatar
  • 313
9 votes
9 answers
686 views

Validate a codice fiscale

Validate a codice fiscale Every Italian resident/citizen is given a 16-character alphanumeric codice fiscale Challenge The final letter is a check code, which is calculated as follows : Characters of ...
Nicolas Formichella's user avatar
8 votes
1 answer
342 views

Longest Repeating Subarray (With Overlapping)

Earlier I asked about this problem on stackoverflow (link), but now I also want to see the golfiest solutions Problem: Given an array of arbitrary numbers, what is the longest subarray that is ...
user23274861's user avatar
7 votes
10 answers
921 views

Make 1's and 2's composite

Input An integer k composed of 1 and 2, with at least 3 digits and at most 200 digits. ...
Sny Smartie's user avatar
15 votes
19 answers
2k views

Doubleouble Talkalk

Input A non-empty string or list of capital letters k with length between 3 to 5000. Output A value indicating whether k can be ...
Sny Smartie's user avatar
19 votes
25 answers
5k views

First person to ever beat Classic Tetris

Historic Tetris Achievement Blue Scuti became the first ever human to beat the classic game of Tetris on NES. Here's the Tetris Kill Screen Challenge Output the following Tetris ...
vengy's user avatar
  • 1,613
13 votes
14 answers
596 views

Binary Expansion Counting Sequence

I found another sequence not yet in the OEIS The binary expansion sequence is defines as follows, assuming 0 indexing: The even numbers of the sequence are how often 0 has appeared in the binary ...
mousetail's user avatar
  • 12.4k
20 votes
14 answers
1k views

Number of ways to partition n into n = K + ꓘ

In this challenge you are asked to find in how many ways we can express a positive integer n as the sum of two positive integers ...
ZaMoC's user avatar
  • 24.8k
6 votes
3 answers
347 views

Tips for golfing in Uiua

What general tips do you have for golfing in Uiua? I'm looking for ideas that can be applied to code golf problems in general that are specific to Uiua. (e.g. "remove comments" would not be ...
Joao-3's user avatar
  • 1,021
4 votes
25 answers
2k views

Consecutive Composite Numbers

Challenge Generate \$n-1\$ consecutive composite numbers using this prime gap formula $$n!+2,n!+3,...,n!+n$$ Input An integer \$n\$ such that \$3 \leq n \leq 50 \$. Output Sequence of \$n-1\$ ...
vengy's user avatar
  • 1,613
15 votes
7 answers
4k views

How many people are awake?

The following data contains the (approximate) population of each UTC timezone in the world (source): ...
enzo's user avatar
  • 1,941
17 votes
19 answers
1k views

Ellipse Lattice Point Counter

Challenge Determine how many integer lattice points there are in an ellipse $$\frac{x^2}{a^2} + \frac{y^2}{b^2} \leq 1$$ centered at the origin with width \$2a\$ and height \$2b\$ where integers \$a, ...
vengy's user avatar
  • 1,613
5 votes
6 answers
455 views

Aircraft registration numbers

Write a program that takes a United States aircraft registration number and returns a 24-bit ICAO hex code corresponding to that registration and vice-versa. An aircraft registration number always ...
Chris's user avatar
  • 2,009
-6 votes
1 answer
167 views

Where to stand to throw circles over sticks

Consider a horizontal line with vertical lines centered on the x-axis and placed at gaps of \$\sqrt{2}/2\$. For a positive integer \$n \geq 3\$, the first half of the lines have lengths \$0, \sqrt{2},...
Simd's user avatar
  • 2,760
17 votes
19 answers
2k views

Mousetail's Sequence

I define mousetails's sequence as follows: If the nth element of the sequence is q, then n+1 must appear q times in the sequence The sequence is weakly monotonically increasing (eg. no lower number ...
mousetail's user avatar
  • 12.4k

1
2 3 4 5
239