Questions tagged [source-layout]
For challenges that involve the physical layout or physical manipulation of source-code.
82
questions
149
votes
155
answers
21k
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 ...
53
votes
70
answers
11k
views
I reverse the source code, you negate the output!
Your task, if you wish to accept it, is to write a program that outputs a non-zero number(can be integer or float). The tricky part is that if I reverse your source code, the output must be the ...
30
votes
4
answers
2k
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 ...
43
votes
68
answers
8k
views
I reverse the source code, you negate the input!
Blatant rip-off of a rip-off. Go upvote those!
Your task, if you wish to accept it, is to write a program/function that outputs/returns its integer input/argument. The tricky part is that if I ...
27
votes
39
answers
6k
views
I reverse the source code, you reverse the input!
Yet another blatant rip-off of a rip-off of a rip-off. Go upvote those!
Your task, if you wish to accept it, is to write a program/function that outputs/returns its string input/argument. The tricky ...
166
votes
5
answers
17k
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 ...
103
votes
30
answers
16k
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):
...
50
votes
51
answers
5k
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 ...
83
votes
17
answers
7k
views
Fault-Tolerant Hello World
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 ...
76
votes
15
answers
6k
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:
...
66
votes
36
answers
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 ...
56
votes
25
answers
8k
views
DON'T... do NOT lowercase UPPERCASE this!
Write a program that outputs its input unchanged. However:
If all uppercase characters are removed from the program, it lowercases all uppercase letters.
If all lowercase characters are removed from ...
56
votes
24
answers
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, ...
44
votes
19
answers
6k
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 ...
40
votes
30
answers
4k
views
Code close to the challenge: Sum of integers
This is a simple challenge:
Given a sequence of integers, find the sum of all integers in it.
But with a twist.
Your score is the Levenshtein distance between your code and the following phrase (The ...
28
votes
24
answers
7k
views
I shift the source code, you shift the input!
Sandbox
A spin-off of a rip-off of a rip-off of a rip-off of a rip-off. Go upvote those!
Your task, if you accept it, is to write a program/function that outputs/returns its input/argument. The ...
22
votes
7
answers
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 ...
20
votes
15
answers
4k
views
I multiply the source, you (probably) multiply the output!
Task
The task is to write a program that outputs a consistent but otherwise arbitrary positive integer \$x\$ (so strictly greater than 0). Here's the catch: when the source is repeated \$N\$ times (...
16
votes
15
answers
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 ...
14
votes
17
answers
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 as ...
10
votes
5
answers
1k
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 your ...
144
votes
90
answers
23k
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 ...
46
votes
3
answers
5k
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, ...
41
votes
9
answers
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 ...
30
votes
65
answers
3k
views
Palindrome Hello, World
Your task is to create a program that prints "Greetings, Planet!" exactly to the console. Seems simple enough, right? Well, here's the trick. The code must be a palindrome, meaning it reads from right ...
29
votes
18
answers
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 ...
27
votes
21
answers
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 ...
27
votes
7
answers
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
...
23
votes
7
answers
3k
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)
...
22
votes
6
answers
777
views
Transposes and Diagonals
For this challenge, you should write a program or function which outputs the diagonals of a given square matrix. However, if you transpose the rows and columns of your solution's source code, it ...
21
votes
3
answers
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 ...
11
votes
9
answers
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 ...
10
votes
44
answers
3k
views
Which character to change (Robbers)
Cops thread
Robbers, your task is to crack a cops answer. Reveal the character that should be changed and what it should be changed to too.
Please notify the cop if you cracked their challenge.
The ...
8
votes
13
answers
598
views
Just Twice Is Nice
Let's have string multiplication to take a string and a positive number and concatenate that string that many times. In Haskell:
...
124
votes
21
answers
18k
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 ...
108
votes
36
answers
12k
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 permutations.
Choose your ...
86
votes
64
answers
7k
views
From Programming Puzzles to Code Golf
Your task is to write a program that outputs the exact string Programming Puzzles (trailing newline optional), but when all spaces, tabs, and newlines are removed ...
42
votes
8
answers
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 the 40 ...
41
votes
19
answers
4k
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 ...
40
votes
12
answers
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 \$...
40
votes
25
answers
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 ...
40
votes
29
answers
5k
views
Double-time is not double time
Based on this challenge.
In the rhythm game osu!, the difficulty modifier "Double-time" actually only increases the speed by 50%.
Your task, is to write a program that outputs a positive ...
39
votes
29
answers
4k
views
Cat, Quine, Hello World
Write a cat program, a quine, and a Hello World in the same language such that when two specific programs of the three are concatenated in a certain order, you get the third program. It does not ...
38
votes
25
answers
6k
views
I transpose the source code, you transpose the input!
Rip-off of a rip-off of a rip-off of a rip-off. Go upvote those!
Your task, if you wish to accept it, is to write a program/function that outputs/returns its input/argument¹. The tricky part is that ...
38
votes
14
answers
3k
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. ...
37
votes
28
answers
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] \...
35
votes
17
answers
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 ...
35
votes
21
answers
4k
views
Longest Non-Repeating Substring
Given a string as input find the longest contiguous substring that does not have any character twice or more. If there are multiple such substrings you may output either. You may assume that the ...
34
votes
18
answers
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.
...
34
votes
4
answers
3k
views
Make The Finest Magic Code Square
In math a magic square is an N×N grid of numbers from 1 to N2 such that every row, column, and diagonal sums to the same total. For example here's a 3×3 magic square:
In this challenge we'...