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
6
votes
7answers
180 views

Convert Planck unit to SI metric

Objective Given a dimension of an SI unit, convert the Lorentz-Heaviside version of a Planck unit \$1\$ into SI metric. What is a Planck unit? Planck units are a set of units of measurement. It ...
13
votes
6answers
525 views

God is real . . . unless declared integer

This challenge is inspired by Fortran's idiosyncratic implicit typing rules. Your task will be to determine the data type of the object GOD according to the ...
9
votes
13answers
622 views

Pseudo-deterministic number generator

Task Write a function/full program that will be able to produce two different sequences of integers in [0, ..., 9]. You will take an input ...
24
votes
5answers
4k views

Draw an ASCII oak tree (or a woman with curly hair?)

Task Your task is to draw these beautiful oak trees: ...
22
votes
17answers
2k views

Cook me a character meal

Chef Avillez is about to cook us some really nice meal. He is just waiting for us to give him some ingredients and to request a meal. Task Given a list of ingredients (strings matching ...
14
votes
4answers
808 views

Reconstruct a 3d arrangement of cubes from two of its projections

Setup Take the following 4x4x4 cube along with a 2D view of 3 of its faces, with a common 1x1x1 cube highlighted: The arrows ...
10
votes
10answers
657 views

Find how many ordered pairs of integers share only one digit

Task Your task is to make the smallest function/program that can, when gives an number N, return/print: the number of possible choices a, b such that \$1 \leq a &...
23
votes
21answers
2k views

Four distinct 8-bit integers

Submit a well-formed program or function with usual I/O rules which satisfy the input, output, and algorithm conditions below. Shortest submission (in bytes) wins. As always, standard loopholes are ...
17
votes
20answers
2k views

Pendulum Encoding

Given a string as an input (which can be any acceptable/convenient format in your language), implement pendulum encoding. The test cases are split into individual items (which aren't quoted) for a ...
12
votes
9answers
492 views

Simulate D Flip-Flop

Objective Simulate an edge-triggered D Flip-Flop. What is D Flip-Flop? A D flip-flop is an electronic digital device that outputs an inputted data (abbr. D) with synchronization to a clock (abbr. ...
1
vote
25answers
485 views

Add N numbers without using + or -

Given N integers, output the sum of those integers. Input You may take the integers in any reasonable format, including: stdin arguments an array or list Rules ...
-4
votes
0answers
72 views

wasting n-dimensional peanut butter

I was scraping the last peanut butter out of the jar during the Covid19 pandemic, and wondering how much of the good stuff was left down inside the jar, inaccessible but for the most desperate ...
20
votes
32answers
2k views

Vowels up, consonants down

Challenge You will be given a string that can contain lowercase letters, uppercase letters, or spaces. You have to turn the vowels (a, e, i, o, u) in the string to upper case and consonants to lower ...
9
votes
4answers
242 views

Counting valid Binary Sudoku boards

Sequel of Counting valid Binary Sudoku rows. Background Binary Sudoku, also known as Takuzu, Binario, and Tic-Tac-Logic, is a puzzle where the objective is to fill a rectangular grid with two ...
12
votes
4answers
375 views

Solving the water bucket riddle!

Context The water buckets riddle or the water jugs riddle is a simple riddle that can be enunciated in a rather general form as: Given \$n > 0\$ positive integers \$a_1, a_2, \cdots, a_n\$ ...
11
votes
26answers
1k views

Filter an array so that duplicate items are removed

In the shortest amount of code in any programming language, filter out the duplicate items in an array of which the order is irrelevant. Here are some test cases: ...
15
votes
10answers
1k views

Shortest total non-primitive recursive function

Natural numbers ≡ \$\mathbb{N}≡\{0,1,2,...\}\$ The submission can be either a program or a function, both cases will henceforth be referred to as "function". The task is to golf the shortest ...
26
votes
26answers
2k views

Measure the lengths of binary patterns

Let's consider the sequence of the binary representation of positive integers (without any leading zero): ...
21
votes
19answers
4k views

Even a clock that isn't working gets the time right two or three times a day

Context When I was a little kid, I watched a Disney movie where Goofy told his son "Boy, even a broken clock is right two or three times a day." (see this youtube clip, courtesy of @Arnauld). ...
4
votes
2answers
75 views

Tips for golfing in Pure Data

Pure data is a graphical programming language designed for audio processing. This makes it unsuitable for most general programming but especially unsuitable for code-golf. It would then be nice to ...
15
votes
12answers
1k views

Day of the week of an ambiguous date

Goal Write a program or function that returns the day of the week for a date, eg. 01/06/2020 -> Mon However, it's unknown if the date is in the format mm/...
40
votes
28answers
4k views

Name your novel disease

Introduction The current coronavirus disease is officially named COVID-19, from the 3 words corona virus disease, and the year 2019. (Technically it's coronavirus, making 2 words, but whatever...) ...
12
votes
5answers
270 views

Return a word with a prescribed sum of letters

Identify each letter of the English alphabet with the number denoting its position in the alphabet, that is, a = 1, b = 2, c = 3, ..., z = 26 (no distinction ...
18
votes
22answers
2k views

A bit of a digital XOR

Here are the first 100 numbers of a sequence: ...
17
votes
4answers
424 views

What can you see on a hexagonal spiral?

This code-golf challenge will have you computing OEIS sequence A300154. Consider a spiral on an infinite hexagonal grid. a(n) is the number of cells in the part of the spiral from 1st to n-th cell ...
24
votes
23answers
3k views

Ah, why is there a bug in my program?

This challenge is inspired by @LuisMendo's MATL answer to my "binary multiples" challenge. Task Pick a code-golf challenge that is open and that has been posted before this one; let me call it the "...
23
votes
55answers
2k views

Numbers by Position

Numbers by Position Challenge Print the numbers: 1 22 333 4444 55555 666666 7777777 88888888 999999999 In that order. I/O Takes no input. The numbers can ...
13
votes
20answers
674 views

Quotes around sequence of chars

Challenge Your goal is to write a function that puts quotes around a sequence of capital letters in a string. So some examples (everything on the left (before function) and right (after function) ...
-2
votes
7answers
178 views

Generate this expanding series [closed]

Challenge Your task is to generate a string using this sequence: 1,1,2,1,1,2,3,2,1,1,3,2,4,2,3,1,.... Which is more understandable in this format: ...
19
votes
13answers
1k views

Counting valid Binary Sudoku rows

Background Binary Sudoku, also known as Takuzu, Binario, and Tic-Tac-Logic, is a puzzle where the objective is to fill a rectangular grid with two symbols (0s and 1s for this challenge) under the ...
17
votes
20answers
2k views

All aboard the factorial train

The system Assume the Earth is flat and that it extends infinitely in all directions. Now assume we have one infinitely long train railway and n trains in that ...
3
votes
5answers
72 views

Find the binary period [duplicate]

We know that not all fractions have a terminating binary representation. However every fraction can be written as a leading portion followed by a repeating portion. For example \$1/3\$ starts with \$...
10
votes
1answer
138 views

Counting polyominoes on (hyper-)cubes

This challenge like some of my previous challenges will have you counting free polyforms, which are generalizations of Tetris pieces. This code-golf challenge will have you count polyomino-like ...
16
votes
13answers
1k views

Appearing a unique number of times

Your task is to write a program or function that takes as input a list of positive integers and determines if there are any two integers in the list, that both appear the same number of times. For ...
15
votes
25answers
2k views

Ones and Twos for days

Inspiring myself on a recent challenge, we ought to compute a sequence that is very close to A160242. Task Your task is to generate the sequence \$ \{s_i\}_{i=0}^\infty \$: ...
13
votes
9answers
517 views

Smaller Strings in Printable ASCII base

Task Given a input string s which contains only printable ascii characters output all strings which contain only printable ascii characters and are strictly ...
11
votes
16answers
871 views

Progressing Two's

Given an positive integer n (including 0 if you decide to support it), output all numbers in the generated sequence up to the index ...
24
votes
20answers
2k views

How many balloons do I need in each corner?

You have a square board with a bunch of items laid out on it in one of a \$3 \times 3\$ grid of cells and you want to lift it up using balloons, but you can only attach balloons to the corners of the ...
16
votes
10answers
2k views

An unknowably odd function

This challenge initially appeared in this challenge as a an extra brain teaser. I am posting it with permission from the original author so that we can have a formal competition. Your task here ...
2
votes
15answers
530 views

Convert a decimal integer to binary only using arithmetic operators

There are 10 types of people in the world, those who understand binary and those who do not. Where are you? Let's see! Challenge Your task is to convert a decimal integer to binary, only using a ...
18
votes
15answers
1k views
+200

(RGS 5/5) Computing the set of all set partitions with fixed sizes

Task Given a set of n unique elements and a multiset l of positive numbers that add up to n,...
25
votes
13answers
4k views

This highway needs rain across both of its lanes

In this challenge you will take a an ascii art image of a highway like so ...
5
votes
5answers
416 views

Special Character Coding Challenge - Check string for validity (Lots of rules) [closed]

There are 5 different "special characters": % & # $ ! These special characters are in a string with numbers. Like so: "5 ! 60%2$5.3" (valid). You must determine the validity of the string and ...
7
votes
6answers
315 views

Japanese Encoding Conversion

Background In JIS X 0208 a 94 by 94 map (kuten (区点)) is defined to encode Chinese characters (kanji), phonetic moras (kana) and other symbols. Along with this standard there are 3 different encodings ...
36
votes
15answers
3k views

Error-correct text

Correct a single-letter typo in a fixed text. Input: The paragraph below but with exactly one typo, where a single letter a-zA-Z is replaced by a different letter <...
14
votes
23answers
2k views

The SBEVE Challenge

She said s(he) be(lie)ve(d), he said sbeve. Input A non-empty string, s. It's guaranteed that s will have only printable ASCII ...
-4
votes
13answers
288 views

Convert a string to upper case without using built in methods/functions [closed]

Challenge You will be given a string as an argument. You need to convert that string to upper case. But you can't use any built in method or function nor any external programs. Rule No use of ...
18
votes
21answers
4k views

Print a list of iPhones

Write the shortest program that prints, in order, a complete list of iPhone iterations, according to this site: ...
25
votes
9answers
733 views

Mad Libs number sequences

My robot for generating Mad Libs-style sequence challenges has gone rogue! To defeat it, I need you to write code that can solve all the challenges it can crank out. Your input is three selections ...
1
vote
1answer
154 views

Summing intertwined terms of an array

I'm recieving 2-dimensional positions of two objects as a string with this format: x1,y1,x2,y2. The string is recieved from a ...

1
2 3 4 5
191