35
3
A snakified string looks like this:
T AnE eOf ifi ing
h s x l A k e r
isI amp Sna dSt
Your Task
Take a string s
and a size n
, then output the snakified string. The inputs ThisIsAnExampleOfaSnakifiedString
and 3
would produce the example above.
Specifications
s
will only contain ASCII characters between code points 33 and 126 inclusive (no spaces or newlines).s
will be between 1 and 100 characters long.n
is an integer representing the size of each output string segment. Each line of characters (up/down or left/right) that make up the curves in the "snake" isn
characters long. See the test cases for examples.n
will be between 3 and 10 inclusive.- The output string always starts pointing downwards.
- Trailing spaces on each line are allowed.
- Trailing newlines at the end of the output are also allowed.
- Leading spaces are not allowed.
- code-golf means shortest code in bytes wins.
Test Cases
a 3
a
----------
Hello,World! 3
H Wor
e , l
llo d!
----------
ProgrammingPuzzlesAndCodeGolf 4
P ngPu Code
r i z d G
o m z n o
gram lesA lf
----------
IHopeYourProgramWorksForInputStringsWhichAre100CharactersLongBecauseThisTestCaseWillFailIfItDoesNot. 5
I gramW tStri 100Ch gBeca CaseW DoesN
H o o u n e a n u t i t o
o r r p g r r o s s l I t
p P k n s A a L e e l f .
eYour sForI Which cters ThisT FailI
----------
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ 10
! <=>?@ABCDE `abcdefghi
" ; F _ j
# : G ^ k
$ 9 H ] l
% 8 I \ m
& 7 J [ n
' 6 K Z o ~
( 5 L Y p }
) 4 M X q |
*+,-./0123 NOPQRSTUVW rstuvwxyz{
I'm guessing the next challenge will be to convert a snakified string back to the original 2 parameters ... – abligh – 2016-04-07T07:24:25.433
@abligh I had no further plans, but that actually sounds like a decent idea. There could be some form of duplicate though, so I'll need to check that first. Stay tuned! – user81655 – 2016-04-07T07:32:55.827
the reverse challenge would be more fun if the snake can be an arbitrary shape ... – abligh – 2016-04-07T07:41:38.317
@abligh That's exactly what I was planning on doing haha! – user81655 – 2016-04-07T07:42:25.853
@abligh Done!
– user81655 – 2016-04-07T10:24:25.520Guess what: Mathematica will have a built-in for that. – Erik the Outgolfer – 2016-10-04T13:14:23.157