Skip to main content

Questions tagged [source-layout]

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

Filter by
Sorted by
Tagged with
171 votes
6 answers
19k views

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 ...
Calvin's Hobbies's user avatar
146 votes
92 answers
25k views

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 ...
pommicket's user avatar
  • 3,187
128 votes
21 answers
19k views

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 ...
Vilx-'s user avatar
  • 1,641
111 votes
36 answers
12k views

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 ...
Calvin's Hobbies's user avatar
105 votes
30 answers
16k views

Consider a square of printable ASCII characters (code points 0x20 to 0x7E) for side length N, like the following (here, N = 6): ...
Martin Ender's user avatar
88 votes
64 answers
8k views

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 ...
user avatar
87 votes
20 answers
8k views

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 ...
user avatar
80 votes
16 answers
6k views

Scenario One of your friends is struggling on a homework assignment. He needs a simple program which prints the first 404 natural numbers: ...
FlipTack's user avatar
  • 14.7k
69 votes
6 answers
5k views

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 the ...
Calvin's Hobbies's user avatar
68 votes
36 answers
8k views

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 ...
Calvin's Hobbies's user avatar
64 votes
44 answers
10k views

Task Create a program that calculates the factorial of a number using no built-in factorial functions. Easy? The catch is that you must write your entire program (including testing it) in haiku form. ...
TheDoctor's user avatar
  • 8,003
58 votes
72 answers
12k views

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 ...
TwilightSparkle's user avatar
57 votes
26 answers
9k views

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 ...
darrylyeo's user avatar
  • 7,937
55 votes
24 answers
7k views

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, ...
Martin Ender's user avatar
51 votes
51 answers
5k views

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 ...
workoverflow's user avatar
  • 1,045
50 votes
24 answers
4k views

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 ...
Wheat Wizard's user avatar
  • 103k
48 votes
16 answers
6k views

Write a rectangular block of text that when arranged into a Sierpinski carpet, using same-sized blocks of spaces for the empty portions, creates a program that outputs the iteration number of the ...
Calvin's Hobbies's user avatar
48 votes
3 answers
4k views

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 ...
Calvin's Hobbies's user avatar
48 votes
3 answers
5k views

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, ...
Calvin's Hobbies's user avatar
47 votes
14 answers
7k views

Pick your favorite 6 letter common English word that has no repeated letters, such as wombat. Write a program in an N×N grid of characters without comments such ...
Calvin's Hobbies's user avatar
45 votes
20 answers
6k views

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 ...
user avatar
44 votes
69 answers
9k views

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 ...
Adám's user avatar
  • 31.8k
44 votes
34 answers
5k views

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 ...
user avatar
43 votes
8 answers
6k views

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 ...
Calvin's Hobbies's user avatar
42 votes
19 answers
4k views

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 start,...
user avatar
41 votes
9 answers
5k views

A string can be shifted by a number n by getting the byte value c of each character in the string, calculating ...
Laikoni's user avatar
  • 26.4k
41 votes
25 answers
5k views

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 ...
Martin Ender's user avatar
41 votes
13 answers
2k views

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 \$...
Wheat Wizard's user avatar
  • 103k
40 votes
31 answers
5k views

Challenge Write \$2 \le n \le 10\$ distinct, valid non-halting full programs in your language of choice. If all of them are concatenated in order, the resulting full program should be a valid halting ...
Bubbler's user avatar
  • 79.3k
40 votes
29 answers
6k views

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 ...
Mayube's user avatar
  • 11.8k
40 votes
31 answers
5k views

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 ...
Beefster's user avatar
  • 10k
40 votes
20 answers
4k views

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 <...
user avatar
39 votes
14 answers
3k views

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. ...
Wheat Wizard's user avatar
  • 103k
38 votes
25 answers
7k views

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 ...
Adám's user avatar
  • 31.8k
37 votes
28 answers
5k views

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] \...
Mr. Xcoder's user avatar
  • 42.9k
36 votes
5 answers
1k views

There are 97 ASCII characters that people encounter on a regular basis. They fall into four categories: Letters (52 total) ...
Calvin's Hobbies's user avatar
35 votes
17 answers
3k views

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 ...
Wheat Wizard's user avatar
  • 103k
35 votes
4 answers
3k views

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'...
Calvin's Hobbies's user avatar
35 votes
21 answers
4k views

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 ...
Wheat Wizard's user avatar
  • 103k
35 votes
3 answers
3k views

In the game Tetris, there are 7 types of bricks or Tetriminoes, which are mathematically known as tetrominoes because they are all made with 4 square segments: The have the names I, J, L, O, S, T, and ...
Calvin's Hobbies's user avatar
34 votes
22 answers
5k views

The task here is pretty simple. You should write a program that takes a string as input and outputs it (that is a cat program). Additionally when the \$n\$th byte of your program is removed (without ...
Wheat Wizard's user avatar
  • 103k
34 votes
18 answers
5k views

In traditional Tetris, there are 7 distinct tetromino bricks, each denoted by a letter similar to its shape. ...
Calvin's Hobbies's user avatar
34 votes
9 answers
5k views

I have one hundred vaults, each one within another. Each vault has a password, consisting of a single number. 95 43 81 89 56 89 57 67 7 45 34 34 78 88 14 40 81 23 26 78 46 8 ...
Ypnypn's user avatar
  • 10.9k
33 votes
30 answers
3k views

Your task is to write a program or function. Its output/return value must follow these rules: The program outputs 1 The program repeated ...
rydwolf's user avatar
  • 19.3k
33 votes
29 answers
5k views

There have been a couple of challenges involving doubling source code: here and here. The task we have here is a bit harder, but should be doable in almost every language. In this challenge, you will ...
GammaFunction's user avatar
33 votes
17 answers
5k views

Challenge Make two programs, A and B, which are both cat programs in the same language. When concatenated, AB (also in the same language) should be a quine. For example, suppose ...
Beefster's user avatar
  • 10k
33 votes
11 answers
2k views

...at least for some definition of "self-modification". The Task In this challenge, your task is to write three strings A, B ...
Zgarb's user avatar
  • 43.2k
32 votes
57 answers
7k views

It's a normal truth machine but instead of taking input, it uses the first character of the program. Thus, internal. The 0 and 1 are plain characters, i.e. ASCII code 0x30 and 0x31 respectively. ...
PkmnQ's user avatar
  • 2,723
32 votes
19 answers
3k views

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 ...
Drathier's user avatar
  • 1,859
32 votes
30 answers
2k views

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 the ...
Calvin's Hobbies's user avatar