Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

5
votes
4answers
102 views

The Great Pyramid of Quine

The task is a rather simple quine challenge with a twist, you must output your source code in the shape of a pyramid. The shape of a pyramid is defined below: ...
14
votes
14answers
1k views

The Highest Dice

Challenge: Here we have the first 100 items of a sequence: ...
31
votes
19answers
2k views

Faro shuffle an array

A Faro shuffle is a technique frequently used by magicians to "shuffle" a deck. To perform a Faro shuffle you first cut the deck into 2 equal halves then you interleave the two halves. For example <...
31
votes
30answers
6k views

Flatten the Array!

In this challenge, your task is to create a program which takes in a nested array and returns a single-dimensional flattened array. For Example [10,20,[30,[40]],50] ...
55
votes
108answers
13k views

Duck, duck, goose!

Remember the kids game, 'Duck, Duck, Goose'? No? Me neither. The challenge Print the word 'duck' on individual lines an indeterminate amount of times. Print the word 'goose'. Your program ends. The ...
12
votes
7answers
426 views

Mask an IP address and give its broadcast

Background Inspired by this Unix.SE question (and of course my own answer). When an IP address is specified for an interface, it is often given in this dotted-decimal form: ...
34
votes
11answers
2k views
+200

A well linked challenge

An activity I sometimes do when I'm bored is to write a couple of characters in matching pairs. I then draw lines (over the tops never below) to connect these characters. For example I might write \$...
1
vote
1answer
85 views

Return Spiral Indexes!

Spirals are cool , so are numbers, and number spirals are even cooler. But what if I want a specific number, in a specific place using xy coordinates... Challenge Using an infinite spiral moving ...
19
votes
19answers
4k views

Generate Ulam Numbers

Given an integer n (where n < 10001) as input, write a program that will output the first ...
16
votes
1answer
277 views

How lit is this room? 🔥 pt. 1

Related to this question. A room is defined to be a (not necessarily convex) non-intersecting polygon, expressed as an ordered list of 2-dimensional coordinates. A sufficiently bright lightbulb is ...
21
votes
31answers
2k views

Fold a List in Half

We are going to fold a list of integers. The procedure to do so is as follows, If the list is of even length, make a list of half of its length where the nth item of the new list is the sum of the ...
4
votes
1answer
106 views

Cell phone Charge

Challenge Taken with permission from my University Code Challenge Contest The dependence we have on mobile phones makes us charge them every night up to the maximum level of the battery, so we do not ...
31
votes
6answers
2k views

Mirror quine (or my head hurts)

I was reading Print your code backwards - reverse quine And I thought, this could be more interesting if your backwards code is also executable. So this challenge will have all the rules and ...
10
votes
24answers
2k views

Password Bishop Goodness

Derived from this, now deleted, post. Given a string, answer (truthy/falsy or two consistent values) if it constitutes a good Bishop password, which is when all the following conditions are met: it ...
19
votes
3answers
930 views

Meta-bowling Golf

Your task is to create the shortest program (A) that outputs another program (B) with the most unique bytes, which in turn outputs the original program (A). Essentially, you are golfing one half of a ...
23
votes
45answers
3k views

The 465 Arrangement

Here's the challenge. Write some code to output all the integers in a range. Sounds easy, but here's the tricky part. It will start with the lowest number, then the highest. Then the lowest number ...
18
votes
7answers
791 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: ...
16
votes
9answers
806 views

Carpet an Airport

In 2015 the Portland International Airport began the replacement of their iconic carpet. I want you to write a program to draw their old carpet in as few bytes as possible. The carpet: ...
12
votes
27answers
2k views

How many times will you have to golf a quine?

For this challenge, you must create a programme which takes an integer x and outputs its source x many times. Rules This is ...
23
votes
2answers
319 views

Drawing a tree from an array

Given a possibly nested, non-empty array of single-digit positive integers (not guaranteed unique), output the ASCII-art representation as a tree, using the box-drawing characters ...
114
votes
243answers
24k views

Shortest code to produce infinite output

Write the shortest code you can that produces an infinite output. That's all. You code will only be disqualified if it stops producing output at some point. As always in code golf, the shortest code ...
7
votes
0answers
180 views

Passwords Strong Against Bishops

Not to be confused with Password Bishop Goodness! Given a string, answer (truthy/falsy or two consistent values) if it constitutes a password which is strong against bishops. A password is strong ...
24
votes
5answers
4k views

Solving Mastermind in 6 or less moves

Your goal is to write a program that will solve any Mastermind puzzle in 6 or less moves. Background Mastermind is a board game. The goal of the game is to exactly guess the combination (colours and ...
-4
votes
0answers
42 views

java program help needed [on hold]

Write a java program to play the following game. Randomly select six of the cards Ace, Two, Three,..., Jack, Queen, and King of clubs. Place the six cards into a bag. One at a time, each player ...
32
votes
54answers
5k views

Is this number triangular?

Challenge Given a positive integer, determine whether it is a triangular number, and accordingly output one of any two constant, distinct values. Definition A triangular number is a number that can ...
17
votes
10answers
796 views

Simple encryption for people on a byte budget

Overview Your goal is to implement RC4 encryption. RC4 encryption, invented by Ron Rivest (of RSA fame), was designed to be secure, yet simple enough to be implemented from memory by military ...
43
votes
22answers
4k views

A Chiral Puzzle

A shape is chiral if no amount of rotation can make it look like it's mirror image. In this puzzle we will be writing chiral computer programs. For this puzzle we will think of a program as a ...
119
votes
120answers
35k views

Obfuscated Hello World

Create the shortest possible obfuscated program that displays the text "Hello World". In order to be considered an obfuscated program, it must meet at least two of the following requirements: Does ...
103
votes
40answers
28k views

Program that creates larger versions of itself (quine-variant)

You are to write a program that will output source code that is Larger than the original program (character wise) Will print another program larger than itself when run (i.e. the new program is also ...
36
votes
6answers
2k views

N-movers: How much of the infinite board can I reach?

Single moves The board is an infinite 2 dimensional square grid, like a limitless chess board. A piece with value N (an N-mover) can move to any square that is a distance of exactly the square root ...
188
votes
304answers
39k views

Golf you a quine for great good!

Using your language of choice, golf a quine. A quine is a non-empty computer program which takes no input and produces a copy of its own source code as its only output. No cheating -- that means ...
43
votes
22answers
11k views

Tips for golfing in C++

What general tips do you have for golfing in C++? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to C++ (e.g. "remove comments" is not ...
14
votes
4answers
540 views

Rotate every row and column in a matrix

The Challenge Given a n x n matrix of integers with n >= 2 1 2 3 4 and a list of integers with exactly ...
17
votes
4answers
638 views

Display a MIDI Track

Background MIDI files are quite different from WAV or MP3 audio files. MP3 and WAV files contain bytes representing a "recording" of the audio, while MIDI files have a series of MIDI messages stored ...
19
votes
5answers
564 views

Tetris! Final heights (Day 3)

Challenge Taken from my university code challenge contest This is actually Day 0 but yesterdays' challenge was too easy and can be a dupe of another question here. Tetris is a video game that became ...
17
votes
9answers
2k views

Tips for golfing in Clean

What general tips do you have for golfing in Clean? Please post only ideas that can be applied to code golf problems in general, and are at least somewhat specific to Clean. If you've never heard of ...
19
votes
12answers
2k views

Find a maximal rectangle of 1s

Background I want to buy an plot of land and build my house on it. My house should be rectangular, and as large as possible; however, the available plots have lots of rocky areas that I cannot build ...
46
votes
43answers
5k views

Detect heat waves

Background The Royal Netherlands Meteorological Institute defines a heat wave* as a series of at least 5 consecutive days of ≥25°C weather (“summery weather”), such that at least 3 of ...
15
votes
6answers
469 views

Panfix to parenthesized infix

Quylthulg is a language by Chris Pressey that attempts to solve the problem of infix notation using what it calls panfix: like postfix, panfix does not require the deployment of arcane contrivances ...
30
votes
11answers
2k views

Swapping heightmaps to depthmaps

Description Your task is to output a 'depthmap' - that is, a heightmap of an object but not seen from its top but from its front. For example, consider the following object as shown on the image. ...
60
votes
11answers
3k views

Reverse indentation

I've heard that your code can run faster if you indent it in reverse, so that the compiler can process it like a tree design pattern from the very top of the "branches" down. This helps because ...
10
votes
20answers
1k views

Parallel accounts (Day 2)

Challenge Taken with permission from my University Code Challenge Contest After finishing her studies a couple of months ago, Marie opened a bank account to start receiving the payment of her first ...
27
votes
33answers
4k views

How many friday the 13th in a year?

Your challenge is to write a program which, given a year, outputs the number of "Friday 13ths" in it. Rules & Details: You can take input via STDIN, or as an ...
21
votes
23answers
3k views

School moving out (Day 1)

Challenge Taken with permission from my University Code Challenge Contest For some years now, the number of students in my school has been growing steadily. First the number of students was increased ...
40
votes
124answers
5k views

Full Width Text

Full width text is text that has a space after every character, including the last one. For instance, the first sentence of this question becomes: ...
19
votes
19answers
3k views

Basic Calculator

You must write a program to evaluate a string that would be entered into a calculator. The program must accept input and output the correct answer. For languages that do not have standard input/...
7
votes
5answers
475 views
+300

9erilous 9ermutations

Note: This is an attempt at recycling guest271314's permutation question(s) There's an interesting pattern that forms when you find the differences between lexographically sorted permutations of base ...
21
votes
12answers
1k views

Indexing the Extended Fibonacci Numbers

You've probably heard of Fibonacci numbers. Ya know, that integer sequence that starts with 1, 1, and then each new number is the sum of the last two? ...
391
votes
733answers
114k views

“Hello, World!”

So... uh... this is a bit embarrassing. But we don't have a plain "Hello, World!" challenge yet (despite having 35 variants tagged with hello-world, and counting). While this is not the most ...
109
votes
221answers
24k views

Fibonacci function or sequence

The Fibonacci sequence is a sequence of numbers, where every number in the sequence is the sum of the two numbers preceding it. The first two numbers in the sequence are both 1. Here are the first ...