40
\$\begingroup\$

A current internet meme is to type 2spooky4me, with a second person typing 3spooky5me, following the (n)spooky(n+2)me pattern.

Your mission is to implement this pattern in your chosen language. You should write a program or function that takes a value n (from standard input, as a function argument, or closest alternative), and outputs the string (n)spooky(n+2)me (without the parentheses; to standard output, as a return value for a function, or closest alternative).

Your solution should work for all inputs, from 1 up to 2 below your language's maximum representable integer value (2^32-3 for C on a 32-bit machine, for example).

Example implementation in Python:

def spooky(n):
    return "%dspooky%dme"%(n,n+2)

spooky(2) -> "2spooky4me"

This is , so standard loopholes are forbidden, and the shortest answer in bytes wins!

Leaderboard

The Stack Snippet at the bottom of this post generates the leaderboard from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

## Language Name, N bytes

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

## Ruby, <s>104</s> <s>101</s> 96 bytes

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

## Perl, 43 + 2 (-p flag) = 45 bytes

You can also make the language name a link which will then show up in the snippet:

## [><>](http://esolangs.org/wiki/Fish), 121 bytes

<style>body { text-align: left !important} #answer-list { padding: 10px; width: 290px; float: left; } #language-list { padding: 10px; width: 290px; float: left; } table thead { font-weight: bold; } table td { padding: 5px; }</style><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="language-list"> <h2>Shortest Solution by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr> </thead> <tbody id="languages"> </tbody> </table> </div> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr> </thead> <tbody id="answers"> </tbody> </table> </div> <table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table><script>var QUESTION_ID = 62350; var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe"; var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk"; var OVERRIDE_USER = 45941; var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page; function answersUrl(index) { return "https://api.stackexchange.com/2.2/questions/" + QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER; } function commentUrl(index, answers) { return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER; } function getAnswers() { jQuery.ajax({ url: answersUrl(answer_page++), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { answers.push.apply(answers, data.items); answers_hash = []; answer_ids = []; data.items.forEach(function(a) { a.comments = []; var id = +a.share_link.match(/\d+/); answer_ids.push(id); answers_hash[id] = a; }); if (!data.has_more) more_answers = false; comment_page = 1; getComments(); } }); } function getComments() { jQuery.ajax({ url: commentUrl(comment_page++, answer_ids), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { data.items.forEach(function(c) { if (c.owner.user_id === OVERRIDE_USER) answers_hash[c.post_id].comments.push(c); }); if (data.has_more) getComments(); else if (more_answers) getAnswers(); else process(); } }); } getAnswers(); var SCORE_REG = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/; var OVERRIDE_REG = /^Override\s*header:\s*/i; function getAuthorName(a) { return a.owner.display_name; } function process() { var valid = []; answers.forEach(function(a) { var body = a.body; a.comments.forEach(function(c) { if(OVERRIDE_REG.test(c.body)) body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>'; }); var match = body.match(SCORE_REG); if (match) valid.push({ user: getAuthorName(a), size: +match[2], language: match[1], link: a.share_link, }); else console.log(body); }); valid.sort(function (a, b) { var aB = a.size, bB = b.size; return aB - bB }); var languages = {}; var place = 1; var lastSize = null; var lastPlace = 1; valid.forEach(function (a) { if (a.size != lastSize) lastPlace = place; lastSize = a.size; ++place; var answer = jQuery("#answer-template").html(); answer = answer.replace("{{PLACE}}", lastPlace + ".") .replace("{{NAME}}", a.user) .replace("{{LANGUAGE}}", a.language) .replace("{{SIZE}}", a.size) .replace("{{LINK}}", a.link); answer = jQuery(answer); jQuery("#answers").append(answer); var lang = a.language; lang = jQuery('<a>'+lang+'</a>').text(); languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang.toLowerCase(), user: a.user, size: a.size, link: a.link}; }); var langs = []; for (var lang in languages) if (languages.hasOwnProperty(lang)) langs.push(languages[lang]); langs.sort(function (a, b) { if (a.lang_raw > b.lang_raw) return 1; if (a.lang_raw < b.lang_raw) return -1; return 0; }); for (var i = 0; i < langs.length; ++i) { var language = jQuery("#language-template").html(); var lang = langs[i]; language = language.replace("{{LANGUAGE}}", lang.lang) .replace("{{NAME}}", lang.user) .replace("{{SIZE}}", lang.size) .replace("{{LINK}}", lang.link); language = jQuery(language); jQuery("#languages").append(language); } }</script>

\$\endgroup\$
  • 2
    \$\begingroup\$ For bonus points: Input %dspooky%dme, validate and return next in series. \$\endgroup\$ – clap Oct 31 '15 at 6:13
  • 23
    \$\begingroup\$ True, but Dennis would still win \$\endgroup\$ – clap Oct 31 '15 at 6:19
  • 7
    \$\begingroup\$ Who is Dennis? :O \$\endgroup\$ – NuWin Feb 15 '16 at 20:39
  • 10
    \$\begingroup\$ @NuWin Dennis is the way. Dennis is the light. \$\endgroup\$ – Alex A. Feb 15 '16 at 23:02
  • 1
    \$\begingroup\$ @NuWin Dennis is love, Dennis is life \$\endgroup\$ – user63571 Jan 25 '17 at 19:40

80 Answers 80

2
\$\begingroup\$

Gema, 21 characters

*=*spooky@add{$0;2}me

Sample run:

bash-4.3$ echo -n 42 | gema '*=*spooky@add{$0;2}me'
42spooky44me
\$\endgroup\$
2
\$\begingroup\$

Java, 39 35 bytes

n->"".format("%dspooky%dme",n,n+2);

A lambda expression that takes an int and returns a string.

\$\endgroup\$
2
\$\begingroup\$

Scala, 30 bytes

(n:Int)=>s"${n}spooky${n+2}me"
\$\endgroup\$
2
\$\begingroup\$

jq, 21 characters

(20 characters code + 1 character command line option.)

"\(.)spooky\(.+2)me"

Sample run:

bash-4.3$ jq -r '"\(.)spooky\(.+2)me"' <<< 42
42spooky44me

On-line test (Passing -r through URL is not supported – check Raw Output yourself.)

\$\endgroup\$
2
\$\begingroup\$

Jolf, 15 bytes

Try it here! I forgot about inline string interpolation until after @quartata posted his solution.

"¦jspooky¦+2jme

Explanation

"¦jspooky¦+2jme
"               string containing
 ¦j              the input,
   spooky        "spooky"
         ¦+2j    2 + the input,
             me  and "me"
                implicitly printed.
\$\endgroup\$
2
\$\begingroup\$

R, 38 bytes

n=scan();sprintf("%dspooky%dme",n,n+2)

or (same length)

sprintf("%dspooky%dme",n<<-scan(),n+2)

Example:

n=scan();sprintf("%dspooky%dme",n,n+2)
1: 999
999spooky1001me
\$\endgroup\$
  • 1
    \$\begingroup\$ paste0(n<-scan(),"spooky",n+2,"me") for 35 :-) \$\endgroup\$ – J.Doe Oct 9 '18 at 11:48
2
\$\begingroup\$

Groovy, 24 22 bytes

{it+"spooky${it+2}me"}
\$\endgroup\$
  • \$\begingroup\$ At string's ends is shorter to concatenate: {it+"spooky${it+2}me"}. \$\endgroup\$ – manatwork Mar 23 '16 at 7:45
2
\$\begingroup\$

Jelly, non-competing

13 bytes This answer is non-competing, since the challenge predates the creation of Jelly.

+0,2ż“×¥X“ŀ`»

I CAN'T OUTGOLF QUARTATA HELP

Try it online!

How it works

+0,2ż“×¥X“ŀ`»  Main link. Input: n

+0,2           Add [0, 2] to n, resulting in [n, n + 2].
     “×¥X“ŀ`»  Yield ['spooky, 'me'] by indexing into a dictionary.
    ż          Zip the results to left and right with each other.
               This yields [[n, 'spooky'], [n + 2, 'me']], which is flattened
               before printing.
\$\endgroup\$
  • 7
    \$\begingroup\$ One does not simply outgolf... quartata? \$\endgroup\$ – Arcturus Mar 31 '16 at 2:23
  • \$\begingroup\$ I can't seem to outgolf quartata, but, since the answer is non-competing, I can give some help. +2ṭż“×¥X“ŀ`» \$\endgroup\$ – Erik the Outgolfer Feb 15 '17 at 17:45
2
\$\begingroup\$

PowerShell, 31 30 29 bytes

param($x)"$x`spooky$($x+2)me"

Try it online!

Takes input $x, constructs and leaves a string on the pipeline with implicit output. The string is formed from $x spooky $x+2 me, with the trick being the ` that allows the variable name to be escaped to be just $x instead of $xspooky.

-1 byte thanks to Veskah.

\$\endgroup\$
  • \$\begingroup\$ param($x)"$x`spooky$($x+2)me" is one shorter \$\endgroup\$ – Veskah Jul 18 '18 at 2:44
1
\$\begingroup\$

Burlesque, 21 bytes

J2?+Cl"~spooky~me"jf~

Needs fixed stack layout. Not usable except as a stand-alone program. Otherwise use one of the versions below that are more generic.

Alternative versions:

"~spooky~me"jbxJ2?+_+f~ [24 bytes]
J"spooky"?+j2?+"me"?+?+ [24 bytes, too]
\$\endgroup\$
1
\$\begingroup\$

O, 20 bytes

j.o"spooky"o))o"me"o

Kinda long Try it online

j          Get input as Number
.          Clone the number to add to later
o          Print the number
"spooky"o  Print spooky
))o        Increment the input by two and print
"me"o      Print me
\$\endgroup\$
1
\$\begingroup\$

Bash, 24 bytes

echo $1spooky$(($1+2))me

Takes input as command line argument

\$\endgroup\$
  • 1
    \$\begingroup\$ There is also an old syntax for arithmetic evaluation: $[]. It is deprecated, but that usually not holds us back from using it. \$\endgroup\$ – manatwork Mar 23 '16 at 14:39
1
\$\begingroup\$

Coffeescript, 23 bytes

(n)->n+"spooky#{n+2}me"

Anonymous function that takes int n and returns <n>spooky<n+2>me.

\$\endgroup\$
  • \$\begingroup\$ Nice! You could save two bytes with (n)->n+"spooky#{n+2}me". \$\endgroup\$ – ETHproductions Oct 31 '15 at 23:15
  • \$\begingroup\$ @ETHproductions Didn't think of that! Thanks! \$\endgroup\$ – Zane Martin Oct 31 '15 at 23:23
1
\$\begingroup\$

JS (ES5) 41

Oh, ES6...

function(a){alert(a+"spooky"+(a+2)+"me")}
\$\endgroup\$
1
\$\begingroup\$

C++11, 142 130 108 bytes

Self-imposed challenge: no C headers

#include<sstream>
#include<string>
[](int x){std::stringstream q;q<<x<<"spooky"<<x+2<<"me";return q.str();}

Thanks to Mego for saving a few bytes with the return logic everything.

\$\endgroup\$
  • \$\begingroup\$ Good tip. I'll make the changes accordingly. \$\endgroup\$ – James Murphy Oct 31 '15 at 23:53
  • \$\begingroup\$ That's terrifying, and also really neat. \$\endgroup\$ – James Murphy Nov 1 '15 at 0:16
  • \$\begingroup\$ Ooh. That's good. \$\endgroup\$ – James Murphy Nov 1 '15 at 0:24
1
\$\begingroup\$

C# 33 bytes

string s(n)=>$"{n}spooky{n+2}me";
\$\endgroup\$
1
\$\begingroup\$

Dart, 27 Bytes

t(n)=>'${n}spooky${n+2}me';

Unremarkable but competitive.

\$\endgroup\$
  • \$\begingroup\$ Welcome to Programming Puzzles & Code Golf! \$\endgroup\$ – Dennis Nov 2 '15 at 20:44
1
\$\begingroup\$

Carrot (version ^3), 14 bytes

#spooky(#+2)me

Explanation:

Carets ^ have now been made optional if you do not want to use commands. The # is the variable representing the input. Every instance of # is replaced with the value of input. Going to the parentheses, the expression inside the parentheses is evaluated and a number is returned.

Test it online here. Please note that this is not permalinked.

\$\endgroup\$
  • 1
    \$\begingroup\$ Did you write this before the challenge, and do you have proof? \$\endgroup\$ – lirtosiast Nov 3 '15 at 15:04
  • \$\begingroup\$ @ThomasKwa I started writing this on the 1st of November. And proof is in Carrot's website \$\endgroup\$ – Cows quack Nov 3 '15 at 15:50
  • 1
    \$\begingroup\$ I might actually start using Carrot. XD \$\endgroup\$ – Addison Crump Nov 8 '15 at 11:59
1
\$\begingroup\$

pl, 12 bytes

_spooky_2┼me

Try it online.

Non-competing since pl was invented after this challenge.

\$\endgroup\$
1
\$\begingroup\$

><>, 25 (+2) = 27 bytes

:n'emykoops'oooooo{2+noo;

Starting with a value (n) on top of the stack from -v (2 byte penalty). Explanation:

:            Duplicates top item on stack
 n           Pops and outputs top value on stack as number -> n
  'emykoops' Pushes each character onto the stack
   o         x5 Pops and outputs top value on stack as character -> "spooky"
    {        Shift stack leftwards making input value top value
     2       Pushes 2 on the stack
      +      Pops top 2 elements, sums them and pushes result
       n     Pops and outputs top value on stack as number -> n+2
        o    x2 Pops and outputs top value on stack as character -> "me"
         ;   Ends execution
\$\endgroup\$
1
\$\begingroup\$

Seriously, 20 bytes (non-competing)

"me",;⌐@"spooky"@kεj

Since this challenge partially inspired this language, I figured I should go ahead and add a solution. Try it online!

\$\endgroup\$
  • \$\begingroup\$ A golfing language partially based on this challenge got 20 whole bytes? \$\endgroup\$ – Cyoce Feb 23 '16 at 6:31
  • \$\begingroup\$ @Cyoce I still haven't implemented the parts of the language that were inspired by this challenge (raw strings mode). \$\endgroup\$ – Mego Feb 23 '16 at 6:36
1
\$\begingroup\$

F#, 33 bytes

fun n->printf"%ispooky%ime"n<|n+2
\$\endgroup\$
1
\$\begingroup\$

Squirrel, 25 bytes

@(n)n+"spooky"+(n+2)+"me"
\$\endgroup\$
1
\$\begingroup\$

D, 71 bytes

import std.string;string s(int i){return format("%sspooky%sme",i,i+2);}

More verbose than Java...

\$\endgroup\$
1
\$\begingroup\$

Jolf, 16 bytes

"%spooky%me"J+2J

Try it online.

\$\endgroup\$
1
\$\begingroup\$

Retina, 17 bytes

This assumes that the integer n may be expressed in unary in the output. Each line would go in its own file, with one byte added per additional file.

1+
$_spooky$_11me

If the input is 11, the output is 11spooky1111me.

For non-unary output (but still unary input), use this (27 bytes):

1+
$_spooky$_11me
(\d)+
$#1

Try it online

\$\endgroup\$
  • \$\begingroup\$ Is unary the standard way of expressing numbers in retina? \$\endgroup\$ – Cyoce Feb 23 '16 at 6:14
1
\$\begingroup\$

Applesoft BASIC, 28 bytes

0input n:?n;"spooky";n+2;"me

The question mark expands to PRINT and the missing final double quotation mark is implied.

Tested with Joshua Bell's online emulator.

\$\endgroup\$
1
\$\begingroup\$

Pylongolf, 20 bytes  

_:AA"spooky"A2+"me"~

_ asks for input and :A puts it into the variable A.
A"spooky" pushes A, and spooky then A2+ adds the input + 2.
After that we push "me" into the stack and print it with ~.

\$\endgroup\$
1
\$\begingroup\$

Stacked, 21 bytes

[:2+,'spooky'#`'me'+]

Try it online!

Function returning the string.

Explanation

[:2+,'spooky'#`'me'+]
[                   ]  function                stack: (y)
 :                     duplicate               stack: (y y)
  2+                   add 2                   stack: (y y+2)
    ,                  pair                    stack: ((y y+2))
     'spooky'#`        join by "spooky"        stack: ("{y}spooky{y+2}")
               'me'+   append the string "me"  stack: ("{y}spooky{y+2}me")
\$\endgroup\$
1
\$\begingroup\$

LOLCODE, 100 99 bytes

HAI 1.3
I HAS A J
GIMMEH J
VISIBLE J!
VISIBLE "spooky"!
VISIBLE SUM OF J AN 2!
VISIBLE "me"
KTHXBYE

Try it online!

\$\endgroup\$

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.