14
\$\begingroup\$

Challenge

The challenge is simple: print a snake.
You will get the length of the snake as input.
A snake of length 2 looks like this:

==(:)-

A snake of length 7 looks like this:

=======(:)-

In other words, the length of a snake is how many equal signs are before the head.

Usage

Let's say I made a C++ implementation and compiled it to ./getsnake.
I could run it like so:

$ ./getsnake 10
==========(:)-

Clarifications

  • Standard loopholes are disallowed.
  • You can get input and output in any acceptable way.
  • You can assume all inputs given are positive integers.
  • You may write a function instead of a regular program.
\$\endgroup\$
14
  • 8
    \$\begingroup\$ It's kinda useless to leave a challenge in the Sandbox for only half an hour. You did get some feedback, but it's usually best to leave it in the Sandbox for 24-72 hours. (Also, you should either flesh out the "Origins" part or remove it.) \$\endgroup\$ Jul 31, 2016 at 20:15
  • \$\begingroup\$ Is a function enough or do you want a full program? \$\endgroup\$
    – betseg
    Jul 31, 2016 at 20:17
  • \$\begingroup\$ @betseg function is enough \$\endgroup\$ Jul 31, 2016 at 20:17
  • 4
    \$\begingroup\$ I'm afraid all My Squiggly Lamp answers are effortlessly portable to this. \$\endgroup\$
    – manatwork
    Aug 1, 2016 at 12:49
  • 3
    \$\begingroup\$ Negative integers should cause the snake to swallow itself. \$\endgroup\$ Aug 2, 2016 at 12:35

89 Answers 89

1 2
3
0
\$\begingroup\$

𝔼𝕊𝕄𝕚𝕟, 10 chars / 13 bytes

⍘=Ċï+'(:)-

Try it here (ES6 browsers only).

Should be rather self-explanatory.

\$\endgroup\$
0
\$\begingroup\$

PHP, 27 bytes

Not the most wonderfull creation, but with register_globals on you can set it via url.

<?=str_repeat('=',$n)?>(:)-
\$\endgroup\$
0
\$\begingroup\$

Ruby, 20 bytes

->n{puts?=*n+"(:)-"}
\$\endgroup\$
0
\$\begingroup\$

Ruby, 27 bytes

puts"="*($*[0].to_i)+"(:)-"
\$\endgroup\$
1
  • \$\begingroup\$ No need for the parenthesis. \$\endgroup\$
    – manatwork
    Aug 9, 2016 at 12:35
0
\$\begingroup\$

J, 14 bytes

'(:)-',~'='#~]

Very simple. This is a five train:

'(:)-' ,~ '=' #~ ]

Both strings, in this case, become constant verbs. #~ essentially repeats its left argument the amount of times as its right argument. ,~ then appends its left argument to the end of its right argument.

Test cases:

   f 2
==(:)-
   f 7
=======(:)-
   f 10
==========(:)-
   f 0
(:)-

I think that it would look more snake-like with a tilde at the end, but eh.

\$\endgroup\$
0
\$\begingroup\$

Kotlin, 34 bytes

{String(ByteArray(it){61})+"(:)-"}

This assumes that a function of (Int)->String type is requested (in such case, it is assumed to be an Int). Version with explicit typing (40 bytes):

{n:Int->String(ByteArray(n){61})+"(:)-"}

Try it out on the JVM target:

fun main(args: Array<String>) {
    val f: (Int)->String = {String(ByteArray(it){61})+"(:)-"}
    println(f(5))
}
\$\endgroup\$
0
\$\begingroup\$

R, 39 bytes

Mildly different than others above

for(i in 1:scan())cat("=");cat("(:)-")

or, if we can precede the line with the input

->n;for(i in 1:n)cat("=");cat("(:)-")
\$\endgroup\$
0
\$\begingroup\$

Perl, 16 bytes

say'='x<>.'(:)-'

Takes input from stdin

\$\endgroup\$
0
\$\begingroup\$

Pyke, 10 bytes

\=*"(:)-"+

Try it here!

Or 8 bytes (noncompeting)

\=*"(:)-

Try it here!

\$\endgroup\$
0
\$\begingroup\$

Ruby, 24 bytes

def f(l) ?=*l+"(:)-";end
\$\endgroup\$
0
\$\begingroup\$

PyMin, 15 bytes

»"="*¬+"(:)-"
\$\endgroup\$
0
\$\begingroup\$

GameMaker Language, 49 bytes

s="(:)-"for(a=0;a<argument0;a++){s="="+s}return s
\$\endgroup\$
0
\$\begingroup\$

Python, 23 bytes

print'='*input()+'(:)-'
\$\endgroup\$
2
  • \$\begingroup\$ Unless it's Python 3, you can remove the int() part. \$\endgroup\$
    – acrolith
    Aug 8, 2016 at 21:33
  • \$\begingroup\$ @daHugLenny thanks, -5 bytes \$\endgroup\$ Aug 9, 2016 at 1:06
0
\$\begingroup\$

Factor 34

[ [ "="write ] times "(:>~"print ]

Quotation (anonymous function) that takes a number and prints a snake.

Alternative (also 34):

[ 61 <string> ":>~""("glue print ]

Sorry, but i made some aesthetic changes...

10 [ [ "="write ] times "(:>~"print ] call
==========(:>~
\$\endgroup\$
0
\$\begingroup\$

Neoscript, 15 bytes

{n|'=*n+"(:)-"}
\$\endgroup\$
0
\$\begingroup\$

Fourier, 28 bytes

I(61ai^~i)40a-8a58a32a41a+4a

Try it online

\$\endgroup\$
0
\$\begingroup\$

Bash, 52 36 bytes

while [[ ${#a} -lt $1 ]];do a=$a=;done;echo "$a(:)~"

printf -vs %$1s;echo "${s// /=}(:)~"

Excellent suggestion by @manatwork.

If one would like to use external programs (sed) this could be a bit smaller(31 bytes):

printf "%$1s(:)~"|sed 's/ /=/g'

Run like that:

$ bash snake.sh 1
=(:)~
$ bash snake.sh 3
===(:)~
\$\endgroup\$
1
  • 1
    \$\begingroup\$ I would go without while: printf -vs %$1s;echo "${s// /=}(:)~". \$\endgroup\$
    – manatwork
    Aug 1, 2016 at 12:50
0
\$\begingroup\$

GNU sed, 16 bytes

y/0/=/;s/$/(:)-/

Since sed has no native support for numbers, the input is given in unary based on this consensus.

Run:

sed -f snake.sed <<< "000"

Output:

===(:)-
\$\endgroup\$
0
\$\begingroup\$

ECMAScript 6, 37 44 37 bytes

Try it here!

Golfed

alert("=".repeat(prompt())+"(:)-");

Ungolfed

alert("=".repeat(prompt()) + "(:)-");

Revisions

  • Original revision.
  • Added alert(); because it used to save to a variable, n. Try it here!
  • Used ECMAScript 6's String.prototype.repeat method instead of the previous method that didn't even work and took more bytes. Try it here!

ECMAScript 6, 53 bytes

This is a version of the above code that is a function, not a full program. Try it here!

Golfed

function makeSnakeArt(n){return"=".repeat(n)+"(:)-")}

Ungolfed

function makeSnakeArt(n) {
    return "=".repeat(n) + "(:)-"
}

alert(makeSnakeArt(5));

Revisions

  • Original revision, stemming off the 3rd revision of the full program. Try it here!
  • Returns the snake instead of alerting it. Try it here!
\$\endgroup\$
2
0
\$\begingroup\$

Scala, 30 Bytes

(x:Int)=>print(("="*x)+"(:)-")
\$\endgroup\$
0
\$\begingroup\$

Microscript, 14 bytes

ic'=P]"-):("ah
\$\endgroup\$
0
\$\begingroup\$

Microscript II, 13 bytes

"="sN*p"(:)-"
\$\endgroup\$
0
\$\begingroup\$

SNOBOL4 (CSNOBOL4), 39 bytes

 OUTPUT =LPAD('(:)-',INPUT + 4,'=')
END

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Charcoal, 7 bytes

×=N(:)-

Try it online!

This is equivalent to the following code:

Print(Times("=", InputNumber()));
Print("(:)-");
\$\endgroup\$
0
\$\begingroup\$

Excel VBA, 20 Bytes

Anonymous VBE immediate window function that takes input, a, from range [A1] and outputs a snake of the length a to the VBE immediate window.

?[Rept("=",A1)]"(:)-
\$\endgroup\$
0
\$\begingroup\$

Sinclair ZX80 (4K ROM) ~39 bytes

 1 INPUT L
 2 FOR I=1 TO L
 3 PRINT "=";
 4 NEXT I
 5 PRINT "(:)-"

No explanation needed really.

\$\endgroup\$
0
\$\begingroup\$

JavaScript 6, input unary '=', 11B

x=>x+'(:)-'

Standard rule allowes it.

Fix it if that's not what you want.

\$\endgroup\$
1
  • \$\begingroup\$ Meta seems to say for such language unary is not allowed but also say allowed. Not sure which \$\endgroup\$
    – l4m2
    Dec 18, 2017 at 19:29
0
\$\begingroup\$

MATL, 12 bytes

61iY"'(:)-'h

Try it on MATL Online.

Explanation

61       % ASCII value for '='
i        % Take input number, n
Y"       % Row vector with 61 repeated n times
'(:)-'   % Push this string
h        % Concatenate horizontally. This converts to string. Implicitly display
\$\endgroup\$
0
\$\begingroup\$

Silicon, 12 bytes

I"="*"(:)-"+

Explanation:

I"="*"(:)-"+

    *   Times
I       Get an integer as input
"="     Push "="

"(:)-"  Push "(:)-"
+       Append

Alternatively, 11 bytes:

"="ã"(:)-"+
\$\endgroup\$
1 2
3

Your Answer

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

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