# Snakes all around

## 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. • 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.) – El'endia Starman Jul 31 '16 at 20:15 • Is a function enough or do you want a full program? – betseg Jul 31 '16 at 20:17 • @betseg function is enough – InitializeSahib Jul 31 '16 at 20:17 • I'm afraid all My Squiggly Lamp answers are effortlessly portable to this. – manatwork Aug 1 '16 at 12:49 • Negative integers should cause the snake to swallow itself. – GuitarPicker Aug 2 '16 at 12:35 ## 89 Answers # Hexagony, 33 bytes Not gonna win, but still cool. Might be able to get golfed more. Try it online! Golfed: 61}?.$)@$j;(3<./;.}l/.400;5\j;.'\ Formatted: 6 1 } ? .$ ) @ $j ; ( 3 < . / ; . } l / . 4 0 0 ; 5 \ j ; . ' \ . . . . Colored (Made using Timwi's Hexagony Colorer) Explanation: Loop, print out "=" until the counter reaches 0. 6 1 } ? .$ . . $. . ( . . . / . . } . . . . . . ; . . . . . ' . . . . . Print "(" . . . . . . . . . . . . . . . / ; . . . . . 4 . . . . . j . . . . . . . . Print ":" . . . . . . . . . . ; ( 3 < . . . . } l / . . . . . . . . . . . . . . . . Print ")" . . . . . . . . . j . . . . . . . . . . . . . . . ; 5 \ . . . . \ . . . . The above values were generated using a simple python script. However, I kind of ran out of room for the "-". So, I had to resort to more advanced tricks. When the program prints out ")", the value of the cell isn't 41, it's 1065. Hexagony just mods the value when printing. As it turns out, (1065*1000+4)%256=44, just one away from 45, the ascii value for "-". Then, I just increment, print, and insert a @ somewhere after printing. . . . . .$ ) @ $j . . 3 . . / . . } . . . 4 0 0 . 5 \ . ; . . \ . . . . • How can it be called a programming language when .j4/; is ... Print "("??? Which part of .j4/; is the print and which part is the string to print? – Fogmeister Aug 1 '16 at 23:36 • @Fogmeister [Part 1/2] In Hexagony, any alphabetical character sets the value of the current memory cell to the ascii value of that character. "j" has an ascii value of 106, so that is what the memory is set to. Also, and numerical characters multiply the value of the current cell by 10, then add themselves to it (this allows for easy construction of numbers, like the 61 at the beginning. – Blue Aug 2 '16 at 0:23 • [Part 2/2] So, j4 sets the memory cell to 1064. When the IP reaches the "/", it gets reflected into ";", which prints out the ascii character corresponding to the current memory cell % 256. 1064%256=40, the ascii value for "(". I hope this answers your question. – Blue Aug 2 '16 at 0:25 • thanks. Yeah it does. I guess this is more of a language to use as a way of testing your brain. Rather than a way to write programmes then? Interesting. – Fogmeister Aug 2 '16 at 0:27 • @Fogmeister there are many esoteric programming languages that are more brain twisting exercises than useful for doing real work, although they CAN do real work if you try hard enough. – Sparr Aug 9 '16 at 1:53 # Cinnamon Gum, 7 bytes 0000000: 7043 dc95 6d4f ce pC..mO. Try it online. Would have been 6 bytes with the old p syntax :/ # Explanation Decompresses to p~=~(:)-, the p stage then simply reads input and repeats the = n times. • Can you link to language spec for this? – Robert Fraser Aug 1 '16 at 5:07 • @RobertFraser I don't have a formal specification or any documentation currently, but you can check out the source at the GitHub repo: github.com/quartata/cinnamon-gum – a spaghetto Aug 1 '16 at 12:52 ## Brian & Chuck, 31 bytes ,{-?>}-):(=? #}<<.{?_<.<.<.<.<. Input in the form of a byte value, so e.g. input ! gives a snake of length 33. Try it online! It's been a while... ### Explanation A quick Brian & Chuck primer: • The first line of the program is Brian, the second is Chuck. • Brian and Chuck are two Brainfuck-like instances. The main catch is that Chuck's program is Brian's tape and vice versa. The tape heads/instruction pointers start on the first cell of each tape and execution starts on Brian. • As for the commands, there are a few differences. Only Brian can use , (input) and only Chuck can use . (output). In addition to < and > there are { and } which move the tape head up to the next zero cell (or in the case of { to the left end of the tape if there is no zero cell on the way). Instead of [...], the only control flow is ? which switches control to the other instance if the current cell is non-zero. The first executed instruction on the other cell is the one after the condition. And finally, _ is just an alias for null-bytes, for convenience. Now the code. Brian starts with this: ,{-? This reads the input into Chuck's first cell, then moves the tape head to the left with { (does nothing right now) and decrements the input with - before switching control for Chuck if the value is still non-zero. This begins the main loop. Chuck then runs this bit: }<<.{? This moves the tape head on Brian to the very end, moves two cells left onto the = and prints it before the tape head all the way to the left and switching control back to Brian. This is how loops generally work in B&C. Once the input has been reduced to zero, the ? on Brian's tape will do nothing. Then Brian executes this part: >}-):(=? The ):(= are no-ops, so the actual code is just >}-?. We move off the zero cell with >, move up to _ with }, decrement it to make it non-zero and switch to Chuck with ?. Then the last bit on Chuck is run: <.<.<.<.<. This simply prints the five characters in front of Chuck, i.e. =(:)-. Note that we need to print another = since the main loop is only executed N-1 times for input N. • Congrats on 100k – Insane Aug 1 '16 at 10:47 # V, 8 bytes Àé=A(:)- Try it online! V uses the "Latin1" encoding. Explanation: À "Arg1 times: é= "Insert an '=' A(:)- "Append the head • I count 10 bytes – Zwei Aug 1 '16 at 6:32 • @zwei see my edit. – DJMcMayhem Aug 1 '16 at 6:37 • Got it! That's better. – Zwei Aug 1 '16 at 6:39 # Retina, 10 bytes .+$*=(:)-

Try it online!

This is a simple regex substitution.

It matches .+ which matches the whole input, and then substitutes it with $*=(;)-. The$* is a feature unique in Retina: it is the character-repetition special operator.

For example, 5$*x would become xxxxx. In the case that the previous argument is absent, the whole match is used as the default argument. # Python, 21 bytes lambda n:"="*n+"(:)-" Ideone it! • You can cut 3 bytes by doing: "="*input()+"(:)-" – gowrath Aug 29 '16 at 16:57 • @gowrath Then it won't be printing anything – Leaky Nun Aug 29 '16 at 18:31 • It'll output it if you're in the interpreter no? Op said you can get output in any way. – gowrath Aug 29 '16 at 18:59 • @gowrath You can't assume that we're in REPL – Leaky Nun Aug 29 '16 at 19:00 • Is that a general rule for code golfing? New here :) – gowrath Aug 29 '16 at 19:02 # Haskell, 25 bytes f n=('='<$[1..n])++"(:)-"

Full program. Takes input $args[0], uses string multiplication to construct the body, then string concatenation to tack on the head. PS C:\Tools\Scripts\golfing> .\snakes-all-around.ps1 7 =======(:)- PS C:\Tools\Scripts\golfing> .\snakes-all-around.ps1 77 =============================================================================(:)- • Kudos to you, I got as far as 26: "$("="*[int]$args[0])(:)-" – Chirishman Aug 29 '16 at 21:33 # C, 464543 bytes saved 2 bytes thanks to owacoder! saved 3 bytes thanks to rici! f(n){while(4-printf("=\0(:)-"+2*!n--));} Try it on Ideone! • The mysterious --> operator strikes again. – Leaky Nun Jul 31 '16 at 20:37 • @LeakyNun 46 bytes version was without the goes to operator, than I remembered the goes to operator ;) – betseg Jul 31 '16 at 20:41 • You can remove the >0 and save two bytes. – owacoder Jul 31 '16 at 20:47 • Slightly shorter: f(n){while(4-printf("=\0(:)-"+2*!n--));} – rici Aug 2 '16 at 2:38 # Cheddar, 15 bytes (noncompeting) n->'='*n+'(:)-' A straightforward answer. # Sesos, 11 bytes Hexdump: 0000000: aaaa5e a0f7b4 ed4cee 5d3b ..^....L.]; Try it online! Assembler: set numin add 61 fwd 1 get jmp,sub 1,rwd 1,put,fwd 1,jnz add 40,put rwd 1,sub 3,put fwd 1,add 1,put add 4,put ## K, 17 Bytes {,[x#"=";"(:)-"]} Example; f:{,[x#"=";"(:)-"]} -1(f'!10); /print out the result of calling f where x is 0 1 2 3 4 5.... (:)- =(:)- ==(:)- ===(:)- ====(:)- =====(:)- ======(:)- =======(:)- ========(:)- =========(:)- Explanation; {} /function x is implicit and is an int x#"=" /take (#) x of "=" --> so 3#"=" gives "===" ,[x#"=";"(:)-"] /comma is a join that takes 2 args --> ,[x;y] gives the concatination of x and y --> "a","abc" is the same as ,["a";"abc"] and gives "aabc" • What is -1(...);? – Adám Aug 1 '16 at 16:04 • Save a byte: {(x#"="),"(:)-"} – Adám Aug 1 '16 at 16:06 • Thanks Adam. -1 Prints to the console. -1"Hello"; will print Hello – Chromozorz Aug 1 '16 at 16:09 • But isn't printing implicit? – Adám Aug 1 '16 at 16:11 • Yes but it includes the double quotes... "====(:)-" rather than; =====(:)- – Chromozorz Aug 1 '16 at 17:22 # Perl, 16 + 1 (-p flag) = 17 bytes$_="="x$_."(:)-" Needs -p flag, so run with : perl -pe '$_="="x$_."(:)-"' ## Minkolang 0.15, 12 bytes "=(:)-"nD$O.

Try it here!

### Explanation

"=(:)-"         Push this to the stack in reverse order - ["-",")",":","(","="]
n        Take number from input
D       Pop k and duplicate top of stack (the "=") k times
\$O.    Output whole stack as characters and stop.

# Befunge-98, 24 bytes

Takes numerical input from the user, then prints the snake.

'=&:00pk:00gk,"-):("4k,@

# Matlab / Octave, 22 bytes

@(n)[~(1:n)+61 '(:)-']

This is an anonymous function.

### Explanation

Assume n= 5.

1:n produces the row vector [1 2 3 4 5].

~(1:n) negates each entry, so it gives [0 0 0 0 0].

...+61 adds 61 to each entry, so it gives [61 61 61 61 61]. 61 is the ASCII value of character =.

[... '(:)-'] concatenates that with the string '(:)-'. This automatically converts [61 61 61 61 61] into the string '=====' before the concatenation.