11
1
Sandbox post here.
Create a function or program that "Springifies" a string.
- Input will be a String in Stdin, or closest alternative
- Input will only contain printable ASCII and/or spaces
- Output will be to Stdout, or closest alternative
- A trailing newlines and spaces are acceptable
How to springify a String
- Format the String into as many ASCII spring coils as needed
- Pad the coils with spaces, up to the nearest coil
- Read off the characters, following the spring around the coils
This is an ASCII spring coil:
#
# ####
# #
# ####
#
Where the #s are the characters of the String
Here is an example:
abcdefghijklmnopqrstuvwxyz
becomes
a
b cdef
g h
i jklm
n
o
p qrst
u v
w xyz.
.
Where the .s replace spaces for visibility.
Then, the string is read back, following the ASCII spring downwards, around the loops, hitting the g and u twice:
1| a <-3
V b cdef
g h
4| i jklm
V n 2->
...
...giving:
abgjklmhfedcginopuxyz vtsrquw (with a trailing space)
Test Cases
(quotations added to highlight trailing spaces - please ignore in terms of IO)
I: "abcdefghijklmnopqrstuvwxyz"
O: "abgjklmhfedcginopuxyz vtsrquw "
I: "!@#"
O: "!@ # "
I: ""
O: ""
I: "12345 67890"
O: "12690 7 54368 "
I: " "
O: " "
Note that the output length is always a multiple of 15, the length of a spring coil
This is code-golf, so the shortest answer in bytes wins.

The main loop starts off executing right to left, wrapping around to the right hand side of the playfield. This is where we read the first character from stdin, and terminate if it's an EOF.
The next section makes sure any EOF characters are converted to spaces using the formula
A copy of the character is saved to temporary memory, and then a lookup of the current index is performed on the table on line four (
) to determine whether the character should be output or not.
If the character needs to be output, we take the left branch. A swap is performed here to cancel out the swap that's going to occur next, and then a zero is pushed to force the branch right.
If the character wasn't output, we swap it down the stack beneath the index counter (this is the swap that gets cancelled in the left branch). And in both cases we save the character to memory at the current index offset, increment the index, and check if it's greater than 13.
If not, we read the next character from stdin and repeat the inner loop.
If it is, we'll have finished a set of 14 characters, 7 having been output (
I feel like it would've been much more of a challenge to follow the pattern along the coil. – Magic Octopus Urn – 2017-01-20T14:52:42.303
@carusocomputing you mean the inverse? – MildlyMilquetoast – 2017-01-20T16:47:30.160
http://codegolf.stackexchange.com/a/107531/59376 turns out I didn't understand the challenge as written, that's exactly the challenge ahaha. – Magic Octopus Urn – 2017-01-20T17:00:16.123