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
17
votes
3answers
926 views

Security by Post-It

As you may know, hackers are everywhere and they want to hack everything. You were asked to make password requirements which will stop any hacker. The problem is, that your boss has heard that paying ...
7
votes
7answers
2k views

Big integer multiplication

Your challenge (if you choose to accept it) is to implement big integer multiplication in the shortest code possible. Rules: Take two integers (decimal form) as ASCII strings from the command line ...
4
votes
9answers
967 views

Subtracting, the old-fashioned way

Overview Adding slightly to the complexity of working with Roman numerals... The ancient Romans devised a number system using Latin letters, which served them well, and which is still used by modern ...
5
votes
5answers
2k views

Prime sieve and sort (x86 asm)

Your challenge is to write a routine, in x86 assembly, which takes a buffer containing 32-bit signed integers and writes a sorted list of the prime values to another buffer, then returns the number of ...
278
votes
70answers
75k views

We're no strangers to code golf, you know the rules, and so do I

Write the shortest program that prints the entire lyrics of "Never Gonna Give You Up" by Rick Astley. Rules: Must output the lyrics exactly as they appear in the above pastebin*. Here's the raw dump:...
12
votes
26answers
724 views

De-Nesting Lists

Given a list with lists nested inside it, return the list with the nested lists' items de-nested. Input The list will have, at most, 4-deep nested lists. Count all 0's within the input as a null ...
8
votes
12answers
1k views

Adding, the old-fashioned way

Overview The ancient Romans devised a number system using Latin letters, which served them well, and which is still used by modern civilization, though to a much smaller degree. In the time of its use,...
15
votes
2answers
3k views

Play a perfect game of Mu Torere

Background Mu Torere is a game that is one of only two known to be played by the Maori people of New Zealand before European influence. This makes it a very unique game in that it has an "objective ...
58
votes
106answers
14k views

List of primes under a million

This is my first code golf question, and a very simple one at that, so I apologise in advance if I may have broken any community guidelines. The task is to print out, in ascending order, all of the ...
3
votes
4answers
311 views

maximum subarray variant

Problem There is a circular track containing fuel pits at irregular intervals. The total amount of fuel available from all the pits together is just sufficient to travel round the track and finish ...
5
votes
5answers
948 views

Text-Twist - similar to boggle problem

A similar play on the boggle problem from before (some text from that has been used below, edited to fit) any code that solves the familiar "text-twist" game Objective 7 letters are given at random, ...
30
votes
30answers
3k views

Josephus problem (counting out)

The challenge Write a function that takes two positive integers \$n\$ and \$k\$ as arguments and returns the number of the last person remaining out of \$n\$ after counting out each \$k\$-th person. ...
38
votes
25answers
3k views

HelolW rdlo (A threading challenge)

I have a challenge for you: Print "Hello World" using any language. Each character must be printed from its own, unique thread That's it. Obviously, as there's no guarantee that the threads will ...
16
votes
11answers
2k views

triplegolf - not only the source code length counts!

The goal of this challenge is to write a program where the length of the following three are exactly the same: the length of the source code the length of the output it prints to the standard output ...
4
votes
4answers
2k views

Convert from postfix notation to infix notation

This question may not be that creative, but I believe that it is different enough to pose a new challenge. The Challenge Your challenge is to write the shortest program possible that can take any ...
23
votes
7answers
6k views

Convert infix expressions to postfix notation

When I saw the title of this closed question, I thought it looked like an interesting code golf challenge. So let me present it as such: Challenge: Write a program, expression or subroutine which, ...
16
votes
10answers
1k views

Sum of (at most) 5 primes

Terence Tao recently proved a weak form of Goldbach's conjecture! Let's exploit it! Given an odd integer n > 1, write n as ...
13
votes
9answers
2k views

Print the first 128 prime numbers without using any reserved words

The obvious solution would be to just print them as a string, but is it possible to write a shorter code? Requirements: No input should be processed, and the output should be in the form of ...
14
votes
6answers
3k views

Output a list of all rational numbers

Out of all of mathematics, there will always be a few theorems that go beyond all common sense. One of these is the fact that there are different sizes of infinity. Another interesting fact is the ...
11
votes
17answers
2k views

Tower of hanoi solver

For reference as to what the tower of Hanoi is, either Google it or look on the Wikipedia page. Your code should be able to do 2 things, and they are the following: Accept user input that specifies ...
11
votes
8answers
2k views

Build a typing speed test / measuring CPM

The Rules It's time to build a typing speed test in your language of choice! 1. You provide a file with a dictionary of choice (every 'word' in it must be newline delimited). Pipe it in via ...
8
votes
3answers
2k views

PHP golfing tips: Reading/writing files and the CLI

I have been participating in a number of PHP code golf challenges recently and some of the techniques that are used to read data from a file such as fopen() and <...
25
votes
2answers
11k views

Shortest ELF for “Hello world\n”? [duplicate]

Is it possible to write (pack) a shorter than 145 bytes version of a program with "Hello world" (plus new line) output if the length of the program is measured as a number of bytes in program's ELF (...
4
votes
3answers
629 views

Pretty-printing polynomials

A polynomial over a variable x is a function of the form p(x) = anxn + an-1xn-1 + ... + a1x + a0 where a0 ... an are the coefficients. In the simplest case, the coefficients are integers, e.g. ...
11
votes
16answers
2k views

ASCII Ball in Box Animation

Write a program that displays a moving ASCII ball * inside a rectangle (20 by 10 chars including border). The ball must not cross the rectangle, e.g. bump off when ...
71
votes
120answers
16k views

Print the alphabet without using each vowel

Inspiration: in 1939, a man named Ernest Vincent Wright wrote a novel called Gadsby without using the letter 'e'. Your task is to write a set of (up to 5) programs in any language (which has a text-...
22
votes
7answers
948 views

Reverse Engineer Polling Statistics

Introduction Given a set of percentages of choices in a poll, calculate the minimum number of voters there must be in the poll to generate those statistics. Example: What is your favorite pet? Dog: ...
11
votes
2answers
336 views

How many mesas begin with a given string?

Let's call a non-empty list of strings a mesa if the following conditions hold: Each listed string is non-empty and uses only characters that occur in the first string. Each successive string is ...
8
votes
3answers
3k views

Solve the 14-Pegs puzzle

Introduction A common puzzle involves a triangular board with 15 holes for tees/pegs as shown in the image below: Starting with all the pegs in the board except for a hole at the top, the point of ...
31
votes
45answers
6k views

Implement hyperexponentiation/tetration without the use of '^'

The Challenge Implement tetration (aka Power Tower or Hyperexponentiation) with the least amount of characters. The Conditions Don't use the 'power' operator or its equivalents (such as ...
14
votes
5answers
6k views

Shortest Hello World program with no semi colons

I recently saw some questions on SO that asked if you could make a Hello World program without using any semi colons using C#. The challenge is to do this again, but in the shortest amount of code ...
25
votes
59answers
7k views

Is string X a subsequence of string Y?

Given strings X and Y, determine whether X is a subsequence of Y. The empty string is regarded as a subsequence of every string. (E.g., '' and ...
6
votes
13answers
878 views

Generate the list [1, 0, -1, 0, 1, 0, -1, 0, …] [closed]

In the spirit of a question on math.se: given an integer n, return the integer in position n of the sequence [1, 0, -1, 0, 1, 0, ...
12
votes
2answers
1k views

Code Golf: What is the spaceship's fate? [floating point version]

This question is slightly harder than the ASCII art version. There is no art, and now you get to do some floating point arithmetic! The Challenge The U.S.S. StackExchange was traveling through the ...
28
votes
7answers
3k views

Score a Cribbage Hand

This challenge is to score a Cribbage hand. If you don't play Cribbage, you've got some learning to do. We play with a standard poker deck, and a hand consists of four cards plus the "up card". ...
14
votes
1answer
2k views

Code Golf: What is the spaceship's fate? [ASCII art version]

Background In a galaxy (and possibly a universe) far, far away... there was a spaceship and a bunch of planets. A malfunction on board caused the spaceship to run out of fuel. It is now moving at a ...
27
votes
6answers
2k views

Can you Meta Quine?

Similar to other quine puzzles (more specifically, this one), write a program that produces the source for itself. Here's the new twist: The code produced should NOT be identical to the source. ...
15
votes
14answers
1k views

Calculate a user's privileges on CodeGolf.SE

The Challenge Your goal is to write the shortest program possible that will take a list of events (such as upvote, downvote, etc) and return the user's reputation and the privileges that he has ...
21
votes
2answers
2k views

Play Connect 4!

Write a program to play the game of Connect 4. You are given the state of the board as input and you must decide which column to place your piece in to either get 4 in a row (horizontally, vertically,...
33
votes
7answers
4k views

Anti-aliasing ASCII art

Background ASCII art is the practice of creating images by using ASCII text to form shapes. Aliasing is the effect created by the large "pixels" of ASCII art, which are the size of characters. The ...
14
votes
16answers
2k views

Rosetta Stone Challenge: Find the rule for a series

The goal of a Rosetta Stone Challenge is to write solutions in as many languages as possible. Show off your programming multilingualism! The Challenge Your challenge is to implement a program that ...
16
votes
3answers
2k views

Code golf: Solve a Knights and Knaves logic problem by parsing English

Background There are two people, Bill and John. One of them is a knight, which always tells the truth, and the other is a knave, which always tells a lie. You don't know who is the knight and who is ...
10
votes
6answers
469 views

Print the sizes of intervals inside of a piece of music

Background In Western music, every single music note has an assigned name. Within each octave, there are twelve unique notes in the following order: "C C#/Db D D#/Eb E F F#/Gb G G#/Ab A A#/Bb B C", ...
4
votes
2answers
7k views

Water-Bucket problem [closed]

This challenge is to calculate how to measure 4 liters of water with just two unevenly sized buckets, one of 3 liters and another of 5 liters, in minimum number of steps. To extend and generalize this,...
12
votes
13answers
9k views

create an ascii progress bar

well, it's something similar to this question but with a little differences. you have to write a program to ask for width of progress bar and how much work is done. and then draw a progress bar with ...
0
votes
0answers
135 views

Code Golf: Expression Evaluator [duplicate]

Possible Duplicate: Advanced Calculator The goal of this is to take a mathematical expression, evaluate it, and return the value. The value of the input string will never be more than 2^31-1, ...
8
votes
3answers
1k views

Did I win the lotto?

I just submitted an answer to this question, and then looked about at some news stories about the MegaMillions lottery craze going on right now in the US. This news article stated that an individual ...
2
votes
1answer
531 views

Code Golf: Make a Web Crawler

A Web Crawler is a program that starts with a small list of websites and gets the source code for all of them. It then finds all the links in those source codes, gets the website it links to then puts ...
95
votes
40answers
10k views

Tips for golfing in <all languages>

The aim of this post is to gather all the golfing tips that can be easily applied to <all languages> rather than a specific one. Only post answers that its ...
13
votes
17answers
3k views

Scrolling Marquee

Following my entry to the Obfuscated Hello World I thought it might be fun to share the underlying code. But why just show the code, lets make it a golf too! Challenge Write a script that scrolls a ...

1
200 201
202
203 204
211