48
\$\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\$
6
  • 3
    \$\begingroup\$ For bonus points: Input %dspooky%dme, validate and return next in series. \$\endgroup\$
    – clapp
    Commented Oct 31, 2015 at 6:13
  • 27
    \$\begingroup\$ True, but Dennis would still win \$\endgroup\$
    – clapp
    Commented Oct 31, 2015 at 6:19
  • 10
    \$\begingroup\$ Who is Dennis? :O \$\endgroup\$
    – NuWin
    Commented Feb 15, 2016 at 20:39
  • 17
    \$\begingroup\$ @NuWin Dennis is the way. Dennis is the light. \$\endgroup\$
    – Alex A.
    Commented Feb 15, 2016 at 23:02
  • 2
    \$\begingroup\$ @NuWin Dennis is love, Dennis is life \$\endgroup\$
    – user63571
    Commented Jan 25, 2017 at 19:40

122 Answers 122

3
\$\begingroup\$

Cookie, 16 bytes

Note that the recent changes to the Github page were not made for this challenge, Cookie is still in development.

wŕspooky[r+2]me"

Explanation:

wŕspooky[r+2]me"
w                 start write command
 ŕ                take input
  spooky          write spooky
        [r+2]     compute input + 2
             me   write me
               "  close write command.
\$\endgroup\$
0
2
\$\begingroup\$

Python, 31 bytes

lambda n:"%dspooky%dme"%(n,n+2)

Ask and you shall receive.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Python 3.6+ lambda n:f'{n}spooky{n+2}me' for 28 bytes. \$\endgroup\$
    – mypetlion
    Commented Nov 10, 2017 at 23:14
2
\$\begingroup\$

Mouse, 25 bytes

?N:N.!"spooky"2N.+!"me"$

Ungolfed:

? N:         ~ Read an integer N from STDIN
N. !         ~ Write N to STDOUT
"spooky"     ~ String literals go straight to STDOUT
2 N. + !     ~ Print N+2
"me"
$            ~ End of program
\$\endgroup\$
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\$

Bash, 24 bytes

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

Takes input as command line argument

\$\endgroup\$
1
  • 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
    Commented Mar 23, 2016 at 14:39
2
\$\begingroup\$

pl, 12 bytes

_spooky_2┼me

Try it online.

Non-competing since pl was invented after this challenge.

\$\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\$

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\$
1
  • \$\begingroup\$ param($x)"$x`spooky$($x+2)me" is one shorter \$\endgroup\$
    – Veskah
    Commented Jul 18, 2018 at 2:44
2
\$\begingroup\$

Java 8, 24 bytes

n->n+"spooky"+(n+2)+"me"

That moment when Java is actually competitive... (and by competitive I mean top 40 :P)

Try it online!

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

Pyramid Scheme, 624 bytes

   ^      ^      ^      ^     ^      ^      ^      ^      ^
  / \    / \    / \    / \   / \    / \    / \    / \    / \
 /set\  /out\  /out\  /out\ /out\  /out\  /out\  /out\  /out\
^-----^^-----^ -----^ -----^----- ^----- ^-----^ -----^ -----^
-    ^--    / \    / \    / \    / \    / \   /+\    / \    / \
    /#\    /chr\  /chr\  /chr\  /chr\  /chr\ ^---^  /chr\  /chr\
   ^---   ^----- ^----- ^----- ^----- ^-----/2\  - ^----- ^-----
  /l\    / \    / \    / \    / \    / \    ---   / \    / \
 /ine\  /115\  /112\  /111\  /107\  /121\        /109\  /101\
 -----  -----  -----  -----  -----  -----        -----  -----

Try it online!

Very straightforward. Gets an integer from input and saves it to the blank variable. Prints it. Prints "spooky". Prints blank+2. Prints "me". Follows the same pattern as Hello, World, for the most part.

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

Wren, 31 bytes

Not special, just uses some formatting

Fn.new{|n|"%(n)spooky%(n+2)me"}

Try it online!

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

MarioLANG, 221 bytes

;>+>+>+>+>.>)
:"+"+"+"+"-"-
)++++++++.-:-
+++++++++--+-"
+++++++++.-+-.
+++++++++-.(--
+++++++++-+.--
+++++++++-++--
+++++++++.++--
++++++++++++--
++++++++++++--
++++++++++++--
++++++++++++--
+!+!+!+!+!+!.!
=#=#=#=#=#=#=#

Try it online!

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

Canvas, 13 bytes

╶spooky╶├me)∑

Try it here!

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

Aussie++, 60 bytes

THE HARD YAKKA FOR f IS(n)<BAIL ""+n +"spooky"+(n +2)+"me";>

Tested in commit e0091bc.

For some reason, the space in n + is required. The empty string at the beginning seems unnecessary but isn't, see this issue.

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

Regenerate, 19 bytes

$~1spooky${$~1+2}me

Attempt This Online!

Explanation

$~1spooky${$~1+2}me
$~1                  First command-line input
   spooky            spooky
         ${     }    Treat the result of this expression as a string:
           $~1         First command-line input
              +2       Plus 2
                 me  me
\$\endgroup\$
2
\$\begingroup\$

Go, 70 bytes

import."fmt"
func f(n int)string{return Sprintf("%dspooky%dme",n,n+2)}

Attempt This Online!

\$\endgroup\$
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\$

Coffeescript, 23 bytes

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

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

\$\endgroup\$
2
  • \$\begingroup\$ Nice! You could save two bytes with (n)->n+"spooky#{n+2}me". \$\endgroup\$ Commented Oct 31, 2015 at 23:15
  • \$\begingroup\$ @ETHproductions Didn't think of that! Thanks! \$\endgroup\$ Commented Oct 31, 2015 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\$
3
  • \$\begingroup\$ Good tip. I'll make the changes accordingly. \$\endgroup\$ Commented Oct 31, 2015 at 23:53
  • \$\begingroup\$ That's terrifying, and also really neat. \$\endgroup\$ Commented Nov 1, 2015 at 0:16
  • \$\begingroup\$ Ooh. That's good. \$\endgroup\$ Commented Nov 1, 2015 at 0:24
1
\$\begingroup\$

C# 33 bytes

string s(n)=>$"{n}spooky{n+2}me";
\$\endgroup\$
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\$
3
  • 1
    \$\begingroup\$ Did you write this before the challenge, and do you have proof? \$\endgroup\$
    – lirtosiast
    Commented Nov 3, 2015 at 15:04
  • \$\begingroup\$ @ThomasKwa I started writing this on the 1st of November. And proof is in Carrot's website \$\endgroup\$
    – user41805
    Commented Nov 3, 2015 at 15:50
  • 1
    \$\begingroup\$ I might actually start using Carrot. XD \$\endgroup\$ Commented Nov 8, 2015 at 11:59
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\$

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\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.