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 GolfandProgramming Puzzleswill 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$ @42then that must output
Programming Puzzles. Also, in the same language,42$@rw$@42must output
Code Golf.
This is code-golf, so the shortest code in bytes wins! Good luck!
64 Answers 64
Python 2, 50 bytes
print["Code40円Golf","Programming Puzzles"][" ">""]
With all spaces removed:
print["Code40円Golf","ProgrammingPuzzles"]["">""]
Thanks to Stephen S for 3 bytes, and Erik the Outgolfer for 1
-
2\$\begingroup\$ Darn, ninja'd! I was just about to click Post Answer! +1 \$\endgroup\$2017年04月28日 13:22:55 +00:00Commented Apr 28, 2017 at 13:22
-
2\$\begingroup\$ I think you just broke my friend's brain. How does this even work? \$\endgroup\$Stevoisiak– Stevoisiak2017年04月28日 15:09:57 +00:00Commented Apr 28, 2017 at 15:09
-
15\$\begingroup\$ @StevenVascellaro It's really simple. In the first case,
" ">""returnsTrue, since, lexicographically, a space is greater than the empty string. In the second case,"">""returnsFalse, since nothing can be greater than itself.TrueandFalseare actually just1and0respectively, just in thebooldatatype instead ofintorlong. 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\x20in the item at index 0"Code\x20Golf"to preserve a space. \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2017年04月28日 15:26:32 +00:00Commented Apr 28, 2017 at 15:26 -
11\$\begingroup\$ @StephenS Nope, because unlike JavaScript, Python doesn't have an obsession with implicit casting. \$\endgroup\$user45941– user459412017年04月28日 15:57:40 +00:00Commented Apr 28, 2017 at 15:57
-
4\$\begingroup\$ If find Python's lack of obsession disturbing. \$\endgroup\$John Dvorak– John Dvorak2017年04月28日 19:56:13 +00:00Commented Apr 28, 2017 at 19:56
Python 2, (削除) 48 (削除ここまで) 47 bytes
-1 byte thanks to Erik the Outgolfer
print' 'and'Programming Puzzles'or'Code40円Golf'
print''and'ProgrammingPuzzles'or'Code40円Golf'
-
10\$\begingroup\$ Aww, I was just about to improve my answer to this... \$\endgroup\$user45941– user459412017年04月28日 13:29:24 +00:00Commented Apr 28, 2017 at 13:29
Jelly, 17 bytes
"Ñ1ɦ+£)G"1⁄2ċṭ6 Ỵ»Ṃ
How it works
As in the other Jelly answer, Ñ1ɦ+£)G and 1⁄2ċṭ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 1⁄2ċṭ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.
-
\$\begingroup\$ Just did the same with
"½ċṭ6Ỵ"Ñ1ɦ +£)G»Ṁ\$\endgroup\$Jonathan Allan– Jonathan Allan2017年04月29日 08:00:50 +00:00Commented Apr 29, 2017 at 8:00 -
\$\begingroup\$ 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? \$\endgroup\$steffen– steffen2017年05月04日 19:55:53 +00:00Commented May 4, 2017 at 19:55
-
\$\begingroup\$ @steffen Jelly uses a custom code page that encodes each of the 256 characters it understands as a single byte. \$\endgroup\$Dennis– Dennis2017年05月04日 21:48:36 +00:00Commented May 4, 2017 at 21:48
-
22\$\begingroup\$ Where it all started. \$\endgroup\$Razetime– Razetime2020年10月10日 04:34:29 +00:00Commented Oct 10, 2020 at 4:34
C, (削除) 64 (削除ここまで) (削除) 62 (削除ここまで) (削除) 53 (削除ここまで) 52 bytes
f(){puts(*" "?"Programming Puzzles":"Code40円Golf");}
Uses the fact that C strings end with a null character
05AB1E, 15 bytes
"ƒËŠˆ"" "v"–±ÇÀ
Explanation
"ƒËŠˆ" # push "Code Golf"
" "v # for each character in the string " " do
"–±ÇÀ # push "Programming Puzzles"
# implicitly output top of stack
-
\$\begingroup\$ ...I just don't get it. Does this use dictionary compression or something? \$\endgroup\$LegionMammal978– LegionMammal9782017年04月30日 02:15:04 +00:00Commented Apr 30, 2017 at 2:15
-
\$\begingroup\$ @LegionMammal978 I'm pretty sure it does. \$\endgroup\$NoOneIsHere– NoOneIsHere2017年04月30日 03:15:32 +00:00Commented Apr 30, 2017 at 3:15
-
\$\begingroup\$ @LegionMammal978: It does indeed use dictionary compression. \$\endgroup\$Emigna– Emigna2017年04月30日 08:59:55 +00:00Commented Apr 30, 2017 at 8:59
-
6\$\begingroup\$ @Emigna Okay, because last I checked, neither of those strings could be fit into 4 bytes :p \$\endgroup\$LegionMammal978– LegionMammal9782017年04月30日 10:27:23 +00:00Commented Apr 30, 2017 at 10:27
-
1
Jelly, 18 bytes
"1⁄2ċṭ6Ỵ»ḷ
"Ñ1ɦ+£)G»
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. "1⁄2ċṭ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.
-
\$\begingroup\$ This turns out to be valid. \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2017年04月28日 15:34:36 +00:00Commented Apr 28, 2017 at 15:34
-
\$\begingroup\$ 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? \$\endgroup\$steffen– steffen2017年05月04日 19:59:10 +00:00Commented May 4, 2017 at 19:59
-
\$\begingroup\$ @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.) \$\endgroup\$user62131– user621312017年05月04日 21:12:08 +00:00Commented May 4, 2017 at 21:12
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.
-
32\$\begingroup\$ Your code is sad
:(\$\endgroup\$Linnea Gräf– Linnea Gräf2017年04月28日 13:51:25 +00:00Commented Apr 28, 2017 at 13:51 -
16\$\begingroup\$ If you're willing to use unprintables,
"Bncd\x19Fnke":)is happy code instead (replace\x19). \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2017年04月28日 15:58:22 +00:00Commented Apr 28, 2017 at 15:58
Javascript, (削除) 46 (削除ここまで) (削除) 43 (削除ここまで) 42 Bytes
x=>" "?"Programming Puzzles":"Code40円Golf"
console.log((x=>" "?"Programming Puzzles":"Code40円Golf")())
console.log((x=>""?"ProgrammingPuzzles":"Code40円Golf")())
-
5\$\begingroup\$ You can replace the
\x20in the first string with a space. \$\endgroup\$Shaggy– Shaggy2017年04月28日 13:30:58 +00:00Commented Apr 28, 2017 at 13:30 -
1\$\begingroup\$ Beat me to it, nicely done. Does this need a trailing
;? \$\endgroup\$ricdesi– ricdesi2017年04月28日 15:22:57 +00:00Commented Apr 28, 2017 at 15:22 -
1\$\begingroup\$ @ricdesi no, it dosen't. \$\endgroup\$user68614– user686142017年04月28日 15:31:41 +00:00Commented Apr 28, 2017 at 15:31
-
4\$\begingroup\$ @ricdesi since this is codegolf, if the program runs, it works.
;s are sometimes not required in JavaScript. \$\endgroup\$Stephen– Stephen2017年04月28日 15:52:33 +00:00Commented Apr 28, 2017 at 15:52 -
4\$\begingroup\$ You can replace
\x20with40円to save a byte :-) \$\endgroup\$ETHproductions– ETHproductions2017年04月28日 18:32:22 +00:00Commented Apr 28, 2017 at 18:32
Haskell, 48 bytes
a _="Programming Puzzles";a4="Code32円Golf";f=a 4
a_="ProgrammingPuzzles";a4="Code32円Golf";f=a4
Defines function f which returns the corresponding string.
For reference, the old version is:
Haskell, 49/47 bytes
f""="Code32円Golf";f(_)="Programming Puzzles";f" "
with spaces removed
f""="Code32円Golf";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$"Code32円Golf":["Programming Puzzles"|" ">""]
last$"Code32円Golf":["ProgrammingPuzzles"|"">""]
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...
-
1\$\begingroup\$ As soon as you paste (or type) this into Mathematica, (cloud based or not) the escape sequence,
\:0020turns into a space, and thus would be removed, so I'm not sure this qualifies. Also\.20is shorter.by two characters."Programming Puzzles"["Code"<>FromCharacterCode@32<>"Golf"][[01]]will work. \$\endgroup\$Kelly Lowder– Kelly Lowder2017年04月28日 20:12:31 +00:00Commented Apr 28, 2017 at 20:12 -
1\$\begingroup\$ @KellyLowder, hmm, that's a good point. I've added another solution that should avoid that issue. (Thanks for the
\.20suggestion — how did you find that? I thought I'd scoured the whole documentation...) \$\endgroup\$Not a tree– Not a tree2017年04月28日 22:56:21 +00:00Commented Apr 28, 2017 at 22:56 -
1\$\begingroup\$ I found the
\.20by making a typo. Seems to only work for two-digit character codes. I don't think it's in the documentation. \$\endgroup\$Kelly Lowder– Kelly Lowder2017年05月01日 13:48:40 +00:00Commented May 1, 2017 at 13:48
Excel - 56 Bytes
=IF(""=" ","Code"&CHAR(32)&"Golf","Programming Puzzles")
Very similar to most of the other answers... nothing fancy here.
Ohm, (削除) 33 (削除ここまで) 32 bytes
Uses CP437 encoding.
▀Bn¬i≈╣Ü╝Rb╡°╧S1⁄2uÇ▀
▀4>~H├MS░l╬δ
Try it online! or try without whitespace
Explanation
With whitespace:
▀Bn¬i≈╣Ü╝Rb╡°╧S1⁄2uÇ▀ Main wire
▀Bn¬i≈╣Ü╝Rb╡°╧S1⁄2uÇ▀ Push "Programming Puzzles" (compressed string)
Implicitly output the top stack element
▀4>~H├MS░l╬δ Helper wire (never called)
Without whitespace:
▀Bn¬i≈╣Ü╝Rb╡°╧S1⁄2uÇ▀▀4>~H├MS░l╬δ Main wire
▀Bn¬i≈╣Ü╝Rb╡°╧S1⁄2uÇ▀ Push "Programming Puzzles" (compressed string)
▀4>~H├MS░l╬δ Push "Code Golf" (compressed string)
Implicitly output top stack element
-
\$\begingroup\$ I'm so glad I finally finished string compression! \$\endgroup\$Nick Clifford– Nick Clifford2017年05月02日 20:01:45 +00:00Commented May 2, 2017 at 20:01
-
1\$\begingroup\$ @NickClifford The curious thing I noticed was that
Code Golfgot 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. \$\endgroup\$Business Cat– Business Cat2017年05月02日 20:05:07 +00:00Commented May 2, 2017 at 20:05 -
\$\begingroup\$ Yeah, Smaz is kind of weird like that. \$\endgroup\$Nick Clifford– Nick Clifford2017年05月02日 20:07:18 +00:00Commented May 2, 2017 at 20:07
-
\$\begingroup\$ FYI, feel free to ping me in chat if you have any questions or feature requests for Ohm. \$\endgroup\$Nick Clifford– Nick Clifford2017年05月02日 20:18:32 +00:00Commented May 2, 2017 at 20:18
Japt, 29 bytes
With spaces:
`Co ̧{S}Golf`r `PgmÚÁ Puzz¤s
Without spaces:
`Co ̧{S}Golf`r`PgmÚÁPuzz¤s
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.
-
\$\begingroup\$ I didn't even think of using replace. Nice one! \$\endgroup\$Tom– Tom2017年04月28日 14:39:20 +00:00Commented Apr 28, 2017 at 14:39
-
\$\begingroup\$ 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? \$\endgroup\$steffen– steffen2017年05月04日 19:57:45 +00:00Commented May 4, 2017 at 19:57
-
\$\begingroup\$ @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) \$\endgroup\$ETHproductions– ETHproductions2017年05月04日 20:00:43 +00:00Commented May 4, 2017 at 20:00
Brachylog, 44 bytes
" "Ṣ∧"Programming Puzzles"w|"Code"wṢw"Golf"w
Explanation
" "Ṣ If " " = Ṣ (which is itself " ")
∧"Programming Puzzles"w Write "Programming Puzzles"
| Else
"Code"w Write "Code"
Ṣw Write " "
"Golf"w Write "Golf"
-
1\$\begingroup\$ Crossed out 44 is still 44 :( Edit in
on either side to fix :) \$\endgroup\$2017年04月28日 13:41:11 +00:00Commented Apr 28, 2017 at 13:41 -
\$\begingroup\$ @HyperNeutrino It's not crossed out, 44 is the length with spaces, and 42 without. \$\endgroup\$Fatalize– Fatalize2017年04月28日 13:41:43 +00:00Commented Apr 28, 2017 at 13:41
-
\$\begingroup\$ Oh. Whoops. Well, it's too similar so I couldn't tell without looking at the markdown by going into edit. Never mind :P \$\endgroup\$2017年04月28日 13:42:44 +00:00Commented Apr 28, 2017 at 13:42
Alice, 44 bytes
/"floG!"t"edoC"#
/"selzzuP gnimmargorP"d&o@
Without whitespace:
/"floG!"t"edoC"#/"selzzuPgnimmargorP"d&o@
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.
-
\$\begingroup\$ You must golf this (crossed out 44 is 44) \$\endgroup\$MilkyWay90– MilkyWay902019年01月11日 01:55:32 +00:00Commented Jan 11, 2019 at 1:55
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)];
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.
-
1\$\begingroup\$ +1, just one thing: "but any sub-expression prefixed with a
,is evaluated and spliced in" Isn't,@necessary for splicing? \$\endgroup\$user65167– user651672017年05月03日 15:46:49 +00:00Commented May 3, 2017 at 15:46 -
\$\begingroup\$ "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. \$\endgroup\$djeis– djeis2017年05月03日 17:04:02 +00:00Commented May 3, 2017 at 17:04
Perl 5, (削除) 43 (削除ここまで) 41 bytes
say" "?"Programming Puzzles":Code.$".Golf
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.
-
1\$\begingroup\$ maybe late but
"Code$\"Golf"is shorter andCode.$".Golftoo \$\endgroup\$Nahuel Fouilleul– Nahuel Fouilleul2019年01月09日 13:09:38 +00:00Commented Jan 9, 2019 at 13:09 -
\$\begingroup\$ @NahuelFouilleul Yeah, I was pretty new when I wrote this answer. Thanks though! \$\endgroup\$Chris– Chris2019年01月09日 17:19:03 +00:00Commented Jan 9, 2019 at 17:19
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')
-
\$\begingroup\$ 49 bytes \$\endgroup\$Robin Ryder– Robin Ryder2019年11月08日 11:48:22 +00:00Commented Nov 8, 2019 at 11:48
Pyth, 37 bytes
?" ""Programming Puzzles""Code40円Golf
?"""ProgrammingPuzzles""Code40円Golf
dc, 50
[pq]sm[Programming Puzzles]dZ19=m[Code]n32P[Golf]p
[ ] 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.
-
\$\begingroup\$ Could you link to the dc interpreter / docs / github? \$\endgroup\$user58826– user588262017年04月29日 01:14:09 +00:00Commented Apr 29, 2017 at 1:14
-
\$\begingroup\$ @programmer5000 Just choose dc on TIO, then click the language name. \$\endgroup\$Dennis– Dennis2017年04月29日 01:15:19 +00:00Commented Apr 29, 2017 at 1:15
-
\$\begingroup\$ @Dennis thanks, I didn't even know that TIO does that! \$\endgroup\$user58826– user588262017年04月29日 01:18:08 +00:00Commented Apr 29, 2017 at 1:18
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. (削除ここまで)
-
1\$\begingroup\$ you can prefix the function name with an
@, so then you havevoid@a...and avoid the "no return type" compilation error (also adds bytes, though :( ) \$\endgroup\$Brian J– Brian J2017年04月28日 15:36:59 +00:00Commented Apr 28, 2017 at 15:36 -
\$\begingroup\$
.Length<1saves one byte;\u0020saves 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=()=>...\$\endgroup\$Peter Taylor– Peter Taylor2017年04月28日 15:37:48 +00:00Commented Apr 28, 2017 at 15:37 -
\$\begingroup\$ @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! \$\endgroup\$Mayube– Mayube2017年04月28日 15:38:25 +00:00Commented Apr 28, 2017 at 15:38
-
\$\begingroup\$ @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)). \$\endgroup\$Brian J– Brian J2017年04月28日 15:41:02 +00:00Commented Apr 28, 2017 at 15:41 -
1\$\begingroup\$ Yes, it requires returning the string; but if you use
=>instead ofreturnyou don't need any spaces. (And even if you usereturn, you canreturn(...)). \$\endgroup\$Peter Taylor– Peter Taylor2017年04月28日 15:47:53 +00:00Commented Apr 28, 2017 at 15:47
Java 8, (削除) 74 (削除ここまで) (削除) 50 (削除ここまで) 48 bytes
()=>" "==""?"Code040円Golf":"Programming Puzzles"
-
\$\begingroup\$ @NonlinearFruit you're right, I've changed that one to be non-competent \$\endgroup\$Khaled.K– Khaled.K2017年05月01日 18:50:21 +00:00Commented May 1, 2017 at 18:50
-
1\$\begingroup\$ I 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"\$\endgroup\$NonlinearFruit– NonlinearFruit2017年05月01日 19:59:13 +00:00Commented May 1, 2017 at 19:59 -
2\$\begingroup\$
\u00A0->040円for a 2 byte savings. \$\endgroup\$Poke– Poke2017年05月03日 18:47:14 +00:00Commented May 3, 2017 at 18:47
><>, (削除) 47 (削除ここまで) 45 bytes
! v"floG!"1-"edoC"!
o<>"selzzuP gnimmargorP">
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.
APL (Dyalog Unicode), (削除) 45 (削除ここまで) (削除) 41 (削除ここまで) 39 bytes SBCS
Anonymous lambda. Takes dummy argument.
{'Programming Puzzles'
⊢4⌽9↑'GolfCode'}
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'}
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.
Wren, 62 bytes
System.write(" ".count>0?"Programming Puzzles":"Code\x20Golf")
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")
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"
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)
-
1\$\begingroup\$ I think you have the outputs backwards. \$\endgroup\$Draco18s no longer trusts SE– Draco18s no longer trusts SE2019年11月11日 20:56:08 +00:00Commented Nov 11, 2019 at 20:56
-
\$\begingroup\$ Whoops lol, thanks. Fixed it \$\endgroup\$Cello Coder– Cello Coder2019年11月13日 16:45:59 +00:00Commented Nov 13, 2019 at 16:45
-
-
1\$\begingroup\$ Heh, I was just about to post the same thing :-) \$\endgroup\$ETHproductions– ETHproductions2017年04月28日 14:30:08 +00:00Commented Apr 28, 2017 at 14:30
-
1\$\begingroup\$ Actually, there is a shorter way... \$\endgroup\$ETHproductions– ETHproductions2017年04月28日 14:35:36 +00:00Commented Apr 28, 2017 at 14:35
Code Golfalso be removed, what about the one inProgramming Puzzles. \$\endgroup\$