Write a program or function which, given an input string and a standard deviation σ
, outputs that string along the normal distribution curve with mean 0
and standard deviation σ
.
Normal distribution curve
The y
coordinate of each character c
is:
where σ
is given as input, and where x
is the x
axis coordinate of c
.
- The character in the center of the string has
x = 0
. If the string's length is even, either of the two middle characters can be chosen as the center. - Characters are separated by steps of
0.1
(e.g. the character to the left of the center one hasx = -0.1
, the one to the right of the middle one hasx = 0.1
, etc.).
Printing the string
- Lines, like characters, are separated by steps of
0.1
. - Each character is printed on the line with the
y
value that is closest to its owny
value (if the value is precisely in between the values of two lines, choose the one with the biggest value (just like howround
usually returns1.0
for0.5
)). - For example, if the
y
coordinate of the center value (i.e. the maximum value) is0.78
and they
coordinate of the first character is0.2
, then there will 9 lines: the center character being printed on line0
and the first character being printed on line8
.
Inputs and outputs
- You may take both inputs (the string and
σ
) as program arguments, throughSTDIN
, function arguments or anything similar in your language. - The string will only contain printable
ASCII
characters. The string can be empty. σ > 0
.- You may print the output to
STDOUT
, in a file, or return it from a function (as long as it is a string and not say a list of strings for each line). - A trailing new line is acceptable.
- Trailing spaces are acceptable as long as they don't make the line exceed the last line in length (so no trailing space is acceptable on the last line).
Test cases
σ String
0.5 Hello, World!
, W
lo or
l l
e d
H !
0.5 This is a perfectly normal sentence
tly
ec n
f o
r r
e m
p a
a l
s se
This i ntence
1.5 Programming Puzzles & Code Golf is a question and answer site for programming puzzle enthusiasts and code golfers.
d answer site for p
uestion an rogramming
Code Golf is a q puzzle enthusia
Programming Puzzles & sts and code golfers.
0.3 .....................
.
. .
. .
. .
. .
. .
. .
. .
... ...
Scoring
This is code-golf,
nsw
a er
t
s i
e n
t
or by
sh te
so the s wins.