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
21
votes
17answers
1k views

Cat a mouse: ASCII art pointers

The Xerox Alto, originally released in 1973, was the first computer to feature the now-familiar angled mouse pointer. The Alto's bitmapped pointer looked like this (redrawn from Fig. 2 here): Your ...
11
votes
10answers
402 views

Conway's Game of Points!

Rest in peace, John Horton Conway There are a ton of different Game of Life interpreters out there! A ton! Currently for you, getting an interpreter is just a dozen types and a couple of clicks away. ...
15
votes
10answers
1k views

Output the International Phonetic Alphabet

The International Phonetic Alphabet is a system of phonetic notation intended to be able to accurately represent every sound used in spoken language. Unless I'm missing any, which I don't think I am, ...
2
votes
0answers
90 views

Grow in a slow-growing sequence [duplicate]

Background There is an interesting question on MathSE about some conjectures that are disproven by extremely large counter-examples. This delightful answer tells the story of a sequence of numbers ...
27
votes
8answers
2k views

Dice Paths on a Grid

You place a standard die at the origin of a 2D grid that stretches infinitely in every direction. You place the die such that the 1 is facing upwards, the 2 is facing in the negative y direction, and ...
-5
votes
0answers
78 views

The HexLattice Problem [closed]

A centered hexagonal number is a centered figurate number that represents a hexagon with a dot in the center and all other dots surrounding the center dot in a hexagonal lattice. Illustration of ...
15
votes
16answers
1k views

Concatenations of powers and their squares

At time of writing, my reputation is \$16,256\$. As I noted in chat, Oh cool my rep is the concatenation of two powers of 2: 16,256 Or even the concatenation of a power of 2 and its square, which is ...
-6
votes
1answer
71 views

No. Of Factors Does the Number Have [duplicate]

Create a function which takes in a input integer and then returns the number of factors it has, like if you pass 25 then it will return ...
12
votes
15answers
1k views

Plot a centered circle

Intro Given radius \$r\$, draw a circle in the center of the screen. Sandbox. The Challenge Here is a simple challenge. Plot a circle using the formula \$x^2+y^2=r^2\$, or any other formula that will ...
20
votes
22answers
1k views

Find the result of some assignment statements

In this challenge, the goal is to find the values of some variables after a number of assignments are done. An example input: a = 5 b = 4 c = a = b a = 2 b = a ...
8
votes
21answers
640 views

Word Length-Sum Multiples

A port of my other question: Double Prime Words Consider a word/string of n alphanumeric characters with sum of the characters, s...
16
votes
29answers
2k views

The Decryption Function

You must write a program that takes an encrypted string and decrypt it according to specific rules and then print it out. Decryption will occur by performing two operations. Sample Input Argument 1 (...
21
votes
16answers
2k views

Delicate primes

Inspired by Find the largest fragile prime. By removing at least 1 digit from a positive integer, we can get a different non-negative integer. Note that this is different to the ...
13
votes
3answers
764 views

Will all the dominoes fall?

The purpose of this challenge is to figure out whether all the dominoes will fall, given an input string representing a top view of the table. Input format The program can take the input as a single ...
0
votes
0answers
173 views

Fractional iteration of a function [closed]

Problem An iterated function \$f^n(x)\$ is defined as \$f(f(f(...f(x)...)\$ for \$n\$ times. For instance if \$f(x)=2x+2\$, then \$f^2(x)=f(f(x))=4x+6\$. But this definition only works for an integer ...
0
votes
1answer
117 views

The Perfect Polynomial [closed]

The coefficients of a perfect square polynomial can be calculated by the formula \$(ax)^2 + 2abx + b^2\$, where both a and b are integers. The objective of this challenge is to create a program that ...
18
votes
13answers
1k views

sporeball numbers

Background We've studied at least five different types of numbers based on the IDs of different users on this site. Why not study another? My user ID is \$91030_{10}\$. Its binary representation is \$...
14
votes
6answers
521 views

Maximal saturated domino covering of a rectangle

Inspired by this OEIS entry. Background A saturated domino covering is a placement of dominoes over an area such that the dominoes are completely inside the area, the dominoes entirely cover the ...
24
votes
32answers
3k views

I uppercase the source code, you reverse the input!

It's one of these again :D Your task, if you wish to accept it, is to write a program/function (without any uppercase letters) that outputs/returns its string input/argument. The tricky part is that ...
-6
votes
0answers
67 views

Make Git segfault [duplicate]

The title says it all: a command starting with git that, when run in the command shell, causes a segmentation fault (SIGSEGV), before any other output occurs. We ...
27
votes
28answers
2k views

Implement the random Fibonacci sequence

The random Fibonacci sequence is defined as follows: $$ f_n = \begin{cases} f_{n-1}+f_{n-2} \text{ with probability } 1/2 \\ f_{n-1}-f_{n-2} \text{ with probability } 1/2 \\ \end{cases} $$ $$ f_1 = ...
15
votes
15answers
1k views

Dovetail two blocks of bits

Check if two blocks of bits dovetail perfectly. Specifications A block of bits is a fixed sequence of 8 bits just like this for example : 11110101. For simplicity we refer to ...
11
votes
12answers
4k views

Is this a robbery?

Backstory You own a tiny jewellery shop in the suburbs of the city. The suburbs are too much overpopulated, so your shop has a thickness of only one character to fit in the busy streets. Recently, ...
35
votes
12answers
3k views

Store eight bits on a punched card

A little while back, data was frequently stored on punched card. A typical card would have 80 columns of 12 possible 'punch' positions. A plethora of encodings was used, each for their own specific ...
-8
votes
1answer
283 views

Red screen in FIVE bytes or less (msdos)

Your program is supposed to create a full red screen in MSDOS. The source of the binary (.com file) must be 5 bytes or less. No wild assumptions, the binary must work in MsDos, DosBox, and FreeDos ...
19
votes
2answers
1k views

Wait, which tetromino was that?

Background Tetris is a single-player game played on a rectangular grid with tetromino pieces. When you fill one or more lines with tetrominoes, the filled lines are removed, and all blocks above them ...
15
votes
26answers
381 views

\$n\$-perfect numbers

A positive integer \$x\$ is an \$n\$-perfect number if \$\sigma(x) = nx\$, where \$\sigma(x)\$ is the divisor sum function. For example, \$120\$ is a \$3\$-perfect number because its divisors sum to \$...
38
votes
9answers
1k views

Recognise a Digit from a Positional Encoding

Starting an the origin on an infinite grid, you follow a predetermined path going up (U), down (D), left (...
8
votes
26answers
648 views

Lolololololololololololol

Let us take a break from the brain-wrecking questions and answer some of the simpler ones You have recently read something extremely funny, and want to express your laughter to the world! But how can ...
33
votes
8answers
2k views

Connect the Three Kingdoms

You are a medieval overlord tasked with designing a road network between three kingdoms placed on a \$9 \times 9\$ grid. A sample placement of kingdoms might look like this: Non-commercial use of ...
-4
votes
2answers
316 views

Is my Processor 32 or 64 bit?

Not to be confused with Is my OS 32-bit or 64-bit. This one is very simple, tell me whether or not my CPU supports 64-bit instructions. If my CPU supports 32-bit instructions, print '32', if my CPU ...
30
votes
5answers
2k views

Avoid walking into a rectangle

Given a rectangle, a start point, and an end point, find any path from start to finish that avoids the rectangle. Example Suppose you were at \$(1.5, -1.5)\$ and you needed to get to \$(2, 4)\$. ...
21
votes
20answers
2k views

How many of each pill to take to achieve the total daily dose

A drug comes in 5mg, 2.5mg, and 1mg sized pills. The drug is taken once a day. The total daily dose will be only one of the following (all in mg): 1, 2, 3, ... 20, 22.5, 25, 27.5, 30, 32.5, 35, 37.5, ...
18
votes
13answers
2k views

Minimum number of platforms required for a railway station

Challenge Given daily arrival and departure times of every train that reaches a railway station, find the minimum number of platforms required for the railway station so that no train waits. In other ...
16
votes
37answers
1k views

Divisible strings

Task Given a string s, output a truthy value if the ASCII code of each letter is divisible by the length of s, and a falsey ...
19
votes
2answers
587 views

Tiling a staircase with staircases

Background A staircase polyomino is a polyomino made of unit squares whose shape resembles a staircase. More formally, a staircase polyomino of size \$n\$ is defined as follows: A staircase polyomino ...
-1
votes
6answers
81 views

Safe bidirectional array index navigation [closed]

Introduction Arrays are usually used with for-loops or iterators. One different task might be the use as a cheap way to rotate through a set of items, so after reaching the last index, the next item ...
14
votes
20answers
1k views

Double Prime Words

Consider a word/string of length \$n\$, only including the letters A-Z, a-z. A word/string is a double prime word if and only if n is prime and the sum of the letters, s, is also prime, using their ...
20
votes
32answers
3k views

Find the largest banknote

Banknotes in many countries come in denominations of 1,2,5,10,20,50,100,200,500,1000, etc. That is, one of \$ \{ 1,2,5\} \$ times a power of \$10\$. This is OEIS A051109, except we'll extend the ...
18
votes
6answers
2k views

Surround a string with “friendliness pellets”

Input a String and surround it with a rounded rectangle of alternating "friendliness pellets".(0) Sandbox Idea originally from Lyxal. Challenge Given a ...
1
vote
0answers
90 views

Robbers: There's a fault in my vault! [closed]

This is the robbers' thread. The cops' thread is located here. Robber rules Should work for all keys and secrets Should require the same number or fewer guesses as the cop's fault, to prevent brute ...
4
votes
0answers
202 views

Cops: There's a fault in my vault! [closed]

In this game of cops and robbers, each cop will make a vault: a program that stores a secret, and requires a key to unlock. The robbers should find a way to get the vault to reveal its secret without ...
12
votes
13answers
1k views

Diophantine Approximation: find lowest possible denominator to approximate within given precision

Challenge Given a number x and a precision e, find the lowest positive integer q such that <...
21
votes
44answers
4k views

Write a “Hello” interpreter

Background Hello is a language "written" by Anne Veling, which errors if the program does not contain only h, and will print ...
2
votes
6answers
138 views

Tips for golfing in Dotty

What general tips do you have for golfing in Dotty? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Dotty (e.g. "remove comments&...
21
votes
11answers
2k views

Spiralize a Word, Triangularly!

Challenge Given a string of any length, write it as a triangle, spiraling out from the center. For example, abcdefghijklmnop becomes: ...
19
votes
24answers
2k views

Prime Power Switch

Input: A positive integer n=p^q where p and q are prime. Output: Output the result of ...
15
votes
12answers
2k views

Implement the Polygamma function

The Polygamma function of order \$m\$, \$\psi^{(m)}(z)\$, is the \$(m + 1)\$th derivative of the logarithm of the gamma function, which is also the \$m\$th derivative of the digamma function. Your ...
12
votes
4answers
770 views

Tips for golfing in Pip

Pip is an imperative golfing language with infix operators. It also borrows some features from functional and array programming. What general tips do you have for golfing in Pip? I'm looking for ...
14
votes
9answers
702 views

On the Subject of Wire Sequences

This challenge is from a game, Keep Talking And Nobody Explodes. It's hard to say how this mechanism works. The engineering is pretty impressive, but there must have been an easier way to manage nine ...

1
2 3 4 5
199