Questions tagged [source-layout]
For challenges that involve the physical layout or physical manipulation of source-code.
151
questions
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 ...
-8
votes
28answers
591 views
Reversible program
Objective
Write a program that outputs some printable ASCII characters. The trick is that if the program is reversed byte-by-byte, it must output the same thing in the reverse order, byte-by-byte, ...
8
votes
7answers
338 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 ...
3
votes
33answers
3k views
Code 3k to Codee k
Write some code...
Write a program that takes no input and outputs an integer n which is a multiple of 3. So ...
38
votes
18answers
3k views
Prime Up your code
Input
no input for this challenge
The Challenge
Write a code that outputs:
The first 10 prime numbers whose sum of their digits equal the number of bytes of your code
Examples
Let's say your code is <...
7
votes
4answers
671 views
Unfurling-Safe Quine
Write a proper quine containing at least one newline/linefeed whose every unfurling is either itself a proper quine or outputs the original quine. Your answer can mix and match outputting itself and ...
9
votes
7answers
808 views
Code-Golf Assembly Line
Note: This challenge has nothing to do with actual assembly language.
As the head of Code-Golf Factory Inc., you must create an assembly line to generate a specific piece of code. Today, the foreman ...
9
votes
32answers
2k views
Square and square [closed]
Squares looks symmetric, and so are the required codes.
Objective: Write a program whose source code is a solid square (N lines with N printable, non-whitespace characters each line) and prints a ...
25
votes
26answers
1k views
Cardinal Code Challenge
Task
You're in charge of making a compass, of sorts.
Imagine your source code as the compass "needle" where running at different orientations produces distinct output.
Supported source code ...
36
votes
24answers
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 ...
139
votes
141answers
19k 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 ...
1
vote
9answers
160 views
Given a string and integer n, split the string at n characters, and print as follows: [duplicate]
Given a string and integer n, split the string at n character, and print as follows:
Ex)
laptop 3 should print lap top
...
18
votes
18answers
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 ...
6
votes
0answers
102 views
Every Nth Char in Source Outputs N [duplicate]
Heavily inspired by Hello, World! (Every other character)
Write a program that outputs 1. When the first, third, fifth, etc. chars are removed, it outputs ...
22
votes
6answers
698 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 ...
135
votes
80answers
20k 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 ...
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 ...
10
votes
5answers
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 ...
66
votes
5answers
5k views
Powerprogramming: O(1^N), O(N^1), O(2^N), O(N^2) all in one
Write a program (or function) that exhibits four common big O time complexities depending on how it is run. In any form it takes in a positive integer N which you may assume is less than 231.
When ...
80
votes
60answers
6k 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 ...
7
votes
10answers
1k views
Break my source file! [duplicate]
Challenge
Create a program that, when run, changes the contents of the source file. This means that you can delete/add/change characters in the source file, but you can't delete the (source) file ...
25
votes
14answers
3k views
Reuse your code!
In this challenge we try to solve two important problems at once. They are:
Given integers \$a\$ and \$b\$, tell if \$a^b-1\$ is a prime number.
Given integers \$a\$ and \$b\$, return \$a\choose b\$.
...
36
votes
5answers
1k views
Letter, Number, Symbol, Space, Repeat
There are 97 ASCII characters that people encounter on a regular basis. They fall into four categories:
Letters (52 total)
...
24
votes
16answers
2k views
Running Merge Conflict
When using a tool such as git to merge two files, a conflict could be detected and added to the result of the merge.
A merge of these two files:
my file:
...
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 ...
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 ...
5
votes
1answer
287 views
Shrink your language's character set [duplicate]
We often get restricted-source questions here on PPCG that favour submitting solutions using only a subset of characters (sufficiently so that there's a tag printable-ascii that identifies a ...
17
votes
7answers
955 views
Make an interweaving quine
Your task is to create a program that, when run, returns itself as output (this is known as a quine). However, this quine must, when it is copied n times, returns ...
10
votes
2answers
862 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 ...
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:
...
105
votes
35answers
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 ...
32
votes
20answers
2k views
Figure and Ground
Source: Wikipedia
For this challenge, you should write two programs which resemble the figure and ground of the above image, such that one of them prints figure ...
41
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 ...
8
votes
10answers
420 views
Make your program sequential! [closed]
Your task, if you choose to accept it, is simple.
Objective
You must make a program that, when run, prints some (as many as you want) terms in a sequence that you choose. The sequence must be a ...
12
votes
2answers
4k views
Primes with a twist
Note: this is heavily inspired by this question.
Task:
Your task is to generate the nth prime, when each character of your program is repeated ...
27
votes
2answers
781 views
Hyper about quines
Inspired by Hyperprogramming: N+N, N×N, N^N all in one.
Thanks to @MartinEnder and @trichoplax for their help in the sandbox.
Definitions
Hyperquines
Define a hyperquine of order n as a quine-...
161
votes
5answers
15k 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 ...
0
votes
1answer
331 views
āHHeelllloo,, EEaarrtthh!!ā [duplicate]
Much like this challenge, write a program or function that takes no input and prints or returns the string
Hello, Earth!
with an optional trailing newline.
The ...
20
votes
2answers
551 views
Chuck Norris vs Travelling Salesman
Introduction
Almost everyone is familiar with the Travelling Salesman Problem (TSP). The task is to, given a list of N cities, find the minimum Hamiltonian cycle ...
17
votes
15answers
2k views
Write a program that outputs the number of times it has been run [duplicate]
In a programming language of your choice, write a full program that, when run, prints a positive integer N and then modifies its own source file such that the next time it is run it will print N+1.
...
12
votes
2answers
439 views
Right and tfeL truncatable primes
A right-truncatable prime is a prime where every prefix is a prime (in base 10). A left-truncatable prime is exactly the opposite, where every postfix is a prime (primes that start with 0 aren't ...
15
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:
...
18
votes
7answers
943 views
Normal and visual string reversion
Write some code that acts as a cat program. That is, to input a string and output it as is. But the normal reversion of your code must output the normal reversion of the input string. And the visual ...
47
votes
3answers
4k views
Coding Around The Clock
Write a single line program two or more characters long that contains no line terminators and takes no input. For example, your program might be:
MyProgram
When ...
14
votes
11answers
2k views
Double-duty quine: quine!dlroW ,olleH
Write a program that will output its own source code when run, and nothing else. Seems easy, right?
The catch is that when the source code is reversed, your program must output "Hello, World!" ...
13
votes
21answers
1k views
Sequential Multiplication
Your objective is to write a program that takes an input, and, when chained together N times, performs "sequential multiplication". What is sequential ...
32
votes
19answers
2k views
Inverse function
Wouldn't it be neat if programming functions could be inverted, just like the mathematical function they implement?
Write a function (or program) that takes one input ...
7
votes
3answers
163 views
The confused twister
The basic idea is to write a program that twists itself, and the twisted version untwists itself. The first program will just be the twisting algorithm described here, and when given its own source ...
31
votes
9answers
7k views
Build a twisted “Hello world!”
Your job is quite simple, write a program that prints Hello, world!, that when twisted creates a program that prints Twister!.
...
21
votes
2answers
488 views
Compile Regexes (By Substitution)
Your task is to compile regexes... by specifying a substitution for each character in a regex.
Regexes
The regexes support these
...