Stack Exchange Network

Stack Exchange network consists of 175 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 [source-layout]

For challenges that involve the physical layout or physical manipulation of source-code.

114
votes
126answers
15k views

I double the source, you double the output!

Your task, if you wish to accept it, is to write a program that outputs a positive integer (higher than 0). The tricky part is that if I duplicate your source code, the output must be double the ...
26
votes
3answers
1k views

Create a rotating quine

A rotation of a string is made by splitting a string into two pieces and reversing their order, for example "world! Hello," is a rotation of ...
153
votes
4answers
13k views

Hyperprogramming: N+N, N×N, N^N all in one

Write a program that takes in a number N from 1 to 9 inclusive. In its native form your program should output N+N. E.g. output 2 if N is ...
98
votes
25answers
15k views

Print a Negative of your Code

Consider a square of printable ASCII characters (code points 0x20 to 0x7E) for side length N, like the following (here, N = 6): ...
66
votes
7answers
6k views

Fault-Tolerant Hello World (a.k.a. the Interview)

At the end of your interview, the Evil Interviewer tells you, "We make all of our applicants take a short coding test, to see if they really know what they are talking about. Don't worry; it's easy. ...
63
votes
24answers
7k views

Write a Rectangular Program that Outputs the Number of Times it was Rotated

The title says it all. Your goal is to write a program that forms a w×h rectangle of characters that can be rotated and re-run to output the number of 90° Counter-Clockwise (CCW) rotations that have ...
74
votes
11answers
5k views

Error 404: Character Not Found

Scenario One of your friends is struggling on a homework assignment. He needs a simple program which prints the first 404 natural numbers: ...
53
votes
23answers
6k views

Significant Whitespace

We define whitespace to be any of the three characters, tab (0x09), newline (0x0A) or space (0x20). For this challenge, you're to write two programs or functions in the same programming language, ...
43
votes
18answers
5k views

Create a square of increasing size by replicating the initial code

Your assignment is to write a program of even length, that prints an ASCII-art square (described below), that increases its side length by 1 unit each time the original source code is pasted in the ...
48
votes
47answers
4k views

Third time the charm

Your task, if you wish to accept it, is to write a program that outputs a positive integer (higher than 0). If the source code is duplicated the output must remain the same. The tricky part is that if ...
16
votes
17answers
2k views

Self-Mutilating Program

Simply put, your goal is to create a complete program that modifies its own source code until every character of the source is different than what it started as. Please include the beginning source ...
16
votes
15answers
2k views

Hidden Inversions (Robbers' Thread)

This is a cops-and-robbers puzzle, the cops' thread can be found here. Your task will be to find an anagram of the provided programs in the cops' thread that performs its left inverse. Once you ...
42
votes
4answers
4k views

Code that runs the Game of Life on itself

Write two rectangular blocks of code, each w characters wide and h characters tall, that implement Conway's Game of Life when arranged in a grid. (w and h may be any positive integers) For example, ...
129
votes
71answers
16k views

Hello, World! (Every other character)

Write a program that prints "Hello, World!". But also, if you take only the first, third, fifth, etc. characters of your program, the resulting program should still print "Hello, World!". If your ...
25
votes
20answers
3k views

Shape Identifying Program

Your task is to build a program that identifies the shape of the input. The shapes to be identified can be any of the following: Square To be identified as a square, the source must have lines of ...
11
votes
9answers
1k views

Everyone Ought to Have a Friend

An isolated character is a character (other than a newline) that doesn't have an adjacent character of the same type. Adjacent characters can be to the left, the right above or below, but not ...
22
votes
6answers
2k views

Mutual Negative Quines

This was inspired by Print a Negative of your Code and Golf a mutual quine. Consider a rectangle of characters, that meet the following restrictions: Consists solely of printable ASCII characters ...
19
votes
6answers
2k views

Run the Nth characters to get N

Write the shortest program possible such that when you combine the first character and every Nth character after it into a new program, the output is N. This must work for N = 1, 2, ..., 16. Another ...
10
votes
6answers
957 views

It's Anagram Quine, not just Quine!

The Task In this challenge, your task is to write a program, which takes in no input, with as many anagrams that are quine of themselves as possible. Your score will be the number of anagrams of ...
28
votes
18answers
5k views

Take a stand against long quine lines

or: Build a vertical quine Inspired by Take a stand against long lines. Your task is to build a vertical quine with as short a line length as possible. Scoring Shortest line length (excluding ...
23
votes
7answers
2k views

Code Crosswords

This is a cops-and-robbers challenge. Answer here if you are a cop (crossword maker), answer the companion question if you are a robber (crossword solver). You may take on both roles. Cops (Puzzlers) ...
114
votes
40answers
16k views

Write a program that always outputs “2012” - even if it's modified!

This idea is not mine, though I don't know where it originated. I once met it in a programming contest very long ago (1998, if I remember correctly). The task is to write a program in your favorite ...
102
votes
32answers
11k views

What are the five most powerful characters in your language?

Choose any five characters your language supports. There are 5! = 5×4×3×2×1 = 120 ways these can be arranged into a 5-character string that contains each character once; 120 ...
39
votes
19answers
3k views

Program template for printing *any* string

Write a program with the following properties: When run as-is, the program produces no output (i.e. 0 bytes of output). There is a location within the program (of your choice: it could be at the ...
37
votes
28answers
4k views

Is the matrix centrosymmetric… and so is the code?

Defintion A centrosymmetric matrix is a square matrix that is symmetric about its center. More rigorously, a matrix \$A\$ of size \$n \times n\$ is centrosymmetric if, for any \$i,\: j \in ([1, n] \...
28
votes
7answers
2k views

Source Code Metamorphosis

mbomb007 asked us to make a self mutilating program. Its an interesting challenge, but I personally don't like to encourage my programs to be self-mutilating. I like to think that, at the heart of ...
40
votes
8answers
6k views

40 Numbers in 9 Bytes

There are 40 ways a directed Hamiltonian path can be arranged on a 3×3 grid: This graphic (thanks Sp3000!) shows only the 20 undirected paths. Traverse each colored line in both directions for ...
34
votes
18answers
4k views

Jumblers vs Rebuilders: Coding with Tetris Bricks

In traditional Tetris, there are 7 distinct tetromino bricks, each denoted by a letter similar to its shape. ...
22
votes
9answers
2k views

Caesar-Cypher-Mania

The Caesar Cypher is a very simple substitution cypher where each letter is shifted by a fixed offset (looping around Z to A). Similarly, we can also a Caesar cypher for the set of printable ASCII ...
41
votes
9answers
5k views

Shifting-Oriented Programming

A string can be shifted by a number n by getting the byte value c of each character in the string, calculating ...
28
votes
29answers
4k views

Program your favorite phrase

Pick a quote or phrase that is exactly 5 words long, such as Programming puzzles and code golf!. Write a program that, when appended to itself n times, outputs the ...
23
votes
28answers
3k views

Take a stand against long lines

Recently, someone proposed more stringent limits for Python's default line length: Clearly, no program should ever use more than 80 characters per line, for a whole host of reasons. First and ...
40
votes
12answers
2k views

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 \$...
28
votes
13answers
2k views

Make a Geiger Counter

A Geiger counter is a device that is used to detect radiation. We will be making a Geiger counter program. As we all know, when radiation hits a computer program it removes exactly 1 byte at random. ...
20
votes
2answers
1k views

90° Self-Rotating Program

Introduction Write a complete program that rotates a rectangular block of ASCII characters 90 degrees clockwise. When the program itself is rotated 90 degrees clockwise, it rotates a block of ASCII ...
30
votes
24answers
2k views

Join N copies of a snippet to produce N^2 characters

Challenge Write the shortest snippet of code possible such that, when N copies of it are concatenated together, the number of characters output is N2. N will be a positive integer. For example if ...
27
votes
5answers
2k views

Radioactive Quines

A radioactive quine is a quine-like program that has an even number of characters and, when run, outputs itself with exactly half of its characters removed. The output itself may be a radioactive ...
16
votes
17answers
2k views

“Hello, World!” (Every other character, Part 2)

As a kind of part 2 to Hello, World! (Every other character), write a program such that all three of these programs print "Hello, World!": the entire program, the 1st, 3rd, 5th, etc. characters of ...
38
votes
22answers
4k views

Hide the Needle in the Haystack (Cops)

This is part of a cops-and-robbers challenge. Go here for the robbers' part. The Cops' Challenge You should write a program or function in a language of your choice, which outputs the string ...
22
votes
3answers
1k views

Write a square program that outputs the number of times it has been “unrolled”

Consider a square block of text, N characters wide by N tall, for some odd integer N greater than 1. As an example let N = 5 and the text be: ...
18
votes
7answers
1k views

Russian Nesting Quine

A Russian nesting doll, more commonly known as a Matryoshka doll, is a doll which contains a smaller version of itself, which then contains another smaller version of itself, which contains a smaller ...
35
votes
17answers
3k views

Hidden Inversions (Cops' Thread)

This is a cops-and-robbers puzzle the robbers' thread can be found here. Your task will be two write two programs (or functions) such that they are anagrams of each other and one performs the left ...
18
votes
21answers
2k views

The repetitive byte counter

Your task is to write a non-empty program / function of byte count L, which, when repeated M times, checks whether a given positive integer N is equal to L × M. You should, in theory, support an ...
18
votes
20answers
2k views

Find the Needle in the Haystack (Robbers)

This is part of a cops-and-robbers challenge. Go here for the cops' part. The Robbers' Challenge A cop's answer can be cracked by removing any subset of characters from the Haystack program, so that ...
17
votes
3answers
2k views

Write a program that always prints N when it is shifted N times up the ASCII alphabet

Write a program using only printable ASCII characters that takes no input. For reference, here are the 95 printable ASCII characters in order: ...
11
votes
5answers
602 views

Code Crosswords - Solutions

This is the companion question for Code Crosswords. Robber answers go here. See Where should we put robbers? for meta-info.
10
votes
2answers
832 views

Positional Awareness

Positional Awareness Your task is to generate a program that, for every permutation of its characters (which includes the original program), outputs the positions of every character relative to the ...
7
votes
7answers
315 views

Twice as long, half the price [duplicate]

Related: I double the source, you double the output! When Steve Jobs launched the iPhone 3G, the slogan said Twice as fast, half the price I changed the word fast to long to better represent this ...