From Programming Puzzles to Code Golf

77

9

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 it outputs Code Golf (trailing newline optional.)

Your byte count is the count of the first program, with spaces still there.

Notes

  • The spaces in Code Golf and Programming Puzzles will be removed as part of the removal, so plan accordingly.

  • In encodings where 0x09, 0x0A and 0x20 aren't tabs, newlines or spaces respectively, those chars will be removed.

  • If your code is

    42  $@ rw$
    @42
    

    then that must output Programming Puzzles. Also, in the same language,

    42$@rw$@42
    

    must output Code Golf.

This is , so the shortest code in bytes wins! Good luck!

programmer5000

Posted 2017-04-28T13:14:24.797

Reputation: 7 828

3will the space in Code Golf also be removed, what about the one in Programming 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.503

13What 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.420

What 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.780

From 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

Answers

68

Python 2, 50 bytes

print["Code\40Golf","Programming Puzzles"][" ">""]

Try it online!

With all spaces removed:

print["Code\40Golf","ProgrammingPuzzles"]["">""]

Try that online!

Thanks to Stephen S for 3 bytes, and Erik the Outgolfer for 1

Mego

Posted 2017-04-28T13:14:24.797

Reputation: 32 998

2Darn, ninja'd! I was just about to click Post Answer! +1 – HyperNeutrino – 2017-04-28T13:22:55.273

1I think you just broke my friend's brain. How does this even work? – Stevoisiak – 2017-04-28T15:09:57.760

12@StevenVascellaro It's really simple. In the first case, " ">"" returns True, since, lexicographically, a space is greater than the empty string. In the second case, "">"" returns False, since nothing can be greater than itself. True and False are actually just 1 and 0 respectively, just in the bool datatype instead of int or long. In the first case, the spaces are preserved, so, the item at index 1, "Programming Puzzles", is returned verbatim. In the second case, the spaces are gone, hence the \x20 in the item at index 0 "Code\x20Golf" to preserve a space. – Erik the Outgolfer – 2017-04-28T15:26:32.613

@Mego I don't really know Python, but if it is like JavaScript, can't [" ">""] simply be [" "]? Because empty string is false and non-empty string is true. – Stephen – 2017-04-28T15:54:10.620

10@StephenS Nope, because unlike JavaScript, Python doesn't have an obsession with implicit casting. – Mego – 2017-04-28T15:57:40.827

2If find Python's lack of obsession disturbing. – John Dvorak – 2017-04-28T19:56:13.160

1@JanDvorak If it's any consolation, Python 2 has an obsession with comparisons. []>"" – Mego – 2017-04-29T01:12:12.680

1Note that bool is a subclass of int. So True and False are actually equal to 1 and 0, just of type bool instead of int. – wizzwizz4 – 2017-04-30T11:28:07.290

@Mego Your comment made me laugh out loud. Have a nice day sir. :) – goodguy – 2017-04-30T20:56:29.337

53

Python 2, 48 47 bytes

-1 byte thanks to Erik the Outgolfer

print' 'and'Programming Puzzles'or'Code\40Golf'

Try it online!

print''and'ProgrammingPuzzles'or'Code\40Golf'

Try it online!

Rod

Posted 2017-04-28T13:14:24.797

Reputation: 17 588

9Aww, I was just about to improve my answer to this... – Mego – 2017-04-28T13:29:24.677

23

C, 64 62 53 52 bytes

f(){puts(*" "?"Programming Puzzles":"Code\40Golf");}

Try it Online!

Uses the fact that C strings end with a null character

math junkie

Posted 2017-04-28T13:14:24.797

Reputation: 2 490

22

05AB1E, 15 bytes

”ƒËŠˆ”" "v”–±ÇÀ

Try it online!

Explanation

”ƒËŠˆ”           # push "Code Golf"
      " "v       # for each character in the string " " do
          ”–±ÇÀ  # push "Programming Puzzles"
                 # implicitly output top of stack

Emigna

Posted 2017-04-28T13:14:24.797

Reputation: 50 798

...I just don't get it. Does this use dictionary compression or something? – LegionMammal978 – 2017-04-30T02:15:04.177

@LegionMammal978 I'm pretty sure it does. – NoOneIsHere – 2017-04-30T03:15:32.323

@LegionMammal978: It does indeed use dictionary compression. – Emigna – 2017-04-30T08:59:55.747

5@Emigna Okay, because last I checked, neither of those strings could be fit into 4 bytes :p – LegionMammal978 – 2017-04-30T10:27:23.780

To my knowledge some of those characters can be saved using one byte, assuming well known encodings. in UTF-8 I get 31 bytes... Am I wrong? – steffen – 2017-05-04T20:00:12.027

@steffen: 05AB1E uses a custom code page (previously CP-1252) where each character is 1 byte.

– Emigna – 2017-05-04T20:07:41.580

How, exactly does the compression work? I tried looking at the language's source code, but couldn't figure it out. Also, how does one generate the compressed strings when golfing? – Draco18s no longer trusts SE – 2019-01-09T17:25:14.363

1

@Draco18s: Kevin has written a nice tutorial over at the tips page you can use to get a better idea of how to use it.

– Emigna – 2019-01-09T17:54:48.153

16

CJam, 38 bytes

" ""Programming Puzzles""Dpef!Hpmg":(?

Try it online! or with spaces removed

Explanation

" "                    e# Push this string.
"Programming Puzzles"  e# Push "Programming Puzzles".
"Dpef!Hpmg":(          e# Push "Dpef!Hpmg" and decrement each char, giving "Code Golf".
?                      e# If the first string is true (non-empty) return the second string,
                       e#   else return the third.

Whether spaces are in the program or not determines if the first string is truthy or falsy.

Business Cat

Posted 2017-04-28T13:14:24.797

Reputation: 8 927

27Your code is sad :( – Roman Gräf – 2017-04-28T13:51:25.793

14If you're willing to use unprintables, "Bncd\x19Fnke":) is happy code instead (replace \x19). – Erik the Outgolfer – 2017-04-28T15:58:22.543

16

Jelly, 18 bytes

“½ċṭ6Ỵ»ḷ
“Ñ1ɦ+£)G»

Try it online!

Explanation

In the program as written, the first line is a helper function that's never run. The second line (the last in the program) is the main program, and is the compressed representation of the string "Programming Puzzles" (which is then printed implicitly).

If you remove the newline, the whole thing becomes one large program. “½ċṭ6Ỵ» is the compressed representation of the string "Code Golf". evaluates but ignores its right hand argument, leaving the same value as before it ran; it can be used to evaluate functions for their side effects (something I've done before now), but it can also be used, as here, to effectively comment out code.

Interestingly, the actual logic here is shorter than the 05AB1E entry, but the code as a whole comes out longer because the string compressor is less good at compressing these particular strings.

user62131

Posted 2017-04-28T13:14:24.797

Reputation:

This turns out to be valid. – Erik the Outgolfer – 2017-04-28T15:34:36.670

To my knowledge some of those characters can be saved using one byte, assuming well known encodings. in UTF-8 I get 36 bytes... Am I wrong? – steffen – 2017-05-04T19:59:10.790

@steffen: Jelly uses its own character encoding, in which all of the 256 different characters it uses can be stored in a single byte. (The only reason it does this rather than using a pre-existing encoding is for readability (!); you could trivially write the program encoded in, say, codepage 437, and it would run in the Jelly interpreter, but it would typically be much harder to read.)

– None – 2017-05-04T21:12:08.350

14

Jelly, 17 bytes

“Ñ1ɦ+£)G“½ċṭ6 Ỵ»Ṃ

Try it online!

How it works

As in the other Jelly answer, Ñ1ɦ+£)G and ½ċṭ6Ỵ encode the strings Programming Puzzles and Code Golf. begins a string literal and separates one string form another, while » selects the kind of literal (dictionary-based compression), so this yields

["Programming Puzzles", "Code Golf"]

then takes the minimum, yielding Code Golf.

However, by adding a space between ½ċṭ6 and , we get a completely different second string, and the literal evaluates to

["Programming Puzzles", "caird coinheringaahing"]

Since caird coinheringaahing is lexicographically larger than Programming Puzzles, selects the first string instead.

Dennis

Posted 2017-04-28T13:14:24.797

Reputation: 196 637

Just did the same with “½ċṭ6Ỵ“Ñ1ɦ +£)G»Ṁ – Jonathan Allan – 2017-04-29T08:00:50.220

To my knowledge neither of those characters can be saved using one byte, assuming well known encodings. in UTF-8 I get 34 bytes... Am I wrong? – steffen – 2017-05-04T19:55:53.060

@steffen Jelly uses a custom code page that encodes each of the 256 characters it understands as a single byte.

– Dennis – 2017-05-04T21:48:36.960

@Dennis thank you for clarifying. – steffen – 2017-05-05T09:30:26.987

13

Javascript, 46 43 42 Bytes

x=>" "?"Programming Puzzles":"Code\40Golf"

console.log((x=>" "?"Programming Puzzles":"Code\40Golf")())
console.log((x=>""?"ProgrammingPuzzles":"Code\40Golf")())

user68614

Posted 2017-04-28T13:14:24.797

Reputation:

5You can replace the \x20 in the first string with a space. – Shaggy – 2017-04-28T13:30:58.610

Beat me to it, nicely done. Does this need a trailing ;? – ricdesi – 2017-04-28T15:22:57.687

@ricdesi no, it dosen't. – None – 2017-04-28T15:31:41.613

3@ricdesi since this is codegolf, if the program runs, it works. ;s are sometimes not required in JavaScript. – Stephen – 2017-04-28T15:52:33.397

2You can replace \x20 with \40 to save a byte :-) – ETHproductions – 2017-04-28T18:32:22.307

10

Haskell, 48 bytes

a _="Programming Puzzles";a4="Code\32Golf";f=a 4
a_="ProgrammingPuzzles";a4="Code\32Golf";f=a4

Defines function f which returns the corresponding string.

For reference, the old version is:

Haskell, 49/47 bytes

f""="Code\32Golf";f(_)="Programming Puzzles";f" "

with spaces removed

f""="Code\32Golf";f(_)="ProgrammingPuzzles";f""

Two simple pattern matches. (_) matches all patterns. You can improve the without-spaces version by one byte by defining the second pattern as f" "=/f""=, but this gives a "Pattern match is redundant" warning.

Alternative solution with the same byte count:

last$"Code\32Golf":["Programming Puzzles"|" ">""]
last$"Code\32Golf":["ProgrammingPuzzles"|"">""]

nimi

Posted 2017-04-28T13:14:24.797

Reputation: 34 639

10

Wolfram language, 62 bytes

"Programming Puzzles"[ToExpression@"\"Code\\.20Golf\""][[0 1]]

The space in [[0 1]] is implicit multiplication, so this is equivalent to [[0]]. Without a space, 01 is just 1. The 0th and 1st parts of this expression are the strings we want.

Another solution of questionable validity (44 bytes, 2 saved by Kelly Lowder):

"Programming Puzzles"["Code\.20Golf"][[0 1]]

The \.20 gets replaced by a space immediately when typed into a Mathematica environment, so it's not clear if it gets removed along with the other spaces…

Not a tree

Posted 2017-04-28T13:14:24.797

Reputation: 3 106

1As soon as you paste (or type) this into Mathematica, (cloud based or not) the escape sequence, \:0020 turns into a space, and thus would be removed, so I'm not sure this qualifies. Also \.20 is shorter.by two characters. "Programming Puzzles"["Code"<>FromCharacterCode@32<>"Golf"][[01]] will work. – Kelly Lowder – 2017-04-28T20:12:31.857

1@KellyLowder, hmm, that's a good point. I've added another solution that should avoid that issue. (Thanks for the \.20 suggestion — how did you find that? I thought I'd scoured the whole documentation…) – Not a tree – 2017-04-28T22:56:21.403

1I found the \.20 by making a typo. Seems to only work for two-digit character codes. I don't think it's in the documentation. – Kelly Lowder – 2017-05-01T13:48:40.183

8

Excel - 56 Bytes

=IF(""=" ","Code"&CHAR(32)&"Golf","Programming Puzzles")

Very similar to most of the other answers... nothing fancy here.

qoou

Posted 2017-04-28T13:14:24.797

Reputation: 711

7

Ohm, 33 32 bytes

Uses CP437 encoding.

▀Bn¬i≈╣Ü╝Rb╡°╧S½uÇ▀
▀4>~H├MS░l╬δ

Try it online! or try without whitespace

Explanation

With whitespace:

▀Bn¬i≈╣Ü╝Rb╡°╧S½uÇ▀    Main wire

▀Bn¬i≈╣Ü╝Rb╡°╧S½uÇ▀    Push "Programming Puzzles" (compressed string)
                       Implicitly output the top stack element


▀4>~H├MS░l╬δ           Helper wire (never called)

Without whitespace:

▀Bn¬i≈╣Ü╝Rb╡°╧S½uÇ▀▀4>~H├MS░l╬δ    Main wire

▀Bn¬i≈╣Ü╝Rb╡°╧S½uÇ▀                Push "Programming Puzzles" (compressed string)
                   ▀4>~H├MS░l╬δ    Push "Code Golf" (compressed string)
                                   Implicitly output top stack element

Business Cat

Posted 2017-04-28T13:14:24.797

Reputation: 8 927

I'm so glad I finally finished string compression! – Nick Clifford – 2017-05-02T20:01:45.927

1@NickClifford The curious thing I noticed was that Code Golf got longer when compressed. I guess that's because of the capitals? Either way it's still shorter than writing it normally because I can't use a literal space here. – Business Cat – 2017-05-02T20:05:07.757

Yeah, Smaz is kind of weird like that. – Nick Clifford – 2017-05-02T20:07:18.710

FYI, feel free to ping me in chat if you have any questions or feature requests for Ohm. – Nick Clifford – 2017-05-02T20:18:32.717

7

Japt, 29 bytes

With spaces:

`Co¸{S}Golf`r `PžgŸmÚÁ Puzz¤s

Try it online!

Without spaces:

`Co¸{S}Golf`r`PžgŸmÚÁPuzz¤s

Try it online!


This takes advantage of the fact that in Japt, a space closes a method call. With spaces, the code is roughly equivalent to this JavaScript code:

("Code"+(S)+"Golf").r(),"Programming Puzzles"

This is evaluated as JavaScript, and the result is sent to STDOUT. Since the last expression is "Programming Puzzles", that string is printed.

Without spaces, the code is roughly equivalent to:

("Code"+(S)+"Golf").r("ProgrammingPuzzles")

(If you haven't figured it out by now, the S variable is a single space.) The .r() method on a string, if given one argument, removes all instances of that argument from the string. Since "Code Golf" does not contain "ProgrammingPuzzles", it returns "Code Golf" unchanged, which is then sent to STDOUT.

ETHproductions

Posted 2017-04-28T13:14:24.797

Reputation: 47 880

I didn't even think of using replace. Nice one! – Tom – 2017-04-28T14:39:20.667

To my knowledge some of those characters can be saved using one byte, assuming well known encodings. in UTF-8 I get 36 bytes... Am I wrong? – steffen – 2017-05-04T19:57:45.897

@steffen Japt uses the ISO-8859-1 encoding, in which each char represents one byte. But some of the chars would be unprintable in this program, so I used the Windows-1252 encoding here (actually, it was autogenerated by TIO)

– ETHproductions – 2017-05-04T20:00:43.073

6

Brachylog, 44 bytes

" "Ṣ∧"Programming Puzzles"w|"Code"wṢw"Golf"w

Try it online!

Explanation

" "Ṣ                                           If " " = Ṣ (which is itself " ")
    ∧"Programming Puzzles"w                    Write "Programming Puzzles"
                           |                   Else
                            "Code"w            Write "Code"
                                   Ṣw          Write " "
                                     "Golf"w   Write "Golf"

Fatalize

Posted 2017-04-28T13:14:24.797

Reputation: 32 976

1Crossed out 44 is still 44 :( Edit in &nbsp; on either side to fix :) – HyperNeutrino – 2017-04-28T13:41:11.967

@HyperNeutrino It's not crossed out, 44 is the length with spaces, and 42 without. – Fatalize – 2017-04-28T13:41:43.803

Oh. Whoops. Well, it's too similar so I couldn't tell without looking at the markdown by going into edit. Never mind :P – HyperNeutrino – 2017-04-28T13:42:44.517

5

PHP, 44 Bytes

ternary operator

<?=" "?"Programming Puzzles":"Code\x20Golf";

PHP, 51 Bytes

comment

<?=/** /"Code\x20Golf"/*/"Programming Puzzles"/**/;

PHP, 57 Bytes

array switch

<?=["Code\x20Golf","Programming Puzzles"][(ord("
")/10)];

Jörg Hülsermann

Posted 2017-04-28T13:14:24.797

Reputation: 13 026

5

Alice, 44 bytes

/"floG!"t"edoC"#
 /"selzzuP gnimmargorP"d&o@

Try it online!

Without whitespace:

/"floG!"t"edoC"#/"selzzuPgnimmargorP"d&o@

Try it online!

Explanation

In the first program, the two mirrors / redirect the instruction pointer onto the second line. "selzzuP gnimmargorP" pushes the required code points in revere order, d pushes the stack depth and &o prints that many bytes. @ terminates the program.

Without the whitespace, the program is all on a single line. In that case, the instruction pointer can't move in Ordinal mode, so the / effectively become no-ops (technically, the IP simply doesn't move for one step, the same / gets executed again, and the IP reflects back to Cardinal mode). So if we drop those from the program, it looks like this:

"floG!"t"edoC"#"selzzuPgnimmargorP"d&o@

To include the space in Code Golf, we use an exclamation mark instead and decrement it with t. After we've got all the code points on the stack, # skips the next command, which is the entire second string. d&o then prints the stack again, and @ terminates the program.

Martin Ender

Posted 2017-04-28T13:14:24.797

Reputation: 184 808

You must golf this (crossed out 44 is 44) – MilkyWay90 – 2019-01-11T01:55:32.763

5

Perl 5, 43 41 bytes

say" "?"Programming Puzzles":Code.$".Golf

Try it online!

Uses the fact that ' ' is true in perl and '' is false. The $" variable is set to a space by default.

Thanks to @NahuelFouilleul for removing two bytes.

Chris

Posted 2017-04-28T13:14:24.797

Reputation: 1 313

maybe late but "Code$\"Golf" is shorter and Code.$".Golf too – Nahuel Fouilleul – 2019-01-09T13:09:38.187

@NahuelFouilleul Yeah, I was pretty new when I wrote this answer. Thanks though! – Chris – 2019-01-09T17:19:03.220

4

C# 88 81 70 63 bytes

Func<string>@a=()=>" "==""?"Code\x20Golf":"Programming Puzzles";

With whitespace stripped:

Func<string>@a=()=>""==""?"Code\x20Golf":"ProgrammingPuzzles";

Thanks to BrianJ for showing me how to have no space between a method return type and the method name, PeterTaylor for saving 7 18 bytes, and Patrick Huizinga for saving 7 bytes.

Same method as everyone else really, technically this could be considered invalid because the method doesn't specify a return type for the method, but there has to be whitespace between the return type and the method name.

Skidsdev

Posted 2017-04-28T13:14:24.797

Reputation: 9 656

1you can prefix the function name with an @, so then you have void@a... and avoid the "no return type" compilation error (also adds bytes, though :( ) – Brian J – 2017-04-28T15:36:59.090

.Length<1 saves one byte; \u0020 saves six if I've counted correctly; and you can make a valid answer (and save a few bytes at the same time) by submitting a lambda instead of a top level function. Func<string>a=()=>... – Peter Taylor – 2017-04-28T15:37:48.933

@BrianJ Hmm, didn't know that, wonder why that works from a compiler view-point. Anyway, it may lose bytes but it also technically makes this answer not non-competing, so it's worth it. Thanks! – Skidsdev – 2017-04-28T15:38:25.840

@Mayube the @ is primarily used if you need to use a reserved word as a variable name (the equivalent is surrounding with [] in VB.NET (and MS SQL Server)). – Brian J – 2017-04-28T15:41:02.840

@PeterTaylor wouldn't changing it to a func lambda require returning the string, which would need a space after return, thanks for the tip on Length and the space though – Skidsdev – 2017-04-28T15:47:20.717

1Yes, it requires returning the string; but if you use => instead of return you don't need any spaces. (And even if you use return, you can return(...)). – Peter Taylor – 2017-04-28T15:47:53.180

But Brian's tip combines with mine if you change the header to say "C# version 6": string@a()=>... – Peter Taylor – 2017-04-28T15:50:01.867

No, string@a()=>" ".Length<1?"Code\u0020Golf":"Programming Puzzles"; is a full-fledged method definition in C# from version 6. – Peter Taylor – 2017-04-28T15:54:46.053

@PeterTaylor Tried it in VS2015 with C#6 and it said it's only available in C#7, if you wanna post it as a separate answer for C#7 go ahead, my VS isn't setup for C#7 – Skidsdev – 2017-04-28T15:59:35.700

Huh. According to the documentation it's available from C# 6 in VS 2015. I'm not going to have access to a computer with any VS until Tuesday.

– Peter Taylor – 2017-04-28T16:12:11.767

Can anyone explain to me why " ".Length<1 is used instead of " "==""? – Patrick Huizinga – 2017-05-01T12:17:44.183

Also, \u0020 can be replaced with \x20. – Patrick Huizinga – 2017-05-01T12:25:20.083

4

R, 50 bytes

I think this is the same as this Javascript answer, and basically the same idea as all the others.

`if`(' '=='','Code\x20Golf','Programming Puzzles')

Giuseppe

Posted 2017-04-28T13:14:24.797

Reputation: 21 077

49 bytes – Robin Ryder – 2019-11-08T11:48:22.323

4

Pyth, 37 bytes

?" ""Programming Puzzles""Code\40Golf

Try it here.

?"""ProgrammingPuzzles""Code\40Golf

Try it here.

Erik the Outgolfer

Posted 2017-04-28T13:14:24.797

Reputation: 38 134

4

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.

djeis

Posted 2017-04-28T13:14:24.797

Reputation: 281

1+1, just one thing: "but any sub-expression prefixed with a , is evaluated and spliced in" Isn't ,@ necessary for splicing? – None – 2017-05-03T15:46:49.023

"spliced" is a poor term for that, admittedly. Technically, , evals the next expression and includes the result in the template, while ,@ assumes the expression will eval to a list and includes that list's contents in the template directly. Traditionally in the lisp community, ,@ is called "splicing", but I'm not sure that's the most obvious choice. I'll try to reword it a bit. – djeis – 2017-05-03T17:04:02.377

4

Java 8, 74 50 48 bytes

()=>" "==""?"Code\040Golf":"Programming Puzzles"

Khaled.K

Posted 2017-04-28T13:14:24.797

Reputation: 1 435

@NonlinearFruit you're right, I've changed that one to be non-competent – Khaled.K – 2017-05-01T18:50:21.743

1I don't think printing is a requirement, so you could just return the string. I haven't tested it but the == operator should also work, ()=>""==""?"Code\u00A0Golf":"Programming Puzzles" – NonlinearFruit – 2017-05-01T19:59:13.247

1\u00A0 -> \040 for a 2 byte savings. – Poke – 2017-05-03T18:47:14.150

3

Japt, 32 bytes

" "?`PžgŸmÚÁ Puzz¤s`:`Co¸{S}Golf

Try it online!

Tom

Posted 2017-04-28T13:14:24.797

Reputation: 3 078

1Heh, I was just about to post the same thing :-) – ETHproductions – 2017-04-28T14:30:08.820

1

Actually, there is a shorter way...

– ETHproductions – 2017-04-28T14:35:36.343

3

PowerShell, 56 bytes

('Programming Puzzles',('Code'+[char]32+'Golf'))[!(' ')]

Try it online!

Pretty basic I would say, but it gets the job done

Sinusoid

Posted 2017-04-28T13:14:24.797

Reputation: 451

3

><>, 47 45 bytes

! v"floG!"1-"edoC"!
o<>"selzzuP gnimmargorP">

Try it online!

Thanks to randomra for -2 (clever two !s so that I can use only one >o<.)

The code shouts "Flog! Flog! Flog!" and resembes a fish.

Erik the Outgolfer

Posted 2017-04-28T13:14:24.797

Reputation: 38 134

3

dc, 50

[pq]sm[Programming Puzzles]dZ19=m[Code]n32P[Golf]p

Try it online.

[ ] defines a string - Z measures its length. If the length is 19 then it contains a space and the macro stored in the m register is called, which prints Programming Puzzles and quits. Otherwise Code Golf is printed.

Digital Trauma

Posted 2017-04-28T13:14:24.797

Reputation: 64 644

Could you link to the dc interpreter / docs / github? – programmer5000 – 2017-04-29T01:14:09.800

@programmer5000 Just choose dc on TIO, then click the language name. – Dennis – 2017-04-29T01:15:19.967

@Dennis thanks, I didn't even know that TIO does that! – programmer5000 – 2017-04-29T01:18:08.430

3

><>, 42 bytes

With whitespace

\"floG"48*"edoC"
/>o<"Programming Puzzles"

Try it online!

Without whitespace

\"floG"48*"edoC"/>o<"ProgrammingPuzzles"

Try it online!

user41805

Posted 2017-04-28T13:14:24.797

Reputation: 16 320

3

T-SQL, 96 82 81 67 bytes

print+iif(len(' x')=2,'Programming Puzzles','Code'+char(32)+'Golf')

Try it online | Without spaces

Old version (96 bytes):

select(case'x'when(replace(' ',' ','x'))then'Programming Puzzles'else'Code'+nchar(32)+'Golf'end)

mbomb007

Posted 2017-04-28T13:14:24.797

Reputation: 21 944

Nice work, you can get to 67 by losing the outer parens and changing the condition to iif(len(' x')=2 – BradC – 2017-06-21T21:31:33.953

@BradC Close, but the outer paren prevents needing a space after print. I used a + instead and it worked. – mbomb007 – 2017-06-21T21:57:30.647

Must've pasted and counted the wrong one. And I didn't know either, but the plus was the first character I tried and it worked. – mbomb007 – 2017-06-22T03:20:25.573

3

MATL, 39 37 bytes

Thanks to @Sanchises for removing 2 bytes.

'Dpef!Hpmg'qc%
'Programming puzzles'&

Try it online!

Explanation

With spaces

'Dpef!Hpmg' pushes this string.

q substracts 1 from each code point, and c converts back to characters. This produces the string 'Code Golf'.

% is the comment symbol. The rest of the line (which is empty) is ignored.

'Programming puzzles' pushes this string.

& specifies that the display function, which is implicitly called at the end of the program, must only print the top of the stack (instead of the whole stack). So the second string is printed.

Without spaces

'Dpef!Hpmg' pushes this string.

q substracts 1 from each code point, and c converts back to characters. This produces the string 'Code Golf'.

% is the comment symbol. The rest of the line (that is, the rest of the code) is ignored.

At the end of the program the implicit display function is called, which prints the string.

Luis Mendo

Posted 2017-04-28T13:14:24.797

Reputation: 87 464

3

Befunge, 47 bytes

# <"floG"84*"edoC">:#,_@#" Programming Puzzles"

Try it Online

Without spaces it skip the first < and prints Code Golf instead

Jo King

Posted 2017-04-28T13:14:24.797

Reputation: 38 234

3

APL (Dyalog Unicode), ₄₅ ₄₁ 39 bytesSBCS

Anonymous lambda. Takes dummy argument.

{'Programming Puzzles'
⊢4⌽9↑'GolfCode'}

Try it online!

This function is a so called "dfn" which terminates with and returns the first non-assignment, i.e. Programming Puzzles.

Removing all whitespace gives:

{'ProgrammingPuzzles'⊢4⌽9↑'GolfCode'}

Try it online!

This takes the last nine characters of GolfCode thus padding with a trailing space, then cyclically rotates that 4 steps to the left. ignores the text on its left and returns the text on its right.

Adám

Posted 2017-04-28T13:14:24.797

Reputation: 37 779

3

Python 3, 72 68 bytes

Had output backwards at first, thanks Draco18s, then saved 4 bytes, thanks Jo King

a=0;ab="Programming";a
b="Code";ad="Puzzles";a
d="Golf";print(ab,ad)

Try it online!

Cello Coder

Posted 2017-04-28T13:14:24.797

Reputation: 61

1I think you have the outputs backwards. – Draco18s no longer trusts SE – 2019-11-11T20:56:08.563

Whoops lol, thanks. Fixed it – Cello Coder – 2019-11-13T16:45:59.120

You can reuse the a to get 68 bytes

– Jo King – 2019-11-16T02:56:29.550

2

GolfScript, 38 bytes

" ""Programming Puzzles""Code\sGolf"if

Try it online!

Erik the Outgolfer

Posted 2017-04-28T13:14:24.797

Reputation: 38 134

2

Befunge, 76 bytes

" "0`#v_"floG"84*"edoC",,,,,,,,,@
,,,,,@>"selzzuP gnimmargorP",,,,,,,,,,,,,,

Try it online!

Not the most compact solution, but then again writing Befunge code without whitespace is pretty difficult.

At the very beginning, it compares a space character with 0. If it's greater, it goes to the bottom row. If it isn't, which is what happens when you replace space with nothing, it stays on the first row.

user55852

Posted 2017-04-28T13:14:24.797

Reputation:

What do the ,s do? – programmer5000 – 2017-04-28T21:14:18.463

@programmer5000 Each prints one character. – Martin Ender – 2017-04-28T21:51:18.840

A tip for printing a large number of characters up until you reach a 0 is to do >:#,_ which could save you a lot of bytes – MildlyMilquetoast – 2017-05-23T00:09:13.567

2

Pyth, 36 bytes

J
"Programming Puzzles" "Code\40Golf

Try it online: with or without whitespace characters

That's a nice challenge for Pyth.

In the above code the newline prints Programming Puzzles and the space suppresses the output of Code Golf. J only assigns the first string to the variable J, but doesn't print anything.

After removing the newline and the spaces, the first string doesn't get printed (only assigned), but the second string gets printed implicitly.

Jakube

Posted 2017-04-28T13:14:24.797

Reputation: 21 462

2

PowerShell, 54 bytes

"$((('Programming','Puzzles'),('Code','Golf'))[!' '])"

Try it online!

Without spaces

"$((('Programming','Puzzles'),('Code','Golf'))[!''])"

Try it online!

Andrei Odegov

Posted 2017-04-28T13:14:24.797

Reputation: 939

2

Ruby, 46 bytes

puts' '[0]?'Programming Puzzles':"Code\40Golf"

histocrat

Posted 2017-04-28T13:14:24.797

Reputation: 20 600

2

Haskell, 67 65 bytes

Even if it's longer than the one by @nimi, here's another Haskell solution, that works by abusing the [] Monad:

λ putStr$[s|s<-[" ">>"Programming Puzzles","Code\32Golf"],s/=""]!!0

  Programming Puzzles

Try it online!

λ putStr$[s|s<-["">>"Programming Puzzles","Code\32Golf"],s/=""]!!0

  Code Golf

Try it online!

Thanks @Laikoni for golfing off 2 bytes!

ბიმო

Posted 2017-04-28T13:14:24.797

Reputation: 15 345

2

Add++, 56 bytes

INy,x:" ",Ix,,O"Programming Puzzles",INx,,O"Code\40Golf"

Try it online!

Uses a very similar technique to a lot of answers, and has the pseudocode of

x = ' '
if x:
    print('Programming Puzzles')
else:
    print('Code Golf')

By removing all whitespace, we make x equal to the empty string, which is falsey in Add++. Therefore, we output Code Golf instead of Programming Puzzles. The space in Code Golf is simply the octal value \$40_8 = 32_{10}\$. The only unusual part is the preceding INy,. With this, we are able to put all our code on one line, as this is a compound statement. Without this, the programming, with whitespace, would look something like this:

x:" "
Ix,O"Programming Puzzles"
INx,O"Code\40Golf"

But, when you remove the whitespace from this, we cause syntax errors, as outside of compound statements, Add++ has no other line terminator than a newline.

caird coinheringaahing

Posted 2017-04-28T13:14:24.797

Reputation: 13 702

2

Haskell, 42 bytes

Simple comment abuse. (Hm, seems to confuse the syntax coloring too.)

{-- }"Code\SPGolf"--}"Programming Puzzles"
  • With the spaces {-- }"Code\SPGolf"--} is a bracketed comment. Try it online!
  • Without the spaces {--} is a bracketed comment and --}"ProgrammingPuzzles" an end of line comment. Try it online!

Ørjan Johansen

Posted 2017-04-28T13:14:24.797

Reputation: 6 914

2

Pushy, 47 bytes

`Dpef!Hpmg `KtkL9=?";
\
c`Programming Puzzles`"

Try it online!

In its initial form, the top line adds the string "Code Golf" to stack, but with each character incremented, and a trailing space. It then decrements each character and checks if the length is 9 - however, as there is a trailing space, the length is 10, so the conditional is not entered. Therefore the top line is essential a no-op. The third line then prints "Programming Puzzles".

After modification, the program looks like this:

`Dpef!Hpmg`KtkL9=?";\c`Programming Puzzles`"

The \ starts a comment therefore the only relevant code is the first half, which gets the string "Code Golf", checks its length (which is now correctly 9 as the space has been removed), and then prints it accordingly.

FlipTack

Posted 2017-04-28T13:14:24.797

Reputation: 13 242

2

Ahead, 44 bytes

j ~"floG"32"edoC"~"selzzuP gnimmargorP"j~WW@

The first space is what's actually important. j will "jump over" the next cell in the head's direction; if the space is there it will be jumped over and the head will land on the first ~, causing it to skip the section that pushes Code Golf. When the spaces are removed, the ~ will be jumped over and the first section will be entered instead.

Try it online!

snail_

Posted 2017-04-28T13:14:24.797

Reputation: 1 982

2

Kotlin, 62 bytes

Lambda returning a string.

{" ".ifEmpty{"Code\u0020Golf"}.ifBlank{"Programming Puzzles"}}

1.3 introduced ifEmpty and ifBlank which each take a lambda and return its result if the receiving string is empty or contains only whitespace. If the condition fails, the receiving string is passed on instead.

So, if the spaces are removed, then the ifEmpty check passes and the ifBlank check fails. The reverse is true if the spaces are left.

Try it online!

snail_

Posted 2017-04-28T13:14:24.797

Reputation: 1 982

2

MathGolf, 34 bytes

╕│Çÿgolf]ûq¶$╦ÿming+û£q$╦α ?;;δ♥$u

Try it online!

Explanation

The code contains only one single space. With it, the stack contains [['code', 'golf'], ['programming', 'puzzles'], ' '] when the ? is reached, otherwise it just contains the two lists. The ?rotates the top three elements, and implicitly pushes a 0 to the stack when only two elements are on the stack. This means that the order of the elements is different after the ? depending on if the space is present. It could be shorter by using the non-breaking space character, which is the "discard everything but TOS" operator, but I don't know if that is allowed.

╕│Çÿgolf]                                   Push ['code', 'golf']
         ûq¶$╦ÿming+û£q$╦α                  Push ['programming', 'puzzles']
                           ?                Push a space and rotate top 3 stack elements
                            ;;              Discard top two elements
                              δ             Capitalize string
                               ♥$u          Join with spaces

maxb

Posted 2017-04-28T13:14:24.797

Reputation: 5 754

2

SmileBASIC, 49 bytes

TABSTEP=5?"Code","Golf"'
CLS?"Programming Puzzles

At first I was afraid I'd need to use CHR$(32) to for the space in "Code Golf". Fortunately, I can save exactly 0 characters using commas and TABSTEP.

12Me21

Posted 2017-04-28T13:14:24.797

Reputation: 6 110

2

bash, 51 bytes

(echo Programming Puzzles||dd<<<$'Code\40Golf')2>&-

TIO

Nahuel Fouilleul

Posted 2017-04-28T13:14:24.797

Reputation: 5 582

2

Befunge-98 (FBBI), 46 bytes

"floG edoCselzzuP gnimmargorP"f3+40# $j$k$8k,@

Try it online!

Explanation:

"floG edoCselzzuP gnimmargorP" ¤ Put "Code Golf" and "Programming Puzzles" into
                                 the stack, character by character, 
                                 so that "Programming Puzzles" is on top of the stack.
f3+40                          ¤ Push 18, then 4, then 0 to the stack.
     # $                       ¤ With space: Jump over the whitespace and pop the 0.
        j$k$8                    Jump over the 4 next instructions.
             k,@                 Print the 18 top chars from the stack and exit.

     #$                        ¤ Without space: Jump over the `$` instruction,
       j                         Jump over the next 0 instructions.
        $                        Pop 4 from the stack.
         k$                      Pop the top 18 chars from the stack.
           8k,@                  Print out the 8 top chars from the stack and exit.

Wisław

Posted 2017-04-28T13:14:24.797

Reputation: 554

2

Wren, 62 bytes

System.write(" ".count>0?"Programming Puzzles":"Code\x20Golf")

Try it online!

Explanation

System.write(                                                ) // Output
             " ".count>0                                       // Whether the length of this string is larger than 0
                        ?"Programming Puzzles"                 // If true, output "Programming Puzzles"
                                              :"Code\x20Golf"  // Otherwise, output "Code Golf"

Wren, 71 bytes

System.write(Num.fromString("0 0")?"Code\x20Golf":"Programming Puzzles")

Try it online!

Explanation

System.write(                                                          ) // Output
             Num.fromString("0 0")                                       // Whether converting to a single number is successful
                                                                         // If this isn't successful, it outputs null, which is a false value.
                                  ?"Code\x20Golf"                        // If this is successful, output "Code Golf"
                                                 :"Programming Puzzles"  // Otherwise, output "Programming Puzzles"

user85052

Posted 2017-04-28T13:14:24.797

Reputation:

2

Keg, 35 30 bytes

‘∂⬭⑥⑷‘¶C≬;Puzz0ɧ;¶\ #ø¶[*;Golf

Without spaces:

‘∂⬭⑥⑷‘¶C≬;Puzz0ɧ;¶\#ø¶[*;Golf

Explained

‘∂⬭⑥⑷‘¶C≬;Puzz0ɧ;¶\ #ø¶[*;Golf
‘∂⬭⑥⑷‘              #Push the string "Program"
       ¶C≬;Puzz0ɧ;¶     #Push the string "ing Puzzles"
                   \        #Escape the space and implicitly print

------------------------------------------------------------------------------

‘∂⬭⑥⑷‘¶C≬;Puzz0ɧ;¶\#ø¶[*;Golf
‘∂⬭⑥⑷‘¶C≬;Puzz0ɧ;¶\#        #Everything as before, but this time:
                     ø      #Empty the stack
                      ¶[*;Golf  #Push the string "Code Golf" and print

Try it online!

Answer History

35 bytes

`∂⬭;⑥⑷;`¶C≬;Puzz0ɧ;¶+\ #__¶[*;Golf¶

Real shifty string compression going on here! Try it online!

Lyxal

Posted 2017-04-28T13:14:24.797

Reputation: 5 253

2

Lua, 56 bytes

print((#' '>#'')and'Programming Puzzles'or'Code\32Golf')

Try it online!

ouflak

Posted 2017-04-28T13:14:24.797

Reputation: 925

2

c, 73 bytes

With whitespace:

main(){printf("%s\n",atoi("- 1")?"Code\x20Golf":"Programming Puzzles");}

Without whitespace:

main(){printf("%s\n",atoi("-1")?"Code\x20Golf":"Programming Puzzles");}

Ryan Burrow

Posted 2017-04-28T13:14:24.797

Reputation: 61

1

Ruby, 56 bytes

puts"Code\x20Golf"if(" "=="")#
puts"Programming Puzzles"

The second string literal should contain a tab.

dkudriavtsev

Posted 2017-04-28T13:14:24.797

Reputation: 5 781

You can save a fair number of bytes if you change !(" ">" ") to " "=="". That should bring it to 56 bytes, by my count. – Chris – 2017-05-04T05:16:37.623

1

Braingolf, 53 bytes [non-competing]

Holy crap I did it

48*# 1+-?"Programming Puzzles"@19%"Code"1#!-"Golf"@9|

So the issue with Braingolf is that the only conditional it has is an "is the last number on the stack greater than 0?" check, which makes this kinda challenge a little tricky, but I persevered and here it is!

Non-competing because the language was created after the date of the challenge

Explanation: Whitespace version:

48*                                                    Push the int literals 4 and 8 to the stack, then multiply them together, consuming both and adding the result to the stack (32)
   #<space>                                            Add the charcode of the literal char <space> to the stack, which also happens to be 32
     1+                                                Push int literal 1 to the stack, then add together the last 2 elements of the stack (1 and 32)
       -                                               Subtract the last 2 elements of the stack from each other (33 - 32)
        ?                                              Check if the last element on the stack is greater than 0, 33-32 is 1, so it is (this also consumes the checked number from the stack)
         "Programming Puzzles"                         Add the charcodes for the string "Programming Puzzles" to the stack
                              @19                      Print the last 19 elements of the stack as chars
                                 %                     Else, nothing after this will run, as the ? returned true
                                  "Code"               Push the charcodes for the string "Code" to the stack
                                        1#!-           Push the literal int 1 and the charcode for the character '!' (33) to the stack, then subtract one from the other (33 - 1 = 32, the charcode for a space)
                                            "Golf"     Push the charcodes for the string "Golf" to the stack
                                                  @9   Print the last 9 elements of the stack as characters
                                                    |  End if-else, at this point Braingolf would normally output the last element of the stack, as there is no semicolon in the program, however the stack is empty, so it doesn't.

No whitespace version (only the important part):

48*        Same as last time, push 4 and 8 to the stack, then multiply them to make 32
   #1      This time add the charcode for the character '1' to the stack (which is 49)
     +     Add the last 2 elements of the stack together (32 + 49 = 81)
      -    Subtract the last 2 elements of the stack from each other, however there is only 1 element in the stack (81) so subtract it from itself, 0
       ?   Is the last (only) element in the stack greater than 0? (no, it is 0)
           At this point the code skips every character up until the % else, and then runs from there to the end.

Skidsdev

Posted 2017-04-28T13:14:24.797

Reputation: 9 656

1

Befunge-98, 51 bytes

]@,k9"Code"*84"Golf";
["selzzuP gnimmargorP">:#,_@;

Try it online!

The main idea here is to use the "turn right" operator (]) to check if there is a line below the first one. If there is, we print selzzuP gnimmargorP backwards. If the newline is removed, we turn right twice to go backwards on the top row. we use the ;s to skip the "Programming Puzzles" code and print Code Golf.

I have other ideas about how to golf this whole thing (having to do with the fact that ProgrammingPuzzles is exactly twice as long as Code Golf) but I thought I would post a simple version first, considering my other one is in progress.

MildlyMilquetoast

Posted 2017-04-28T13:14:24.797

Reputation: 2 907

1

Microscript II, 45 bytes

" "("Programming Puzzles"ph)"Code"p32Kp"Golf"

Or, which is one byte longer:

' s#("Programming Puzzles"ph)"Code"p32Kp"Golf"

SuperJedi224

Posted 2017-04-28T13:14:24.797

Reputation: 11 342

1

Microscript, 48 bytes

' d32{"floG"z32s"edoC"ah}"selzzuP gnimmargorP"ah

Or, which is the same length:

" "#{o"selzzuP gnimmargorP"ah}"floG"z32s"edoC"ah

Or:

' s#{o"selzzuP gnimmargorP"ah}"floG"z32s"edoC"ah

SuperJedi224

Posted 2017-04-28T13:14:24.797

Reputation: 11 342

1

Braingolf, 44 bytes

" "?"Programming Puzzles":"Code"48*"Golf"|&@

Try it online!

With whitespace removed:

""?"ProgrammingPuzzles":"Code"48*"Golf"|&@

Try it online!

Explanation

With whitespace:

" "                         push a space character
   ?                        if the last item on the stack > 0...
    "..."                   ...push the string "Programming Puzzles"
         :                  else...
          "..."             ...push the string "Code" and...
               48*          ...push 4 and 8 and multiply them and...
                  "..."     ...push the string "Golf"
                       |    end the conditional
                        &@  print all the characters on the stack

Without whitespace:

""                          push nothing
  ?                         if the last item on the stack > 0...
   "..."                    ...push the string "ProgrammingPuzzles"
        :                   else...
         "..."              ...push the string "Code" and...
              48*           ...push 4 and 8 and multiply them and...
                 "..."      ...push the string "Golf"
                      |     end the conditional
                       &@   print all the characters on the stack

totallyhuman

Posted 2017-04-28T13:14:24.797

Reputation: 15 378

1

Pip, 37 bytes

"Programming Puzzles"  "Code0Golf"R0s

Try it online!

Explanation

Comment abuse.

Anything following two spaces in Pip is a comment.* So with the spaces, this is just the string expression "Programming Puzzles", which is autoprinted. Without the spaces, the first expression doesn't do anything, and we instead autoprint "Code0Golf"R0s, which replaces the 0 in Code0Golf with a space.

My original idea, ' ?"Programming Puzzles""Code0Golf"R0s (fun with character literals), was 1 byte longer.

* Spaces at the beginning of a line don't count.

DLosc

Posted 2017-04-28T13:14:24.797

Reputation: 21 213

1

Petit Computer BASIC, 40 bytes

?"Code","Golf"'
CLS?"Programming Puzzles

The original program prints Code Golf and then clears the screen and prints Programming Puzzles. When whitespace is removed it becomes ?"Code","Golf"'CLS?"Programming Puzzles (' starts a comment), so only Code Golf is printed.

12Me21

Posted 2017-04-28T13:14:24.797

Reputation: 6 110

1

Zsh, 49 bytes

<<<${${:-ProgrammingPuzzles}/*gP*/$'Code\40Golf'}

Try it online!

With spaces (in fact, only one added):

<<<${${:-Programming Puzzles}/*gP*/$'Code\40Golf'}

Uses ${ /match/replacement}, and executes it on any string containing gP.

GammaFunction

Posted 2017-04-28T13:14:24.797

Reputation: 2 838