# 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.

59 questions
699 views

### Halting Problem for Simplified Hexagony

Introduction Decide whether a Hexagony program composed solely of the characters .)_|\/><@ will halt using least bytes. Challenge Hexagony is a language ...
381 views

### Matrices Generated Using Rectangles

Input is an r by c matrix of non-negative integers (you may input r and c as other parameters if this helps with golf). This may be inputted as a 2D array or, if you prefer, a 1D array (though taking ...
470 views

### Maximal discrepancy-2 sequence with minimal entropy

Background As noted in the PPCG challenge Compress a maximal discrepancy-2 sequence – which inspired this challenge – the authors of the paper Computer-Aided Proof of Erdős Discrepancy Properties ...
409 views

### Optimize Compiler for simple Reverse Polish Notation Programming Language

Description Imaginary programming language (IPL) uses Polish Reverse Notation. It has the following commands: i -- input number and push it to the stack o -- non-destructive output top of the stack ...
831 views

### Complement a POSIX Extended Regular Expression

Given a POSIX Extended Regular Expression as input, output its complement (also a POSIX ERE). If the given regular expression matches a string, its complement should not match it, and the regex: ...
483 views

### Determine if a Graph is Toroidal

A simple graph is toroidal if it can be drawn on the surface of a torus without any edges intersecting. Your task is to take a simple undirected graph via any reasonable method (adjacency matrix, ...
468 views

### Expand Sine and Cosine

Trigonometry has LOTS of identities. So many that you can expand most functions into sines and cosines of a few values. The task here is to do that in the fewest bytes possible. Identity list Well, ...
412 views

### How to reduce EXE size of x86 ASM compiled with FASM?

As an exercise, I've created a simple solution for this challenge, in x86 Assembly Language. I'm running this with FASM on Windows. Here's my source code: ...
433 views

### Complement of a Regex

For the purposes of this challenge, we define a postfix regex dialect with alphabet {1, 0} and the following operations: 1 and <...
586 views

### Golf an unbeatable chopsticks bot

From Wikipedia: Chopsticks is a hand game for two players, in which players extend a number of fingers from each hand and transfer those scores by taking turns to tap one hand against another. In ...
291 views

### Totally Cubular

Create a program or function to unjumble a 9x9x9 cube of digits by rotating individual 3x3 cubes within it. This is similar to (but, I suspect, a bit harder than) my Flippin' Squares question. Input ...
385 views

### Hexasweep (part 1): The Solver

(This is part 1 in a two-part challenge.) Your task is to solve a Hexasweep puzzle. A Hexasweep puzzle is set out on a grid of diamonds arranged in hexagonal shapes, of which the board looks like a ...
210 views

### Tips for golfing in Erlang

Does anybody have tips for golfing in Erlang? I'm looking for specific things that can be applied to Erlang, not any language. I know we already have tips for Elixir, but that is different. As usual,...
376 views

### How should I tile my kitchen?

I recently ordered some new and colorful tiles to replace my boring old white tiling for my kitchen. However, when the tiles arrived, they were all in a weird shape! Therefore, I need a program to ...
619 views

### Keep my Trip Cool!

Challenge Walking around Marks and Spencers, I noticed that they had air conditioning units placed randomly around the shop. Wanting to keep cool, I wondered what was the easiest way to move around ...
700 views

### Find a Glider Synthesis (Game of Life)

Challenge Summary In summary, the challenge is to provide the glider synthesis for a Game of Life configuration, which is your input. What does this mean? Well, firstly, let me explain a few terms. ...
400 views

### Please parse this aLL1en language

Background Due to some unfortunate accident during coding you are now teleported and stranded on an alien planet. You really hope that the locals will be helpful and point to the general direction of ...
455 views

### mini SPICE solver

SPICE is an electrical circuit simulation program originating from UC Berkeley. Your goal is to implement a minimalistic version which can solve for the nodal voltages and branch currents of a circuit ...
112 views

### Fix Brain-Flak push-pop redundancy

Brain-Flak is a stack-based esoteric language with eight commands: ...
218 views

### Solve Subset-Sum in polynomial time (…if P = NP)

Shocking news: Dr. Mad J Scientist has released a proof of P = NP to the world. But the proof is nonconstructive, and she's keeping the algorithm to herself. Worry not. Without even looking at her ...
237 views

### Is this a Boggle pad?

Given a list of case-insensitive ASCII letter strings ("words"), output whether the entire list can be found on some four-by-four configuration ("board") of letter squares, in which no square can be ...
185 views

### Tips for Golfing in SQLite?

I was looking for this page to help me enhance my first answer with SQLite, but I couldnt find one. So here we are! What general tips do you have for golfing in SQLite? I'm looking for ideas that can ...
508 views

### Up 12 at 4 it's

Introduction On BBC Radio 2, on Saturdays there's a show hosted by Tony Blackburn called Pick of the Pops. Here, Tony selects a random week from a random year (in the range 1960-1989), and plays the ...
396 views

### Simulate a Game of Quagmire

Background Many moons ago, in a galaxy much like our own, a young BrainSteel attempted to invent a board game. He believed that he, too, could find an amazingly simple set of rules that would ...
211 views

One of the cool features introduced in the C++11 standard is the ability to declare a template parameter as being variadic; i.e. that parameter represents a sequence of an arbitrary number of ...
251 views

### Simple predictive keyboard CG

In honor of recent news of Google developing a keyboard for iPhone... Your input (for simplicity, all input is case sensitive): Location of standard dictionary file. File format is 1 valid word per ...
511 views

### Printing the Cracker Barrel Game

Revised formatting and instructions Given a list of moves for a Cracker Barrel peg board game, or as @Steveverrill stated, Peg Triangle Solitaire: ...
279 views

### Recording xiangqi moves

The game of xiangqi, also known as Chinese chess, is a chess-like game popular in China, Vietnam, Taiwan, and other East Asian countries. The colours of the two sides in xiangqi are red and black. ...
271 views

### Code Golf: BlackJack - best moves

The Challenge I was looking into small code examples for a specific language as a small tutorial and came accross a simplified Blackjack that should be implemented. In this Challenge you will have to ...
428 views

### Chaining autograms

Write a program that takes one integer input n and one format letter and outputs n autograms in the format This sentence contains ? "A"s, ? "B"s ... and ? "Z"s. ...
367 views

### Get ERC-20 token balance

Ethereum is a blockchain platform. It has its own native cryptocurrency, ether, but in this challenge, we'll be focusing on its ability to run smart contracts. The ERC-20 standard describes an ...
319 views

### Don't break the bridges!

Introduction: You are a worker, who is in charge of managing a set of bridges, connecting a square grid of "nodes": ...
213 views

This is thematically similar to Generate keyboard shortcuts for a menu, but its actually a pretty different challenge. Let's take PHPStorm's menu as an example: ...
280 views

### Find a dual graph

A dual graph is defined such that for every "face" in a graph G, there is a corresponding vertex in the dual graph, and for every edge on the graph ...
127 views

### Tips for golfing in Subleq

Subleq is a programming language with only one instruction. Each instruction contains 3 parameters. Code and data space is the same. How it works: A B C A, B and ...
148 views

### Implement FBLint

(FB, or Functional-Basic, as found here Interpret Functional-Basic) Task Implement a linting program for FB, similar to JSLint for JavaScript. Error types Invalid identifier Identifiers can only ...
639 views

### Generate Loopy puzzles

Loopy is a puzzle game from the collection of Simon Tatham. The previous link contains a javascript implementation of a Loopy puzzle generator. I suggest everybody who wants to attempt this challenge ...
205 views

A radiation-hardened quine can take a hit and stay standing, but nobody ever said that the quine can't be a wuss about it. For this challenge, you should write a quine that: If no characters are ...
158 views

### Tips for golfing in Scratch

Scratch is a visual programming language. For the sake of counting bytes, Scratch is usually written in scratchblocks2 syntax. Post tips that specifically apply to Scratch or scratchblocks2.
184 views

### Find the smallest triangle encompassing the specified polygon

Input: An integer N which represents the polygon's vertices and a list of their x and y coordinates. Expected output: The smallest difference possible between the area of the(not necessarily convex) ...
255 views

### Declare a Code Golf Winner

Normally, I'd open with some flavor text here about being bored and/or lazy but looking through the stack-exchange-api questions that would be far from original. So instead I'm going to open with a ...
270 views

### Hamilton is coming to town

It's almost Christmas, so Santa has to plan his route. You're helping him, for reasons unknown. Santa needs help planning the route and wants you to give him a solution, but since you're all ...
265 views

### Generate net puzzles

An acyclical grid is a mapping of an acyclical graph (that is, a tree) where each node has no more than four edges onto a toroidal rectangular grid such that each cell of the grid is occupied by a ...
291 views

### Tetris overlooked move counter

Playing tetris is fun. Watching an AI play tetris is also fun. Some tetris AIs will always ignore the possibility of maneuvering a piece under an overhang, which makes me sad. It means that the ...
183 views

### Decompose the domain

In scientific computing, it is often desirable to decompose some large domain into smaller "subdomains", then parallelize the computation by performing the work on each subdomain in parallel and the ...
237 views

### Rope&Nail logic

Related, both rope, nail and falling, but reversed and some other differences Consider a loop of rope hanging on n nails on a row. Given a table showing whether ...
192 views

### 2017 SCRAM Finder

Background The nuclear industry has term, SCRAM, used to describe a quick shutdown of the reactor. There's a fun myth that it stands for "Safety Control Rod Ax Man," the role which served to shut ...
124 views

### Tips for golfing in SageMath

SageMath is an open-source mathematics software system, built on Python 2. Its extensive math library support makes it a strong choice for golfing in math-based challenges. What tips do you have for ...