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.
36
questions
5
votes
19answers
315 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.
...
0
votes
1answer
97 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 ...
15
votes
22answers
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 ...
10
votes
2answers
275 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 ...
5
votes
1answer
168 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 ...
30
votes
47answers
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 ...
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 ...
17
votes
20answers
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 ...
18
votes
46answers
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 ...
18
votes
15answers
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 ...
52
votes
25answers
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, ...
8
votes
3answers
354 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 ...
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 ...
24
votes
15answers
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 ...
12
votes
2answers
329 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. (...
52
votes
9answers
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 ...
5
votes
5answers
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 ...
31
votes
5answers
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 ...
38
votes
27answers
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:
...
26
votes
15answers
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: ...
43
votes
5answers
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 ...
18
votes
7answers
485 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 ...
20
votes
29answers
2k 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 ...
23
votes
9answers
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 ...
80
votes
46answers
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 ...
33
votes
4answers
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 ...
64
votes
12answers
3k 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 ...
55
votes
24answers
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, ...
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
...
101
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):
...
47
votes
7answers
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 ...
12
votes
7answers
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 ...
10
votes
3answers
550 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 ...
7
votes
3answers
661 views
Pretty Printing Parentheses
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 this challenge is to make it at least ...
20
votes
10answers
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 ...
16
votes
23answers
2k 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 ...