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.
3will the space in
Code Golf
also be removed, what about the one inProgramming Puzzles
. – colsw – 2017-04-28T13:20:31.487@ConnorLSW I assume so, see Mego's answer – Stephen – 2017-04-28T13:26:23.963
In encodings where 0x09, 0x0A and 0x20 aren't tabs, newlines or spaces respectively, should the bytes or the chars be removed? – Erik the Outgolfer – 2017-04-28T15:30:06.560
@EriktheOutgolfer the chars, not the bytes. – programmer5000 – 2017-04-28T15:30:36.747
4
This will be impossible in at least Whirl and Whitespace.
– Engineer Toast – 2017-04-28T17:14:12.50313What are the close votes for? – OldBunny2800 – 2017-04-28T21:16:42.200
12@OldBunny2800 good question. I keep asking that but the comment gets removed... – programmer5000 – 2017-04-28T21:19:30.457
12The close votes are for the lack of inputs and outputs and restriction on the formatting of inputs and outputs. 100% if you had a section labeled "rules" with a bullet-pointed list of things you think were obvious about the challenge you'd have 0 close votes. It's all about presentation with CompSci folks, if we can think of a seemingly idiotic question to ask that may save us a byte or to, we will, try to counter that idiocy and you will be a great question writer. – Magic Octopus Urn – 2017-04-28T22:00:40.567
1I think this challenge resembles the quality of
polyglot
challenges. Though not entirely, of course. Awesome idea! +1 – Arjun – 2017-04-29T13:50:00.420What about non-breaking space? In MathGolf, non-breaking space is the operator "discard everything but top-of-stack", which is quite useful in this challenge.
– maxb – 2018-12-10T14:10:13.780From Code Golf to Coding Challenges – MilkyWay90 – 2019-06-15T20:04:39.953
I'd add a solution in Poetic, but such a solution would be at least 3111613151435231622325141268427653175133731762761752743751317 bytes long. (No kidding.) – JosiahRyanW – 2019-11-16T03:01:45.507