79
\$\begingroup\$

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!

\$\endgroup\$
  • 3
    \$\begingroup\$ will the space in Code Golf also be removed, what about the one in Programming Puzzles. \$\endgroup\$ – colsw Apr 28 '17 at 13:20
  • 4
    \$\begingroup\$ This will be impossible in at least Whirl and Whitespace. \$\endgroup\$ – Engineer Toast Apr 28 '17 at 17:14
  • 13
    \$\begingroup\$ What are the close votes for? \$\endgroup\$ – OldBunny2800 Apr 28 '17 at 21:16
  • 12
    \$\begingroup\$ @OldBunny2800 good question. I keep asking that but the comment gets removed... \$\endgroup\$ – programmer5000 Apr 28 '17 at 21:19
  • 12
    \$\begingroup\$ The 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. \$\endgroup\$ – Magic Octopus Urn Apr 28 '17 at 22:00

60 Answers 60

1
2
3
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
3
\$\begingroup\$

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!

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ I think you have the outputs backwards. \$\endgroup\$ – Draco18s no longer trusts SE Nov 11 '19 at 20:56
  • \$\begingroup\$ Whoops lol, thanks. Fixed it \$\endgroup\$ – Cello Coder Nov 13 '19 at 16:45
  • \$\begingroup\$ You can reuse the a to get 68 bytes \$\endgroup\$ – Jo King Nov 16 '19 at 2:56
2
\$\begingroup\$

GolfScript, 38 bytes

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

Try it online!

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ What do the ,s do? \$\endgroup\$ – programmer5000 Apr 28 '17 at 21:14
  • \$\begingroup\$ @programmer5000 Each prints one character. \$\endgroup\$ – Martin Ender Apr 28 '17 at 21:51
  • \$\begingroup\$ 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 \$\endgroup\$ – MildlyMilquetoast May 23 '17 at 0:09
2
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

PowerShell, 54 bytes

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

Try it online!

Without spaces

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

Try it online!

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

Ruby, 46 bytes

puts' '[0]?'Programming Puzzles':"Code\40Golf"
| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

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!

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

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!
| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

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!

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

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!

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

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
| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

bash, 51 bytes

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

TIO

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

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.
| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

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"
| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

Lua, 56 bytes

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

Try it online!

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

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");}
| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

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!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

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.
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

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
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Microscript II, 45 bytes

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

Or, which is one byte longer:

' s#("Programming Puzzles"ph)"Code"p32Kp"Golf"
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Ruby, 56 bytes

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

The second string literal should contain a tab.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ You can save a fair number of bytes if you change !(" ">" ") to " "=="". That should bring it to 56 bytes, by my count. \$\endgroup\$ – Chris May 4 '17 at 5:16
1
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

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
| improve this answer | |
\$\endgroup\$
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.