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
18 votes
6 answers
2k views

Is it 1089-able?

\$ 1089 \$ is a very special number. To prove why, select any 3-digit number whose first and last digits differ by at least 2. Then, reverse the digits, and take the difference of these two numbers. ...
user avatar
  • 16.9k
9 votes
5 answers
737 views

Will this makina program halt?

makina is a cell-based esolang composed of automata which move around a grid. These automata follow paths of instructions that direct their movement. Your task is to, given a makina program using only ...
user avatar
  • 3,224
21 votes
16 answers
1k views

Get the trends of an array

For our purposes, a trend is a contiguous subsequence of an array that falls into one of three categories: increasing, e.g. [1,2,3,10,239] decreasing, e.g. ...
user avatar
  • 8,658
13 votes
10 answers
1k views

Lexicographically self-comparing code

This is a quine challenge related to Write the shortest self-identifying program (a quine variant) Write a function or a full program that compares lexicographically its source code and input, that is,...
user avatar
  • 9,426
16 votes
18 answers
4k views

How long is it in Roman

Or Fix American Kennel Club's database As covered by the recent video by Matt Parker, the American Kennel Club permits thirty-seven (37) dogs of each breed to be assigned the same name (source), ...
user avatar
  • 10.7k
16 votes
7 answers
540 views

Translate Text into Matoran

The Matoran Alphabet is the alphabet used by many of the characters in the Bionicle universe. Your challenge is to create a program or function that takes a string as input and creates an image of ...
user avatar
18 votes
17 answers
3k views

Convert angle to clock time

Your task is to make a program or function that takes a nonnegative integer (or a different convenient format to represent it) that represents an angle measure in degrees from 0 to 180 (inclusive) as ...
user avatar
  • 1,841
12 votes
10 answers
939 views

Convert J brackets back to 2-D list

Let's say we have a 2-D list, like the following one: \$ \begin{bmatrix} \color{red}{1} & \color{red}{2} & \color{red}{3} & \color{red}{4} \\ \color{blue}{5} & \color{blue}{6} & \...
user avatar
  • 3,696
14 votes
13 answers
838 views

Ragged list pattern matching

Given a pattern and a ragged list of positive integers, your task is to decide whether the pattern matches the ragged list. The pattern is also represented by a ragged list. But in addition to ...
user avatar
  • 32.7k
16 votes
23 answers
1k views

Pair my brackets

Given a string consisting of ()[]{}, print the paired brackets in the same order as they appear in the string. Any opening bracket ...
user avatar
  • 3,605
8 votes
1 answer
286 views

Generate all polyiamonds

A polyiamond of size \$n\$ is a contiguous shape formed by joining \$n\$ equilateral triangles side by side. Your output should consist of two distinct characters, plus whitespace as necessary (▲ and ▼...
user avatar
  • 1,995
14 votes
5 answers
692 views

Is this propositional formula an instance of an axiom?

Please help me automate my discrete mathematics homework. Given a valid propositional formula, check if it is an instance of one of Łukasiewicz's axioms. Here's how it works. A term can be defined ...
user avatar
16 votes
1 answer
288 views

Simplified Piet Interpreter

Background Piet is an esoteric stack-based programming language in which programs are images meant to resemble abstract paintings. To keep the challenge from being unnecessarily complex, you will not ...
user avatar
  • 3,821
12 votes
18 answers
1k views

Words with Easy Letters in a Word Search

Introduction: Apparently I keep coming up with word search related challenges lately. :) When I do the word search in the Dutch news paper, some words are very easy to find because they contain ...
user avatar
18 votes
15 answers
3k views

Join my exclusive friendly club!

Two or more positive integers are said to be "friendly" if they have the same "abundancy". The abundancy of an positive integer \$n\$ is defined as $$\frac {\sigma(n)} n,$$ where \$...
user avatar
0 votes
0 answers
80 views

Please simplify math for me by implementing super operation [duplicate]

I did lot of math recently and get tired of using those different operations like +, *, and ...
user avatar
  • 669
9 votes
5 answers
299 views

Convert the type modifiers from prefix to C-fix

Given a base type T, this can be augmented with * or [], each meaning pointer and array. For ...
user avatar
  • 2,121
19 votes
8 answers
2k views

Optimally break a string into words

Given a string, like potatocarrot, break it into the smallest number of substrings possible. These substrings can consist either be a single character, or one of a ...
user avatar
14 votes
13 answers
1k views

Average-ignorant sets of integers

Recently a friend of mine posed the following: What subset of the integers satisfies the condition if distinct a and b are in the subset, their average is not in the subset? I know the set of non-0 ...
user avatar
  • 491
8 votes
35 answers
3k views

Find the weight of five apples

Problem John bought 5 apples. You are given the weights of every group of four apples, and must then find the weights of the apples themselves. For example, if all apples without the first one weigh ...
user avatar
  • 99
22 votes
12 answers
2k views

How many Sieve of Eratosthenes hits?

Sieve of Eratosthenes is a method for finding prime numbers: take the sequence of all positive integer numbers starting from 2 then for each remaining number drop all its multiples. ...
user avatar
  • 9,426
10 votes
1 answer
726 views

Curry tips for Haskell programmers

Curry is the Language of the Month this month and some users are starting to get into it, so let's get some tips together. Haskell and Curry are similar in a lot of ways and a lot of tips for Haskell ...
user avatar
  • 84.7k
14 votes
3 answers
827 views

Sniff out biased random permutations

The brilliant engineers at <enter company you love to hate> have struck again. This time they've "revolutionised" the generation of random permutations. "Every great invention is ...
user avatar
  • 5,690
20 votes
13 answers
2k views

Shuffle an array, a little bit

Given some input array a = [a1, a2, ..., an] and a positive integer k, shuffle the input array ...
user avatar
  • 42.9k
13 votes
12 answers
2k views

Simulate the ripple effect

Imagine throwing a rock into a pond. You get to see perfect circles of ripples spreading out over the pond, bouncing off of each other. Of course, nothing can be as serene as that in coding, but, we ...
user avatar
  • 691
14 votes
8 answers
732 views

Organize a Kiowa library

We are probably all used to the English alphabetical order: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z When we compare words in English for the sake of ...
user avatar
  • 84.7k
17 votes
17 answers
1k views

Play Caesar's Cipher with Letters only

Description The Caesar cipher is a cipher, where every letter in the alphabet will be rotated by a secret number. If the rotation is \$7\$, then a -> ...
user avatar
  • 3,605
16 votes
16 answers
1k views

Damerau-Damerau distance

Given a list of the integers from \$1\$ to some \$n\$, give the minimum number of adjacent swaps required to put the list in ascending order. You will receive a list as input and should output a non-...
user avatar
  • 84.7k
10 votes
2 answers
468 views

Tips for golfing in Piet

Seeing that the current language for Learn You a Lang for Great Good is Piet, and that we don't seem to have a tips page for Piet yet, I decided to make one. Piet is a stack-based esoteric programming ...
user avatar
  • 3,821
17 votes
17 answers
3k views

Numbers in 2050

It's 2050, and people have decided to write numbers in a new way. They want less to memorize, and number to be able to be written quicker. For every place value(ones, tens, hundreds, etc.) the number ...
user avatar
  • 303
12 votes
1 answer
324 views

Wash clothes as quickly as possible

It's laundry day, and you have lots of clothes that need to be washed. Wanting to have as much time left over for code golf as possible, you hope to optimize how quickly you wash and dry them all. You ...
user avatar
17 votes
11 answers
777 views

Find the J twin

For a 2 dimensional array we will define the elements in either the first row or the last column to be the largest "J-Bracket" of the array. For example in the following array elements in ...
user avatar
  • 84.7k
2 votes
0 answers
64 views

Tips for golfing in Fennel

Fennel is a lispy language which compiles to Lua. From its page: Fennel is a programming language that brings together the speed, simplicity, and reach of Lua with the flexibility of a lisp syntax ...
user avatar
  • 1,581
18 votes
19 answers
1k views

Removed J-brackets

For a 2 dimensional array we will call the elements in either the first row or the last column the "J-Bracket" of the array. For example in the following array elements in the J-bracket are ...
user avatar
  • 84.7k
0 votes
5 answers
268 views

Make a +-= Interpreter [duplicate]

+-= is a language created by Esolangs user Anonymous in 2017.The language consists of only three commands: + increases the accumulator by one. ...
user avatar
5 votes
6 answers
534 views

Batt to the Basics

One of your acquaintances has a hobby of making make-shift electrical gadgets using various types of batteries. However, since they're thrifty, they want to use as few batteries as possible for their ...
user avatar
7 votes
5 answers
415 views

Calculate the overlapping line

(l, r) defines a line whose left end is at l and the right end is at r, on a 1-dimensional ...
user avatar
  • 2,121
10 votes
6 answers
552 views

Fourth Time's the Triple Tap

The sci-fi shooter Destiny 2 contains guns which have the ability to regenerate ammunition directly into the magazine if, and only if x (precision) shots are landed ...
user avatar
13 votes
9 answers
920 views

Remove unmatched brackets

Inspired by @AviFS. Given a string containing brackets, e.g. [xyz]]abc[[def]hij[ You can parse through it with a stack of brackets. When you find an open bracket, ...
user avatar
  • 26.7k
19 votes
7 answers
1k views

Expand a matrix goo-ily

Input An \$m\$ by \$n\$ binary matrix, with \$m\$ and \$n\$ both at least 2. Think of the ones as gobs of melted cheese, which stretch as we expand the matrix horizontally and vertically. More ...
user avatar
  • 26.5k
10 votes
7 answers
275 views

Maximum population of a \$n \times n\$ still life in Conway's Game of Life

This is OEIS sequence A055397. In Conway's Game of life, a still life is a pattern that does not change over time. We can see from the rules of Conway's Game of life that, a pattern is a still life if ...
user avatar
  • 32.7k
12 votes
5 answers
232 views

Resolve a Super Auto Pets Round

In Super Auto Pets, players build teams of animals that face off in battles to the death unconsciousness. Each animal has an Attack and Health value, and combat occurs in iterations of the following ...
user avatar
9 votes
11 answers
1k views

Smallest numbers whose square has even number of digits

...
user avatar
  • 9,426
16 votes
11 answers
2k views

Satisfy as many people as possible

There are times when a large number of people need to choose something. They all want to get the stuff they choose, obviously, but it's impossible to please everyone that way, so a usual compromise is ...
user avatar
  • 2,659
14 votes
17 answers
1k views

The interstice of two binary numbers

Given two integers, compute the two numbers that come from the blending the bits of the binary numbers of equal length(same number of digits, a number with less digits has zeros added), one after the ...
user avatar
  • 457
12 votes
9 answers
462 views

Draw an ASCII envelope based on size input

You want to send an ASCII letter to someone, but you need an envelope to put it in. Your task is to output an envelope given a size as input. Rules: Given positive integer input ...
user avatar
-1 votes
5 answers
259 views

Output this string from the `kolmogorov-complexity` tag info page [closed]

kolmogorov-complexity is one of the tags on this site, representing challenges that test how much code is needed to output a given fixed result (usually a piece of text). The info page for this tag ...
user avatar
  • 1,460
19 votes
30 answers
2k views

Convert from variable-width Two's Complement to Integer

Take an input, and convert it from Two's Complement notation (binary where the first bit is negated, but the rest are taken as normal) into an integer (in a somewhat standard output form). Input can ...
user avatar
  • 1,240
10 votes
8 answers
2k views

How many times do I break my own rule?

Introduction: In my recent Strikethrough the Word Search List challenge I mentioned the following: When I do the word-search puzzles, I (almost) always go over the words in order, and strike them ...
user avatar
6 votes
15 answers
897 views

Spaceship shooter

Your task is to output a spaceship of size n with shooters/guns and n bullets of character - ...
user avatar
  • 3,031