Questions tagged [code-golf]

Code-golf is a competition to solve a particular problem in the fewest bytes of source code. If you want to score by characters instead of bytes, please state this explicitly in the challenge. If source code length is not the primary scoring criterion, consider using another tag instead.

Filter by
Sorted by
Tagged with
20
votes
10answers
385 views

Phony fractions

Context If a0 and b0 are two decimal numbers, with a and ...
11
votes
6answers
579 views

Visualize a Recursive Acronym

Background Famously, the acronym GNU stands for GNU's Not Unix. 1 It's recursive because, after expanding it once, it still ...
19
votes
20answers
1k views

The most common substring

The purpose of this task is to write a program or function to find the most common substring within a given string, of the specified length. Inputs A string, s, ...
2
votes
5answers
137 views

Shift the digits [closed]

Here, x (supplied as input) and n (the result of your computation) are both positive integers. n * x = n shifted. Find n. Here's an example of shifting: ...
0
votes
0answers
41 views

code-bowlingn't [duplicate]

If you place the suffix n't on any given word, it instantly means the opposite of the intended usage of the word. If you place the word ...
38
votes
18answers
3k views

The Sorting Hat

Context At Hogwarts School of Witchcraft and Wizardry, students are sorted into 4 houses, Gryffindor, Ravenclaw, ...
4
votes
0answers
149 views

Finding Radical Ideals

Sandbox Finding radicals of arbitrary ideals in rings is hard! However, it's a doable task in polynomial rings, since they are Noetherian (all ideals are finitely generated) Background A quick ...
25
votes
18answers
4k views

Egg, sausage, bacon and spam (lovely spam!)

You are given four integers: \$e,s,b\in\{0,1\}\$ and \$S\in \{0,1,2,4\}\$, where \$e,s,b,S\$ stand for egg, sausage, bacon and spam respectively. Your task is to figure out whether the corresponding ...
3
votes
7answers
168 views

String permutations

Print the biggest-size subset of strings in the input that are all permutations of each other. If there are ties, any one will do. If no strings are permutations of each other (for example, only one ...
-2
votes
0answers
59 views

Find the number of edge in a graph [closed]

In graph theory, you can describe a graph using a letter and its number of vertices. For example, the complete graph with 5 vertices is denoted by K5 There are many identifiers for many family of ...
22
votes
6answers
6k views

ASCII Pizza (no pineapple)

I like pizza! Task Given the radius of a pizza and a list of ingredients, create the corresponding ascii pizza! Example size 4 pizza with mozzarella cheese, olives and ham: ...
-6
votes
0answers
74 views

Heuristic pseudo-prime generator [closed]

Your task is to write a program that accepts an input N and outputs an integer p in the range [2,N]. (2 to N inclusive) As the title mentioned, the output p must be a probable pseudo-prime. How I ...
10
votes
21answers
905 views
+50

Sort list by types

Rules You will receive as input a list that contains integers and strings. Your task is to move all of the strings to the end of the list and all of the integers to the beginning of the list. This ...
14
votes
26answers
2k views

Drawing one-liner

CodeDrawing one-liner Teaser Behold this formidable drawing: Can you draw this in a single stroke? Give it a try. Can you do this one, now: Give it a try. How it works These "make this drawing ...
21
votes
17answers
2k views

Answer templating

Context Just look around! Whenever someone posts an answer, the same template is followed over and over again! A first line with the byte count and language name. Then the code. Then the TIO link. ...
11
votes
8answers
1k views

Integer Logarithm

Objective Take \$a \in ℤ_{>1}\$ and \$b \in ℤ_+\$ as inputs. Write a function \$f\$ such that: $$ f(a,b) = \left\{ \begin{array}{ll} \log_ab & \quad \text{if} \space \log_ab \in ℚ ...
20
votes
1answer
503 views

Are They Similar Polygons?

Task Given the x,y coordinates (coordinates are guaranteed to be integers) of the vertices of two simple polygons in clockwise or anti-clockwise order. Output a Truthy value if both the polygons are ...
6
votes
4answers
468 views

Count regex matches

Your task Given a simple regular expression, you have to count how many strings of length n have a match of length n with the ...
17
votes
35answers
2k views

Is it a doubling sequence?

A doubling sequence is an array of numbers where each subsequent number is at least twice the previous number. Given an ordered list of numbers, determine if the numbers in the list (\$n_{x}\$) have ...
36
votes
37answers
7k views

Is this a triangle?

Task Write a function/program that, given three positive integers a, b and c, prints a ...
7
votes
13answers
157 views

Computational Parity Party! [duplicate]

The computational parity of an integer is defined as 1 if the integer has an odd number of set bits, and 0 otherwise. (src). Input You will receive one nonnegative integer that you will take the ...
20
votes
39answers
2k views

Reversed Iota's

I didn't invent this challenge, but I find it very interesting to solve. For every input number, e.g.: 4 Generate a range from 1 to that number: ...
14
votes
12answers
210 views

Combinations of stepwise increasing integers

Working on something in probability theory, I stumbled across another combinatorical exercise. These are always fun to solve, searching for intelligent approaches. Of course, one can use brute force ...
23
votes
7answers
2k views

10-pin bowling split spare

Bowling Bowling is a game where, essentially, each player gets 10 turns to: Take 2 attempts at knocking down 10 pins arranged in a triangle. between turns the pins are reset from the 1st to the 2nd ...
1
vote
0answers
50 views

Shortest Sorting algorithm [duplicate]

So, you need to create the shortest sorting algorithm with a resonably fast run time. It could be any sorting algorithm. Test code: ...
34
votes
36answers
4k views

Lonely Multiplication

Based on this question from Code Review. Given precisely three positive integers, return the product of all of the distinct inputs. If none of the inputs are distinct, return 1. That is, implement ...
1
vote
1answer
101 views

Self-loathing program/function [duplicate]

Simple task, write a program/function that returns error if and only if presented with itself. The program must give a valid output for any input other than itself. For the error part, you can only ...
0
votes
0answers
94 views

Let's learn a bit French: 99 Bottles [duplicate]

The 99 bottles in French The lyrics of the song goes like this: ...
1
vote
1answer
127 views

Name an arbitrary string [closed]

This should be easy: given an arbitrary string, your program will give it a name. Requirements Your program will accept an input of a UTF8 string, and output a string representing the input's "name",...
9
votes
5answers
177 views

Count switches in a smallest square root sequence mod \$2^n\$

Definition For any \$a\equiv1\ (\text{mod }8)\$ and \$n\ge3\$, there are exactly 4 roots to the equation \$x^2\equiv a\ (\text{mod }2^n)\$. Now, let \$x_k(a)\$ be the smallest root to the equation \$...
9
votes
1answer
174 views

Count the Shantens

Introduction to Mahjong tiles Mahjong (麻雀) is a board game that originates from China. Mahjong tiles used in this challenge are in Unicode points U+1F000 – U+1F021: ...
30
votes
27answers
5k views

How far should I sum?

How far should I sum? The harmonic series is the "infinite sum" of all the fractions of the form \$\frac1n\$ for \$n\$ positive integer. I.e. the harmonic series is $$\frac11 + \frac12 + \frac13 + \...
21
votes
24answers
2k views

Can I join the music box?

The magic music box (MMB) This explains the motivation for the challenge, feel free to ignore. The magic music box is a word game played by a group of people, where one is the owner of the magic ...
1
vote
5answers
346 views

Write some Random English

Your Goal: Given an odd integer input n greater than 1, generate a random English word of length n. An English word is one in ...
3
votes
5answers
254 views

Implement a Caesar Cipher with a Digit Shift

I assume everyone here is familiar with the Caesar Cipher that shifts letters to a certain index. https://en.wikipedia.org/wiki/Caesar_cipher for those who still needs introduction. But, we can all ...
1
vote
0answers
124 views

What does the shortest pseudo-random algorithm look like? [closed]

After seeing some impossibly short solutions in this SE, I began to wonder what code someone could come up with to build a pseudo-random number generator. Now given that I am new to programming, I ...
27
votes
12answers
3k views

Compress 8 bits to 6 when certain bit patterns will never occur

Consider an eight bit number in which an even position bit will never be 1 if one of its neighbors is 0 (considering MSB and LSB as neighbors). There are fewer than 64 such numbers, so there is at ...
21
votes
35answers
2k views

Give me Triangles [duplicate]

Given an integer n>0, write a program that will output an "isosceles" Triangle out of #'s of height n. Examples: ...
22
votes
22answers
1k views

Mountain range numbers

Mountain range number A number is a mountain range number if the inequalities satisfied by their consecutive digits alternate. In a way, looking at the number's digits should exhibit a ...
27
votes
25answers
2k views

The Magical Piper

An old test for programmers, taken from here (Note: in italian). Along a road (denoted by '_'), there is a Magical Piper (denoted by '...
29
votes
19answers
4k views

Print this maximally long URL

Task This one is simple. We want to compress a URL, but don't trust URL shorteners. Write a program that prints to stdout (or a 0-argument function that returns) the following, working URL: http://...
4
votes
3answers
177 views

Shortest POSIX command line that eagerly removes dual newline sequences

Example: echo -ne 'a\n\nb\nc\n\n\n\nd\n\n\n' | your-command should output the same as echo -ne 'ab\ncd\n' Watch out, some ...
11
votes
3answers
1k views

Intersection of circles – How can I reduce this golf code to 127 bytes?

I started a CodeWars kata in Python, just two days ago, related to code golf. Task: Given two congruent circles a and b of radius r, return the area of their intersection rounded down to the nearest ...
15
votes
12answers
1k views

It's all about the sum of the digits

The sequence Given an integer \$n>0\$, we define \$a(n)\$ as the lowest positive integer such that there exists exactly \$n\$ positive integers smaller than \$a(n)\$ whose sum of digits is equal ...
21
votes
17answers
2k views

Concentric rings on a snub square tiling

This challenge takes place on the snub square tiling. Start by choosing any triangle, and color it \$c_1\$. Next, find all tiles which touch this triangle at any vertex, and color them \$c_2\$. Next,...
26
votes
7answers
1k views

Roll a cube to a target position

You have your very heavy cubical box on a flat floor at position (0,0). All you can do with it is roll it in four cardinal directions (east, north, west, south). Your task is to bring it to a target ...
27
votes
24answers
4k views

Calculate the Progressive Mean™

Disclaimer: This challenge is inspired by a coding error I once made. Okay, time for a maths lesson. A normal mean average looks like this: ...
14
votes
15answers
1k views

Find the Inverse Neighbor Pairs

Definition We say a pair of integers \$(a,b)\$, where \$0<a<b<N\$ and \$N\$ is an integer larger than 4, is an inverse neighbor pair respect to \$N\$ if \$ab\equiv1\text{ }(\text{mod }N)\$ ...
18
votes
13answers
1k views

Number of palindrome splits

In this task you will take as input a non-negative integer \$n\$, and output the number of pairs of non-negative integers \$a,b\$ such that both are palindromes*, \$a \leq b\$, and \$a+b = n\$. For ...
20
votes
24answers
2k views

Power-Ending Patterns

When you look at the last decimal digit of each power of a non-negative integer a repeating pattern forms. For example, 3: ...

1 2 3 4 5 190