30
1
Goal: Write a program or function which prints an input string in a sinusoidal shape.
The ASCII sinusoid
Here is one period of the sinusoid:
.......
... ...
.. ..
. .
. .
. .
. . .
. .
. .
. .
.. ..
... ...
.......
Note that there is exactly one dot on each column.
- Each character in the input string will replace a dot in the shape above, from left to right.
- Spaces in the input have to be outputted like normal characters, in place of a dot.
- The starting character corresponds to the leftmost dot in the figure above.
- This is only one period, inputs can be longer than the number of dots above.
Input
- Inputs are ASCII strings that contain only characters between ASCII decimal 32 (space) and ASCII decimal 126 (Tilde ~).
- Inputs will always be one line only (no linebreaks).
- Inputs can be taken via STDIN, function parameters, command line arguments, or anything similar.
Output
- Output must be printed exactly like they are in the test cases given.
- Trailing spaces on lines are allowed as long as the length of the line with those trailing spaces does not exceed the length of the longest line (the one with the last character on it).
- No leading/trailing line allowed.
Test cases
- Input:
.................................................
Output:
.......
... ...
.. ..
. .
. .
. .
. . .
. .
. .
. .
.. ..
... ...
.......
- Input:
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.
Output:
ng Puzz ion and siasts stratio
mmi les est an thu and egi n r
ra & qu sw en c r eq
g e o o u
o C a r e d n i
r o l e r
P d s s z , e
e i i z g e d
t u o e .
G e e p l r
ol ng f g fe f
f S cha or min rs. 00%
tack Ex program It's 1
- Input:
Short text.
Output:
t.
tex
t
r
o
h
S
- Input:
The quick brown fox jumps over the lazy dog
Output:
brown
ick fox
qu j
u
e m
h p
T s
o
v
er
th dog
e lazy
Scoring
This is code-golf, so the shortest program or function in bytes wins.
This is what I was thinking of – Beta Decay – 2015-07-26T12:52:45.700
Oh I see it is indeed somewhat similar. – Fatalize – 2015-07-26T12:56:09.257
Incidentally, your wave is not quite sinusoidal. (Naturally I tried using a
sin
function to reproduce it but the positions are a little off.) – David Z – 2015-07-27T11:09:03.663@DavidZ That doesn't surprise me, I eyeballed the ASCII shape. Can you even get something sinusoidal without any "gap" in the columns (i.e. exactly one dot per column)? – Fatalize – 2015-07-27T11:11:06.980
Sure, it's like plotting: you can calculate the height of a sine wave at each 1/48th of a period, round it, and put the letter at that height. It only differs from yours by one spot in each of a few columns. – David Z – 2015-07-27T11:14:02.067
Taking
sin(x*pi/24)^a*b
and rounding away from infinity generates the right wave for some 0 < a < 1 and 5 < b < 6! – Lynn – 2015-07-27T13:39:01.807Also related
– Digital Trauma – 2015-07-27T15:49:35.9104I spent a couple minutes entertaining myself by moving the scroll bar on test case 2's output back and forth really fast. – mbomb007 – 2015-07-27T16:41:53.410
What should you output for the input "Short"? Should there be two leading newlines? – FryAmTheEggman – 2015-07-27T21:39:07.337
@FryAmTheEggman That would be acceptable I guess. This edge case is not in the test cases so I can't change the rules since there are already a lot of answers. – Fatalize – 2015-07-27T21:41:15.287