2022 Developer Survey is open! Take survey.

Questions tagged [whitespace]

For challenges related to the processing and placement of whitespace characters (mainly, but not limited to spaces, tabs and line feeds), like challenges related to indentation. For challenges about the esoteric programming language Whitespace, use [whitespace-language] instead.

Filter by
Sorted by
Tagged with
16 votes
17 answers
1k views

Capture the longest leading whitespace substring from lines

The Challenge Given a multiline string, return the longest substring of leading whitespace present in every line, ignoring empty lines or lines composed only of whitespace. If input is empty or ...
user avatar
23 votes
5 answers
1k views

Ungolf my tinylisp code

I like golfing in tinylisp: (d M(q((x)(i x(i(disp x)0(M x))0 But I also like posting explanations with nicely formatted code: ...
user avatar
  • 31.8k
20 votes
15 answers
5k views

Write a Stack Exchange compliant brainfuck explainer

You are to take a string representing a piece of brainfuck code and Explanations, containing only printable ASCII characters and newlines ( to ...
user avatar
  • 2,493
1 vote
0 answers
54 views

Reverse a sentence word by word [duplicate]

The setting "Well I actually wrote the sql library they, the maintainers actually.." "Right, but do you have any experience working with django?" " ...no I don't use ...
user avatar
  • 111
5 votes
19 answers
324 views

How many spaces are there? [duplicate]

Your task is to input a string, and output the number of spaces in the string. This is code-golf, so least number of bytes win. Your Test Cases Double quotes are not part of the test cases. ...
user avatar
  • 3,704
0 votes
1 answer
104 views

Remove indentation [duplicate]

Write a program which removes any common leading spaces from the input string. For example, if the least indented line started with 3 spaces, and every other line has ...
user avatar
15 votes
22 answers
3k views

Implement a whitespace golfer

Some two-dimensional esolangs, such as Forked, and some non-esolangs, such as Python, can sometimes require spaces before lines of code. This isn't very golfy. Also, I'm lazy and writing a 2d lang ...
user avatar
  • 13.2k
9 votes
2 answers
286 views

Reindent Java/C/C++/etc. code

Write a program that adds or removes whitespace to format code nicely. Rules for what the code should look like when you're done: No line should contain more than one of ...
user avatar
  • 2,376
5 votes
1 answer
173 views

Expand elastic tabs

Background The tabs versus spaces war in programming has been going on a long time, basically because spaces are too low-level to have all the properties you'd want for alignment and indentation, but ...
user avatar
31 votes
50 answers
3k views

Reversing of Words

Sona is in her house with her 10 year old daughter. She needs to go to school to bring back another child from school, as school is over at 2 pm. It's hot outside, so she wants to leave her younger ...
user avatar
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 ...
user avatar
17 votes
20 answers
2k views

Get rid of whitespace on otherwise empty lines

Ah, yet another of my selfish uses of this Stack. Being a Chromebook owner, I'm a frequent user of the Ace IDE, the editor used by Cloud9. It has lots of tools for dealing with excess whitespace, but ...
user avatar
18 votes
46 answers
3k views

Create a codeblock tool

When using Markup, like on the SE network, an indentation of four spaces before a line of text denotes it as part of a code block, as I hope you know. If you don't, here's an example (with ...
user avatar
18 votes
15 answers
2k views

Significant Whitespace: Robbers

This is part of a Cops and Robbers challenge. Go here for the cops' part. For the purpose of this challenge, we'll define whitespace as only linefeeds (0x0A) and spaces (0x20). Note that most ...
user avatar
52 votes
25 answers
5k views

Significant Whitespace: Cops

For the purpose of this challenge, we'll define whitespace as only linefeeds (0x0A) and spaces (0x20). Note that most languages and regex flavours consider many other characters as whitespace as well, ...
user avatar
8 votes
3 answers
359 views

Line ending conversion program

Write a program or function that alters the file at a user-specified filename via replacing all instances of UNIX line endings with Windows line endings and vice versa. Clarifications: For the ...
user avatar
32 votes
20 answers
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 ...
user avatar
25 votes
15 answers
5k views

End the tabs versus space war

End the tabs versus space war So, there has been a great deal of debate of whether to use tabs or spaces to indent/format code. Can you help the university settle the dispute, by going to an ...
user avatar
13 votes
2 answers
345 views

Will it ​float?

The challenge Given a 2d string representing the bottom of a boat as an input, you must determine whether or not the boat will float. This 2D string can be in whatever format is most convenient. (...
user avatar
53 votes
10 answers
4k views

Unfolding the Hexagony source code

Introduction If you're not familiar with Hexagony, it's an esoteric language created by Martin Büttner. The thing is that this language accepts multiple forms for the program. The following programs ...
user avatar
  • 43.3k
5 votes
5 answers
1k views

Remove Whitespace from a Java Program [closed]

In this challenge, you will be given the source code of a Java program. Your task is to write a function or full program that will remove the whitespace from this program. The whitespace-removed ...
user avatar
  • 7,406
32 votes
5 answers
1k views

Break tabs in half

Holy wars have been fought over spaces vs. tabs. (And of course spaces, being objectively superior, won.) —Alex A. Some people still refuse to accept that which is clearly supreme. You've just ...
user avatar
  • 70.5k
38 votes
27 answers
2k views

Aligning Lines!

Aligning Lines! Given a character and a multiline string, your job is to pad each line of the string so they line up among the given delimiter. Examples Input: ...
user avatar
  • 28.4k
27 votes
15 answers
4k views

Goodness, it's covered in tabs!

Space indentation users, unite! We must fight against all the lowly tab users! Your mission (should you choose to accept it) is to write a program or function that takes in two arguments: A string: ...
user avatar
44 votes
5 answers
2k views

My god, it's full of spaces!

Some people insist on using spaces for tabulation and indentation. For tabulation, that's indisputably wrong. By definition, tabulators must be used for tabulation. Even for indentation, tabulators ...
user avatar
  • 206k
18 votes
7 answers
499 views

Numbering Hierarchical Outlines

Write a program that takes in a string where every line consists of the character 0 indented by some number of spaces. The top line is not indented and every other ...
user avatar
20 votes
30 answers
3k views

Remove common leading spaces

When coding in Python, sometimes you want a multiline string within a function, e.g. def f(): s = """\ Line 1 Line 2 Line 3""" (The backslash is ...
user avatar
  • 60.9k
23 votes
9 answers
1k views

Formatting a Lisp-like Syntax

Background (Based on a true, heart-wrenching story) In my time, I've played around with Lisp and similar languages often. I've written with them, ran them, interpreted them, designed them, and made ...
user avatar
  • 5,342
83 votes
50 answers
7k views

Telescopic Parentheses

Consider a non-empty string of correctly balanced parentheses: (()(()())()((())))(()) We can imagine that each pair of parentheses represents a ring in a ...
user avatar
34 votes
4 answers
2k views

Code Explanation Formatter

Successful code golf submissions are, by nature, filled with crazy symbols all over the place. To make their submission easier to understand, many code-golfers choose to include an explanation of ...
user avatar
  • 28.5k
70 votes
12 answers
7k 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 ...
user avatar
  • 70.5k
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, ...
user avatar
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 ...
user avatar
  • 9,165
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): ...
user avatar
50 votes
8 answers
3k views

Avoiding Rivers

Background In typography, rivers are visual gaps in a block of text, which occur due to coincidental alignment of spaces. These are particularly annoying since your brain seems to pick them up more ...
user avatar
12 votes
7 answers
2k views

C code indenter

Situation: You are a high school teacher, teaching your computing class how to write C programs. However, since it is just the beginning of the term, you haven't taught them about the importance of ...
user avatar
  • 8,936
10 votes
3 answers
565 views

Expand tabs (implement expand(1))

Your task this time is to implement a variant of the POSIX expand(1) utility which expands tabs to spaces. Your program is to take a tabstop specification and then ...
user avatar
  • 7,248
8 votes
4 answers
781 views

Pretty Printing Parentheses [closed]

The worst part about long lines or code or math equations are the parentheses. Nobody wants to read through 2x(3y+4*abs(x^[2*e^x])-5{3(x+y)-5})! So, the goal of ...
user avatar
  • 4,194
20 votes
10 answers
2k views

Exploit "free whitespace"

Suppose a codegolf challenge doesn't count whitespace in the length of your program. Cheat this system by encoding your script into whitespace, and golf a script which decodes and executes embedded ...
user avatar
  • 9,537
17 votes
23 answers
3k views

Indent a string using given parentheses

Given the following input to the program: List of block start characters List of block end characters A string to format format the string with the blocks delimited by the two character sets ...
user avatar