Common Lisp (SBCL), 52 bytes
(format`,t"~[Programming Puzzles~;Code~@TGolf~]"0 1)
Prints Programming Puzzles
(format`,t"~[ProgrammingPuzzles~;Code~@TGolf~]"01)
Prints Code Golf
Ungolfed:
(format t "~[Programming Puzzles~;Code Golf~]" 0 1)
Explaination:
The trick basically comes from how #'format
works in Common Lisp.
In CL, most whitespace can be omitted provided that there is no ambiguity about where tokens start or end. The first trick was separating the format
and t
symbols. I had to unambiguously end the format
symbol without changing how t
was interpreted. Luckily, ` in CL ends the preceding token before it gets processed, and ,
cancels the effect of ` (` is used to implement templating, where the next expression following it gets "quoted", but any sub-expression prefixed with a ,
is evaluated and the result included in the template, so `, is nearly a no-op).
The third argument to format
is the template string. format
is similar to printf in C, but has much more powerful formatting directives and use ~ to indicate them instead of %. ~[ and ~] allow you to select between multiple options for printing, with ~; separating them. An additional argument is supplied to format- the numeric index of which one you want printed. In order to ensure that the " " in Code Golf survives, I used the tabulation directive ~T, which is used to insert whitespace, generally to align text into columns. ~@T is a variation which just inserts a given number of spaces, defaulting to 1.
Finally, there are two arguments to format- 0 and 1. Before whitespace is removed, the 0 is used by ~[~;~] to select "Programming Puzzles" and the extra format argument (the 1) is dropped (I'm not sure how standard dropping extra format arguments is, but this works on Steel Bank Common Lisp). After whitespace is removed, there is only one argument (01) which selects "Code Golf" instead.
Code Golf
also be removed, what about the one inProgramming Puzzles
. \$\endgroup\$