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
5
votes
1answer
45 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: ...
-4
votes
0answers
59 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 ...
6
votes
15answers
472 views

Sort list by types

Rules You have a list (L) that contains integers and strings. Your task is to move all strings to the end of the list and all integers to the beginning of the list. It is a code-golf so the lowerest ...
10
votes
23answers
811 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 ...
0
votes
0answers
69 views

Interpret CJS inside of Javascript. Raw Strings [closed]

Background: Javascript has a built in function. Eval. The Evil Eval. We know its issues, and we know its one and a very rare while uses. I wanted to see someone emulate CJS in JS, which is a made up ...
19
votes
17answers
1k 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. ...
10
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 ℚ ...
19
votes
1answer
482 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 ...
5
votes
4answers
448 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 ...
16
votes
32answers
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 ...
6
votes
13answers
152 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 ...
19
votes
38answers
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
199 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 ...
22
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
49 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: ...
33
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
92 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
126 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
175 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
171 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 + \...
-4
votes
0answers
40 views

A task with some matches [closed]

members) I got some task with 5 matches you must move 2 of them to make figure More details in the file https://www.sendspace.com/file/2zwnon
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
340 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
252 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
123 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
174 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,...
25
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: ...
15
votes
25answers
1k views

pleTriwapt Sgpin (Triplet Swapping)

Intro/Background I was looking at a Flybuys card at Coles recently and noticed that if I took something like this: Source, randomly found on the Internet And swapped some words around, I'd get ...
14
votes
1answer
282 views

Solve a meta-knowledge puzzle

Alice and Bob are perfect logicians trapped on an island with a puzzle generator. Although they can instantly solve the Riemann hypothesis and P=NP just by thinking about it, rather than doing ...
13
votes
12answers
588 views

Computing a specific coefficient in a product of polynomials

Generator functions This gives the context for why this challenge came to life. Feel free to ignore. Generator functions are a nice way of encoding the solution to a problem of combinatorics. You ...
17
votes
12answers
807 views

Walk home one step at a time

You're at integer coordinates \$(x,y)\$ facing one of North, South, East, or West. Your goal is to walk home to \$(0,0)\$. At each step, you may do one of: Walk one step in the current facing ...
25
votes
54answers
3k views

Repeat every other character in string starting with second character

Requirements: Take a single word as input with only lowercase alphabetical characters (a-z) Output a string where every other character is repeated, with the first repeated character being the second ...
5
votes
3answers
233 views

Choose 3 strings and output the exact minimum Hamming distance between any pair

Consider \$3\$ binary strings of length \$n\$ chosen independently and uniformly at random. We are interested in computing the exact expected minimum Hamming distance between any pair. The Hamming ...
33
votes
12answers
3k views

How many countries are in the European Union?

Tonight, 31 January 2020, Brexit will happen and the United Kingdom will leave the European Union, the first time that the number of EU member states will decrease. Your job is to take a date and ...
11
votes
1answer
301 views

Write a Whitespace Interpreter

Challenge: Your challenge is to write an interpreter for Whitespace. Given a string consisting of spaces, tabs, newlines, and potential other characters, as well as possible inputs for the Whitespace ...

1 2 3 4 5 189