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
9
votes
11answers
186 views

Make an ASCII table

We're getting markdown tables! I assume this is what they look like: ...
18
votes
10answers
376 views

Operational countdown

Given a non negative integer number \$n\$ output how many steps to reach zero using radicals, divisions or subtractions. The algorithm Get digits count ( \$d\$ ) of \$n\$. Try the following ...
-3
votes
2answers
111 views

Rocket Liftoff! [closed]

This code golf challenge is about making a rocket liftoff sequence. Your output should be similar to this: ...
19
votes
24answers
1k views

Perfect radicals

Given a positive integer number \$n\$ output its perfect radical. Definition A perfect radical \$r\$ of a positive integer \$n\$ is the lowest integer root of \$n\$ of any index \$i\$: $$r = \sqrt[i]{...
25
votes
17answers
2k views

Convert negadecimal to decimal (and back)

Negadecimal, also known as base -10, is a non-standard positional numeral system. Take the number \$1337_{10}\$. In decimal, this has the value one thousand three hundred thirty seven, and can be ...
28
votes
49answers
3k views

Infinitely many ℕ

Background: A sequence of infinite naturals is a sequence that contains every natural number infinitely many times. To clarify, every number must be printed multiple times! The Challenge: Output a ...
1
vote
12answers
483 views

just a caesar cypher… with a twist [closed]

I have been going to puzzling.se, and people over there write stuff in rot13 a lot, sot this gave me an idea: Write a program that takes 2 inputs, a string and integer: the message to encode or ...
67
votes
21answers
11k views

“Hello, World!” in zero lines of code

NPM's sloc is a moderately popular tool for counting source lines of code in a file. The tool will attempt to strip out both single and multiline comments and count the remaining lines in order to get ...
28
votes
48answers
3k views

Multiply or Divide by n

Here's a simple challenge, so hopefully lots of languages will be able to participate. Given a positive integer \$n\$, output \$A076039(n)\$ from the OEIS. That is, start with \$a(1)=1\$. Then for \$n&...
11
votes
3answers
623 views

How to golf evaluation of math expression in MySQL?

The challenge given to me is comparatively easy, and specific to MySQL only. I'm given a table expressions which have mathematical calculations done by a kid. ...
28
votes
17answers
2k views

Gluttonous Colluding Numbers

Here's an easy one, with just enough complexity to make golfing non-trivial. Input A list of non-negative numbers representing people waiting in line for Thanksgiving dessert. The first (leftmost) ...
16
votes
20answers
2k views

Find distance between the closest 3D points

Your task is to take \$n \ge 2\$ points in 3D space, represented as 3 floating point values, and output the Euclidean distance between the two closest points. For example $$A = (0, 0, 0) \\ B = (1, 1, ...
21
votes
19answers
973 views

Compatible strings

When studying numerology, you can say two words (strings consisting entirely of letters) are compatible if they produce the same number under the following operation (let's use the string ...
36
votes
15answers
3k views

NATO phonetic spelling can take long

NATO phonetic alphabet is a spelling alphabet that associate to each of the 26 letters of the English alphabet one word (table below) that is easy to understand over the radio or telephone. For ...
1
vote
0answers
102 views

Printing Hello World using fewest characters [duplicate]

I saw a problem which asks you to print "Hello World" using the fewest characters, including spaces. How can I further shorten this code? Thank you in advance! ...
16
votes
14answers
1k views

Centerless Polygons

A centered polygonal number is a positive integer given by the number of vertices when a point is surrounded by (increasingly larger) polygons with the same number of sides, as shown below. For ...
19
votes
13answers
2k views

NESCA: New English Stroke Count Alphabet

TLDR: Sort your input according to a new English alphabet somewhat based on Chinese stroke count methods. Background: In a Chinese glossary/index, finding terms that are contained within the book is ...
13
votes
5answers
734 views

Write a Unicode Unpacker

We all know scoring by characters is ripe for abuse. Let's prove this. The Challenge Output the following: ...
16
votes
13answers
1k views

All-inclusive semi-primes

\$723 = 3 \times 241\$ is a semi-prime (the product of two primes) whose prime factors include all digits from \$1\$ to \$n\$, where \$n\$ is the total number of digits between them. Another way to ...
2
votes
0answers
99 views

Dobble Double Challenge [closed]

I have a problem, which I haven't found a solution for. Solutions to the first part are well documented, but I have yet to find anyone who has solved the second part. I call this the "Dobble"...
7
votes
1answer
279 views

How to golf wrap-around assignments?

This is a relatively simple question. I'm trying to golf a Snake game I've written, and I'm trying to work out if there's a way to golf the following conditional assignments which control x and y ...
18
votes
17answers
491 views

Align a list of numbers [duplicate]

Perhaps something like this is here already, but I couldn't find it. It is not the same as Aligning Lines!. Example: Input: 98.6 $2,750.17 -$23 -86 3,120,487.19 ...
19
votes
32answers
2k views

Make a minimal and maximal 2-digit number from digits of two 3-digit numbers

Let's solve this user's homework; I think it's an interesting exercise! Input Two 3-digit natural numbers. Outputs Two 2-digit numbers. In each of the output numbers, one digit is taken from one input ...
24
votes
7answers
2k views

Are these states connected?

With the US election going on right now, I noticed that there is one (completely meaningless, but still) thing which Trump can still achieve and which is out of reach for Biden: Having the won states ...
17
votes
5answers
2k views

Convert Magic the Gathering colours to a Colour based deck name

Magic the gathering has many unique names for colour combinations in decks, as an example when Blue and White appear together in a deck, the deck maye sometimes be named after the Ravnican Guild that ...
1
vote
1answer
331 views

Hacker Challenge: Guess the Correct Password

In an attempt to “liberate” their fellow birds, a group of highly intelligent hens are attempting to compromise the zoo’s security system. To get access to the zoo’s mainframe, the hens first need to ...
13
votes
5answers
560 views

Wuxings in Positive Action

Background Wuxings(五行) are the five "elements" in Chinese philosophy. They are Fire(火), Water(水), Wood(木), Metal(金), and Soil(土). You can find them on East Asian calendar, where some days (...
33
votes
22answers
3k views

Narcissistic loop lengths

A narcissistic number is a natural number which is equal to the sum of its digits when each digit is taken to the power of the number digits. For example \$8208 = 8^4 + 2^4 + 0^4 + 8^4\$, so is ...
22
votes
15answers
1k views

Convert height to US Men’s Jacket size

In the US, clothing size sometimes has rough designations like M, L, XXL, etc. The US designation of the "men's jacket" category depends on the height of the person. So, in this challenge, ...
23
votes
36answers
1k views

Display the exponent from a binary floating point number as a decimal value

Had my software final exams recently, one of the last questions had me thinking for a while after the exam had finished. Background IEEE754 numbers are according to the below layout The exponent is ...
-7
votes
4answers
191 views

Generate a RecursionError [closed]

Write the shortest possible code cause an error due to recursion too deep Example error in python RecursionError: maximum recursion depth exceeded Example error in ...
18
votes
26answers
3k views

Is It A Rainbow Color?

Challenge: The challenge is to determine whether or not a color, given it's name, is one of the colors in the rainbow. When supplied with a color, your program should output a truthy value if it is a ...
10
votes
1answer
321 views

Total resistance from unit resistors

This problem is based on, A337517, the most recent OEIS sequence with the keyword "nice". \$a(n)\$ is the number of distinct resistances that can be produced from a circuit with exactly \$n\...
11
votes
13answers
816 views

Prefix divisibility

Inspiration Given a positive integer \$1 \le n \le 9\$, output all positive \$n\$-digit integers \$i\$ for which the following is true: Each digit from \$1\$ to \$n\$ appears exactly once in \$i\$. ...
25
votes
29answers
2k views

Not so triangular numbers

Let's consider the sequence \$S\$ consisting of one \$1\$ and one \$0\$, followed by two \$1\$'s and two \$0\$'s, and so on: $$1,0,1,1,0,0,1,1,1,0,0,0,1,1,1,1,0,0,0,0,...$$ (This is A118175: Binary ...
-1
votes
1answer
176 views

Square root of a base 10 positive integer, digit by digit [closed]

It is possible (Wikipedia reference) to compute the square root of any number in a digit by digit fashion using a simple (I had learned it in primary school) algorithm. Challenge: read a positive ...
6
votes
8answers
831 views

Bi-directional translator

Bi-directional translator The challenge is to create a translator that can translate a [a-zA-Z ] string into another string according to the mappings below. The ...
16
votes
18answers
3k views

Calculate COVID spread

Because the coronavirus is still at large, I thought it would be fitting to have a epidemic-themed challenge. Challenge You are given a 2D array of people, where 1 ...
18
votes
19answers
1k views

The Fibonacci Rectangular Prism Sequence

What is the Fibonacci Rectangular Prism Sequence? The Fibonacci Rectangular Prism Sequence is a sequence derived from the Fibonacci sequence starting with one. The first 3 numbers of the Fibonacci ...
6
votes
3answers
552 views

Day of Week - Natural language processing and date parsing

You'll get a human-readable question matching one of the following syntaxes, and are expected to print/return the corresponding result. Finding similarities between the human-readable inputs and ...
-1
votes
1answer
214 views

Ping-pong bot for StackExchange

History There's a room on StackOverflow in Russian where you can see such an interesting discussion: Just because there are not enough real discussing in that room, @Grundy "plays ping-pong"...
27
votes
17answers
3k views

Which side should I serve on?

Introduction In Tennis, the server alternates serving on the left side or the right side of the court every point, starting on the right. It is possible to figure out which side to serve on for that ...
12
votes
9answers
2k views

Naïve compression

using Prefixed Length Code We are going to implement a compression of text (string, array/list of characters/bytes) by simple substitution of each character by a binary code, based on the frequency of ...
17
votes
4answers
1k views

Simulate my keyboard wave light!

(The word frame in the following text does not mean an actual frame, it is used as a placeholder for an undefined time unit) The task Imagine you have a keyboard layout with only letters like so: <...
9
votes
0answers
156 views

Distance between point and line segment [closed]

Given a point and a line segment in the plane, output the Euclidian distance between them, that is the distance between the given point and the nearest point on the line segment. Because the line is ...
14
votes
14answers
451 views

Repetend length in 1/n

This problem is based on non-terminating, repeating decimal points. Let \$n\$ be any positive integer \$(n > 1 \text{ and } n < 10000)\$, say \$7\$. Then, \$1/n = 1/7 = 0.142857142857142857...\$ ...
8
votes
14answers
356 views

Golf a bijection \$\mathbb{N}^n\to\mathbb{N}\$

Your task is to write a program which implements a bijection \$\mathbb{N}^n\to\mathbb{N}\$ for \$n \ge 1\$. Your program should take \$n\$ natural numbers as input, in any acceptable method (including ...
-1
votes
16answers
484 views

Implement Smokey's !!/coffee command. (Part 2)

Like the previous SmokeDetector challenge? This one is for you too ;) Note: SmokeDetector is a bot that detects spam and offensive posts on the network and posts alerts to chat. What to implement ...
13
votes
6answers
444 views

Can I print my picture on {A,B,C}{0-10} paper?

The task is to find the smallest paper size on which it is possible to print a picture of the dimensions given in milimetres. The image will be printed without margins. Input: Two integers (bigger ...
16
votes
15answers
2k views

Implement Smokey's !!/alive command

Note: SmokeDetector is a bot that detects spam and offensive posts on the network and posts alerts to chat. What to implement Smokey's !!/alive command uniformly ...

1
2 3 4 5
201