if you want to test the one liner version with input from stdin
, your input has to be entered as oneone single string
, so you'd have to enclose your input between '
characters.
Example:
if you want to test the one liner version with input from stdin
, your input has to be entered as one string
, so you'd have to enclose your input between '
characters.
Example:
if you want to test the one liner version with input from stdin
, your input has to be entered as one single string
, so you'd have to enclose your input between '
characters.
Example:
Matlab, 133133, 130 bytes
s=input('');y=ceil(5.6*sin(0:pi/24:pi-.1).^.9);l=[-y y]+7;n=numel(s);t=char(ones;t=repmat(' ',13,n)*32);for k=1:n;t(l(mod(k-1,48)+1),k)=s(k);end;t
function f(s)
y=ceil(5.6*sin(0:pi/24:pi-.1).^.9);l=[-y y]+7; %// calculate the line number for each column position
n=numel(s); %// number of character in input
t=char(onest=repmat(' ',13,n)*32); %// Create a blank canvas of whitespace characters
for k=1:n
t(l(mod(k-1,48)+1),k)=s(k); %// place each input character where it should be
end
t %// force the output display
The one liner takes input from the console (stdin
) and is 133130 bytes. The expanded version replace the console input by a function definition (+1 byte) but is much more comfortable to use for the test case in a loop:
t =
.......
... ...
.. ..
. .
. .
. .
. . .
. .
. .
. .
.. ..
... ...
.......
t =
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
t =
t.
tex
t
r
o
h
S
t =
brown
ick fox
qu j
u
e m
h p
T s
o
v
er
th dog
e lazy
if you want to test the one liner version with input from stdin
, your input has to be entered as one string
, so you'd have to enclose your input between '
characters.
Example:
'Short text.' %// valid input
Short text. %// INVALID input
Thanks Luis Mendo
for shaving up 3 bytes ;-)
Matlab, 133 bytes
s=input('');y=ceil(5.6*sin(0:pi/24:pi-.1).^.9);l=[-y y]+7;n=numel(s);t=char(ones(13,n)*32);for k=1:n;t(l(mod(k-1,48)+1),k)=s(k);end;t
function f(s)
y=ceil(5.6*sin(0:pi/24:pi-.1).^.9);l=[-y y]+7; %// calculate the line number for each column position
n=numel(s); %// number of character in input
t=char(ones(13,n)*32); %// Create a blank canvas of whitespace characters
for k=1:n
t(l(mod(k-1,48)+1),k)=s(k); %// place each input character where it should be
end
t %// force the output display
The one liner takes input from the console (stdin
) and is 133 bytes. The expanded version replace the console input by a function definition (+1 byte) but is much more comfortable to use for the test case in a loop:
t =
.......
... ...
.. ..
. .
. .
. .
. . .
. .
. .
. .
.. ..
... ...
.......
t =
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
t =
t.
tex
t
r
o
h
S
t =
brown
ick fox
qu j
u
e m
h p
T s
o
v
er
th dog
e lazy
Matlab, 133, 130 bytes
s=input('');y=ceil(5.6*sin(0:pi/24:pi-.1).^.9);l=[-y y]+7;n=numel(s);t=repmat(' ',13,n);for k=1:n;t(l(mod(k-1,48)+1),k)=s(k);end;t
function f(s)
y=ceil(5.6*sin(0:pi/24:pi-.1).^.9);l=[-y y]+7; %// calculate the line number for each column position
n=numel(s); %// number of character in input
t=repmat(' ',13,n); %// Create a blank canvas of whitespace characters
for k=1:n
t(l(mod(k-1,48)+1),k)=s(k); %// place each input character where it should be
end
t %// force the output display
The one liner takes input from the console (stdin
) and is 130 bytes. The expanded version replace the console input by a function definition (+1 byte) but is much more comfortable to use for the test case in a loop:
t =
.......
... ...
.. ..
. .
. .
. .
. . .
. .
. .
. .
.. ..
... ...
.......
t =
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
t =
t.
tex
t
r
o
h
S
t =
brown
ick fox
qu j
u
e m
h p
T s
o
v
er
th dog
e lazy
if you want to test the one liner version with input from stdin
, your input has to be entered as one string
, so you'd have to enclose your input between '
characters.
Example:
'Short text.' %// valid input
Short text. %// INVALID input
Thanks Luis Mendo
for shaving up 3 bytes ;-)
Matlab, 133 bytes
The one liner:
s=input('');y=ceil(5.6*sin(0:pi/24:pi-.1).^.9);l=[-y y]+7;n=numel(s);t=char(ones(13,n)*32);for k=1:n;t(l(mod(k-1,48)+1),k)=s(k);end;t
And the expanded version:
function f(s)
y=ceil(5.6*sin(0:pi/24:pi-.1).^.9);l=[-y y]+7; %// calculate the line number for each column position
n=numel(s); %// number of character in input
t=char(ones(13,n)*32); %// Create a blank canvas of whitespace characters
for k=1:n
t(l(mod(k-1,48)+1),k)=s(k); %// place each input character where it should be
end
t %// force the output display
The one liner takes input from the console (stdin
) and is 133 bytes. The expanded version replace the console input by a function definition (+1 byte) but is much more comfortable to use for the test case in a loop:
Description:
The line index of each character is calculated for a half period, then mirrored and concatenated to have a full period.
We create a blank background of whitespace character (same length as the input string.
We place each character according to its position in the relevant line. If the input string is longer than one period, the mod
(modulo) operator wraps that so we don't get out of bound when requesting the line number.
Test case:
Save the function version under textsine.m
in your path, then run:
s = {'.................................................';...
'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.';...
'Short text.';...
'The quick brown fox jumps over the lazy dog'};
for txtcase=1:4
textsine(s{txtcase,1})
end
will output:
t =
.......
... ...
.. ..
. .
. .
. .
. . .
. .
. .
. .
.. ..
... ...
.......
t =
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
t =
t.
tex
t
r
o
h
S
t =
brown
ick fox
qu j
u
e m
h p
T s
o
v
er
th dog
e lazy