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
16
votes
7answers
208 views

AoCG2021 Day 4: Infinite Elves and infinite houses 2

Part of Advent of Code Golf 2021 event. See the linked meta post for details. Related to AoC2015 Day 20, Part 1. Here's why I'm posting instead of Bubbler and why not emanresuA To keep the Elves busy,...
16
votes
23answers
847 views

AoCG2021 Day 3: Say-Look-Say

Part of Advent of Code Golf 2021 event. See the linked meta post for details. Related to AoC2015 Day 10. Here's why I'm posting and not Bubbler The Elves are playing a variation of the game called ...
12
votes
7answers
640 views

Are these the basis vectors?

A basis of a vector space \$V\$ is a set of vectors \$B\$ such that every vector \$\vec v \in V\$ can be uniquely written as a linear combination of the vectors in \$B\$. In other words, let \$B = \{\...
12
votes
20answers
2k views

Total cost of The 12 Days of Christmas

Introduction I have decided that this Christmas, as a "present" to a friend, I wish to purchase the things described in the classic song "The 12 Days of Christmas". The only ...
22
votes
27answers
2k views

AoCG2021 Day 2: Naughty or nice?

Part of Advent of Code Golf 2021 event. See the linked meta post for details. The story continues from AoC2015 Day 5, Part 2. Santa needs help figuring out which strings in his text file are naughty ...
20
votes
34answers
2k views

Randomly capitalize half of a string

Given string s of even length as input, randomly capitalize exactly half of the letters. You can assume the input will always be a non-zero, even length You can ...
3
votes
3answers
379 views

How to shorten the Python code? Part II

Code Python 3, 245 bytes ...
6
votes
2answers
185 views

Temporally Dither an Image (Image to PWM Image)

Background I want to display rich, vibrant images on my theoretical fancy custom display, but due to budget constraints, it displays everything in 3-bit colour! Whilst Regular Dithering would work, I ...
5
votes
1answer
98 views

Tips for golfing in BQN

What general tips do you have for golfing in BQN? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to BQN (e.g. "remove comments"...
7
votes
4answers
2k views

How to shorten the python code?

I'm writing a program that takes a number from input (call it x), loops from 0 to (x - 1) (let's call our iterator y) and prints \$y^x+x\$ for each y. After the loop, it then prints "SUM: N" ...
22
votes
17answers
2k views

AoCG2021 Day 1: Automated delivery frenzy

Originally from caird coinheringaahing's idea, I (Bubbler) am hosting Advent of Code Golf 2021. On each day from today (Dec 1) until Christmas (Dec 25), a challenge will be posted at UTC midnight, ...
15
votes
1answer
313 views

How to solve the LCM in 50 bytes of Python

I've recently stumbled upon a Russian site called acmp.ru, in which one of the tasks, HOK, asks us to find the LCM of two positive integers. The full statement, translated to English is as follows: ...
13
votes
8answers
2k views

All distances different on a chessboard

Inspired by this Puzzling SE question: All distances different on a chess board. Introduction Lets define a sequence \$a(n), n\geqslant 1\$ as how many pawns can you put on a \$n \times n\$ chessboard ...
3
votes
0answers
112 views

Print random characters indefinitely [duplicate]

Task Continuously print a random character (a-z, A-Z, 0-9) not separated by a newline (\n). Expected output ...
-1
votes
2answers
105 views

Challenge: create a large number using an esoteric programming language [duplicate]

I enjoy large numbers and esoteric programming language, so I decided to combine them into a programming challenge. Your goal is to push the limits of esoteric languages like BF or Pyth and return the ...
0
votes
0answers
113 views

SQL Christmas Code Golf Challenge: PRON Christmas Tree generator [closed]

I wish all of you a reflective advent season. If anyone likes to play some code golf, here's your challenge: Write the query that generates a similar Christmas tree in fewer characters than I did. But ...
16
votes
13answers
4k views

Worst case of Slowsort

Background Slowsort is an in-place, stable sorting algorithm that has worse-than-polynomial time complexity. The pseudocode for Slowsort looks like this: ...
5
votes
8answers
1k views

Tips for golfing in TypeScript's type system

What general tips do you have for golfing in TypeScript's type system? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to TypeScript's ...
25
votes
33answers
2k views

Even sum subarrays

Given an array of integers, count the number of contiguous subarrays with an even sum. You may assume that the array is non-empty, and contains only non-negative integers. This is code-golf, so the ...
-1
votes
0answers
199 views

Quantum boolean [closed]

Background Have you ever dream of quantum state? If that's true for you, you are probably weird... Anyway, I came up with an idea: what if we make a quantum in code? Task Create a ...
11
votes
16answers
829 views

Cartesian literal notation

Introduction In computer science, a literal is a notation for representing a fixed value in source code. Almost all programming languages have notations for atomic values, some also have notations ...
27
votes
36answers
3k views

Bubbler and 3 others are typing․․․

Task Implement a kind of "some users are typing" system, which can be found in Discord and some other chat clients. If 1 user (say, Bubbler) is typing, output ...
5
votes
7answers
426 views

Fetch the answer from the Internet

So, normally, this is a forbidden loophole to fetch the desired output from an external source. But this challenge is an exception ! In this challenge you will have to fetch data from the internet and ...
-1
votes
6answers
209 views

Check for Wonky numbers [closed]

Task : Wonky numbers are 3-or-more digit numbers that meet one or more of the following criteria: Any digit followed by all zeros: 100, ...
26
votes
21answers
2k views
+100

Convert prefix to infix

Infix notation is a method of printing mathematical expressions where each operator sits between its two arguments, such as \$ \left(5 \cdot 4\right) + 3 \$. Prefix notation is a method of printing ...
3
votes
9answers
231 views

Panic! at the Golf Club [closed]

I was pondering today about how many characters it would take in each language to throw an exception, and noticed there wasn't any existing collection of answers, so: The task Throw an exception in ...
14
votes
18answers
1k views

Harmonic divisor numbers

Consider the \$4\$ divisors of \$6\$: \$1, 2, 3, 6\$. We can calculate the harmonic mean of these numbers as $$\frac 4 {\frac 1 1 + \frac 1 2 + \frac 1 3 + \frac 1 6} = \frac 4 {\frac {12} 6} = \frac ...
12
votes
7answers
827 views

Convert codepoint to UTF-1

UTF-1 is one of the methods to transform ISO/IEC 10646 and Unicode into a sequence of bytes. It was originally for ISO 10646. The UTF-1 encodes every character with variable length of byte sequence, ...
14
votes
9answers
1k views

Convert Regex to Mask

From my CMC. Given a regex and a non-empty printable ASCII text, return one bit per character in the text, indicating the positions of beginnings of non-overlapping matches, and also the positions of ...
21
votes
5answers
3k views

Will one-cell brainfuck halt?

Brainfuck is an esoteric programming language that is Turing Complete, meaning you can't tell whether a given program will halt without running it. It's cell-based and has an infinite tape of cells, ...
5
votes
0answers
163 views
+50

Tips for golfing in Chef

What general tips do you have for golfing in Chef? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Chef (e.g. "remove unnecessary ...
28
votes
29answers
2k views

Open or Close the Parentheses

Every phone needs a calculator app. Because of the limited screen real estate, the developer of mine has decided to save some buttons. Instead of having two dedicated bracket buttons - one for open <...
19
votes
15answers
5k views

Write a Stack Exchange compliant brainfuck explainer

You are to take a string representing a piece of brainfuck code and Explanations, containing only printable ASCII characters and newlines ( to ...
14
votes
22answers
2k views

Ways to add 1 to lists of lists

Adapted from this StackOverflow question In this challenge you will take a list of lists of integers, e.g. A = [[1,2],[3,4],[5],[]] And an additional single ...
0
votes
0answers
141 views

Create the shortest fastest implementations of powers from 1 to 10 [closed]

Create the shortest code snippet of the power functions 1 through 10 which can be compiled to assembly code and which contains the minimum number of imul assembly ...
13
votes
12answers
2k views

Convert codepoint to UTF-9

UTF-9 was an April Fool's Day RFC joke specifications for encoding Unicode suitable for 9-bit nonet platforms. Challenge Your task is to implement a program or a function or a subroutine that takes ...
16
votes
21answers
2k views

Digit small numbers

A digit small number is a positive integer \$n\$ such for any two numbers that multiply to \$n\$, their total number of digits is more than the digits in \$n\$. In otherwords: there are no two ...
13
votes
3answers
1k views

Recognize a Roboto Mono character

Your input will consist of an 18×18 image in any reasonable format, containing a horizontally and vertically centered 14px Roboto Mono character. This can be any of 94 printable ASCII characters (not ...
1
vote
2answers
99 views

When the result will reach the people? [closed]

Assume the result of an exam has been published. After 5 minutes, First person knows the result. In next 5 minutes, new 8 persons know the result, and in total 9 know it. Again after 5 minutes, new 27 ...
18
votes
5answers
608 views

Is it an elementary matrix?

Consider a linear system of equations, in \$n\$ unknowns, expressed as $$A \textbf x = \textbf b$$ where \$A \in M_{n,n}(\mathbb Z)\$ is an \$n \times n\$ matrix of integers, \$\textbf x\$ is a column ...
9
votes
3answers
517 views

rank and unrank arrays of integers

Consider all arrays of \$\ell\$ non-negative integers in the range \$0,\dots,m\$. Consider all such arrays whose sum is exactly \$s\$. We can list those in lexicographic order and assign an ...
26
votes
18answers
2k views

Floating Point indexOf

Given a sorted array of unique positive integers \$A\$ \$(A_0<A_1<\cdots<A_{n-1})\$, and an integer \$t\$, where \$A_0\le t\le A_{n-1}\$. Output the value \$i\$ such that: If \$t \in A\$, \$...
13
votes
21answers
2k views

Constructing Solar Panels from Squares

I'm designing a new space station for generic super-villain purposes (something something megalaser), but I'm having trouble designing the solar panels. My genius team of scientists can calculate ...
19
votes
21answers
2k views

Alienese cycles

Alienese refers to two "languages" in the show Futurama. In actuality, they are two ciphers of English text with a pictographic alphabet. The first is a simple substitution cipher, but the ...
22
votes
60answers
4k views

Swap every two elements in a list

Challenge Let's have a list L of n elements. The task is to swap every two elements in this list. Constrains the list ...
18
votes
15answers
1k views

Verb arities in J trains

Background J has trains similar to APL's. Given a sequence of verbs (functions), three rightmost verbs are grouped to form a derived verb (a fork) recursively, until one or two verbs remain. If the ...
19
votes
19answers
2k views

Make a Scrabble Word Finder

Yes, I know there is a similar question, but this one specifically concerns any possible words, even with letters left over, while the linked one restricts to a permutation of the input Objective ...
19
votes
13answers
2k views

Compute matrix blockiness

Consider a non-empty binary matrix M and a natural number n. For the purposes of this challenge, M is said to have blockiness n if it can be built using adjacent square blocks of size n, where each ...
9
votes
1answer
227 views

Concatenation Coincidence

This code-golf challenge (and test cases) are inspired by the work of Project Euler users amagri, Cees.Duivenvoorde, and oozk, and Project Euler Problem 751. (And no, this isn't on OEIS). Sandbox A ...
11
votes
9answers
973 views

Bijective meets mixed base

Background A bijective base \$b\$ numeration, where \$b\$ is a positive integer, is a bijective positional notation that makes use of \$b\$ symbols with associated values of \$1,2,\cdots,b\$. ...

1
2 3 4 5
214