# Questions tagged [code-golf]

Code-golf is a competition to solve a particular problem in the fewest bytes of source code.

3,154 questions
Filter by
Sorted by
Tagged with
285 views

### Is this a Lucas number? [duplicate]

Write a program or function that takes an input greater than or equal to 2. It should output a truthy or falsy value corresponding to whether the input is a Lucas number or not. You may take input ...
808 views

### Alex the Truck Driver

Alex is a Truck Driver who wants to find the quickest way to deliver goods to multiple cities. He knows the distances between his destinations, but you need to write a program to help him find the ...
313 views

### Sorting for search by monotomy

Statement Given N distinct integers, output them in order such that for any integer J from 2 to N, for any K>0 obtainable by dividing J by 2 (rounding down) at least one time, the Jth integer ...
400 views

### Autocomplete the input

Pre-Note Because of popular demand, and to avoid disqualifying certain languages, the dictionary can now be provided as input parameter. Intro Given a dictionary of words, you should write an ...
169 views

### Black and white shirt 2

This is a more complicated version of this puzzle. The premise is the same but a few rules differ in a few key places, making for a more complex problem. Assume I have some number of black shirts and ...
555 views

### Find number of polynomials with a root which is a root of unity

Write a program which takes an integer argument and outputs the number of degree n monic polynomials with coefficients that are -1,1 or 0 which have a root which is a root of unity. To make it a ...
468 views

### Create a kind of quine, such that the program prints one character of itself, then two, then three and so on

Create quine variant such that the program prints its first character, then the first two, then three and so on until the whole program is printed. Example Suppose your code is ...
2k views

### Base-2 integer logarithm of 64-bit unsigned integer

Problem: In your choice of language, write the shortest function that returns the floor of the base-2 logarithm of an unsigned 64-bit integer, or –1 if passed a 0. (Note: This means the return type ...
789 views

### Isn't the point of math to just use numbers?

Write a program that converts a mathematical expression to words, evaluates the expression, and prints how the equation would be spoken aloud. Input The input must only contain numbers and the ...
233 views

### Simulate Rocket League Quick Chat

In Rocket League, there are controls assigned to quick chat. For PC, they are 1, 2, 3, and <...
618 views

### Recursive Mathematical Puzzle from a high school contest

The problem appeared on the 2013 SJCNY High School Programming Contest. It was the last question in the set of problems and no team produced a correct answer during the 2.5 hours they had to work on ...
2k views

### Alien Name Generator [closed]

Task Write a function to generate names of aliens and their worlds, so that the output is of the form: Greetings Earthfolk, I am ____ of the planet _____. "...
246 views

### Write the shortest code that bring to a solution of “The old curious knight with a lazy horse” problem [duplicate]

The Story: Once upon a time there was a curious Knight that lived on a never used chessboard in the Realm, an antique store. He spent all his career over there and when it came the moment of the ...
487 views

### Evaluate the binomial theorem!

Your mission, even if you don't accept it, is to input three numbers from STDIN or file: 5 0.5 6 What you must do is evaluate this: (5a + 0.5b)^6 This basically means that the first two ...
389 views

### Black and white shirts

This puzzle is based on this Math.SE post. A more complex version of this problem can be found over here. Assume I have some number of black shirts and some number of white shirts, both at least 1. ...
126 views

### Chemical sentences! Encrypting [duplicate]

Background You are bored in class, and having exhausted all the possible things to write on a standard calculator (Like 8008135) you turn to the periodic table. You want to figure out if you can ...
360 views

### Calculate the first n perfect numbers [closed]

Write a program that calculates the first n perfect numbers. A perfect number is one where the sum of the factors is the original number. For example, 6 is a perfect number because 1+2+3=6. No non ...
395 views

### Gode-Colf: Wipping Flords around [duplicate]

Here is another short string related code-golf. You must write a full program that reads a string (from STDIN or as command line arguments, as long as you specify which) and wips the flords around (...
168 views

### Most logical rectangle formula from numbers [duplicate]

Introduction The task is simple. When given a number, output the most logical rectangle. To explain what a logical rectangle is, I provided some examples: Input: ...
534 views

### Find the next number in the pattern

Write a program, that takes 5 numbers as input and outputs the next number in the pattern. Heres a text file with 1835 test patterns, containing 6 numbers separated by commas each line. Using the ...
1k views

### Self replicating Hello World program [closed]

Create a self-replicating Hello World Program. (The program has the ability to use the compiler, if you want). For example: ...
336 views

### Create a Boolean parser [closed]

What you need to do is create a Boolean parser. Boolean expressions, in case you haven't heard of them yet, have two inputs and one output. There are four 'gates' in boolean arithmetic, namely OR (...
212 views

### Tips for golfing in Visual Basic

This page is not for Visual Basic .NET Tips or VBA tips Visual Basic (VB or VB6) is an object-oriented and event-driven dialect of basic that was developed and released by Microsoft in 1991. The last ...
295 views

### Tips for golfing Yabasic

Yabasic, or Yet Another Basic is a dialect of basic created by Marc-Oliver Ihm that may be run on Windows, Unix and PAL versions of the Sony PlayStation 2. Development for this language is ongoing. ...
1k views

### Longest Seven Segment Word

This question was inspired by Tom Scott's video here. The English language has plenty of words, but what's the longest one that can be displayed on a seven segment display? Your challenge is given a ...
74 views

### Merry Christmas (and a Happy New Year) [duplicate]

The goal of this challenge is to create a program that outputs a string depending on the time of year. Output If the date is December 25, output: ...
106 views

### Encode the simple substitution cipher [duplicate]

Review First, let's review the Simple Substitution Cipher. To encode a string in the Simple Substitution Cipher, replace each letter in your string with another letter. A letter may not be used to ...
234 views

### Tips for golfing in Befunge 93 [duplicate]

What general tips do you have for golfing in Befunge 93? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Befunge 93 (e.g. "remove ...
4k views

### Find the Longest Palindrome in a String by Removing Characters [duplicate]

Problem: Remove characters from strings to make the longest (character length) palindrome possible. The first line gives an integer value of the number of strings to test. Each subsequent line is a ...
243 views

### Tips for golfing in Visual Basic .NET

This page is not for Visual Basic Tips Visual Basic .NET (VB.NET) is an multi-paradigm dialect of basic that was developed and released by Microsoft in 2002 as a replacement for Visual Basic. The ...
208 views

### Dyalog's International Problem Solving Competition (Phase I) – Code Golf Edition [closed]

Every year, Dyalog Ltd. holds a student competition. The challenge there is to write good APL code. However, this is a multiple-holes (common theme is manipulation of data of any type and structure, ...
258 views

### What's the missing column/row? (GCJ 2016-1A rankfile)

There is an N x N square of numbers. All columns increase strictly monotonically from top to down All rows increase strictly monotonically from left to right There ...
308 views

### How compute WPA key? [closed]

WPA2, the actual encryption standard that secures all modern wifi networks, has been cracked... This challenge has nothing to do with the way that the WPA2 was cracked, however is is about computing ...
259 views

### Output in the Correct Order

Ok lets say we get a input the following csv file (all entries are quoted strings) ...
238 views

### Havel-to-da-Hakimi [duplicate]

It was a dark and stormy night. Detective Havel and Detective Hakimi arrived at the scene of the crime. Other than the detectives, there were 10 people present. They asked the first person, "out of ...
85 views

### Josephus Problem [duplicate]

With n people numbered 1 to n in a circle, every second one is eliminated until only one survives. For example, for n=10, the elimination order is 2 4 6 8 10 3 7 1 9, so 5 survives. The problem: ...
873 views

### HyperNeutrino is back!

Today, @HyperNeutrino succeeded merging his two accounts, and finally got the reputation he lost back. Now, it's time to celebrate! Your task is to output this exact text: /\ ...
405 views

### Embedded Triangles!

Your task: given an integer n, output an embedded triangle to the nth depth. Standard methods of input and output, input in any ...
207 views

### Solitaire no-win states [duplicate]

NOTE: SIMILIAR TO Solitaire Dreams - Creating a winnable solitaire starting hand Find a minimum of 5 deck orders where if the cards were dealt out would create a game of Klondike Solitaire where ...
338 views

### Do not use the same code again [closed]

I want to give a task. The main rule is not to use the same code again, it means no loops, no jumps, no goto, no recursion, if you declare procedure it can be called only once and etc. Also if you ...
2k views

### Solve this math problem in smallest amount of code [closed]

Here I found a cool math problem. I thought you could write some golfed code to compute all answers between x and x.(there is an infinite amount). Problem: Once upon a time, and old lady went to sell ...
7k views

### Shortest way to generate UUID's version 3,4 and 5 in php

I have this function to generate UUID's: ...
233 views

### Generate a hexdump of a file! [duplicate]

In this task, your goal is to write a program for generating hexdumps of files of arbitrary types. Input The input consists of a (relative or absolute) path to the file to be processed. It may be ...
208 views

### Find an Eulerian Circuit

Challenge You have been assigned a task to write a program which takes a multigraph as its input and if it contains an Eularian circuit to return one. Otherwise, the program's behavior is undefined, ...
452 views

### Find the hardest OEIS sequence to golf!

Notice: This question originally had people write comments with a shorter program, rather than new answers. This has been changed so that people with shorter programs can get reputation too. Hopefully ...
229 views

### Binary Magic Cards [closed]

There's a cool magic trick that works using the power of binary. The effect of the trick is as follows: An audience member chooses some natural number in the range of ...
765 views

### Make a golfing language [closed]

In this challenge, you get to create a language. Although you have to provide code in other languages, you will only be rated based on the language. Here are the requirements. You must invent a ...
290 views

### Solve an algebraic expression

The Challenge Your task is to create a program that can solve an algebraic equation. Input Input will consist of a String. The string will be an equality ...