Enlarge ASCII art
APL, 7 chars/bytes*
{⍺/⍺⌿⍵}
Function that takes the number and input string as parameters and returns the result:
a
abcde
fghij
2 {⍺/⍺⌿⍵} a
aabbccddee
aabbccddee
ffgghhiijj
ffgghhiijj
3 {⍺/⍺⌿⍵} a
aaabbbcccdddeee
aaabbbcccdddeee
aaabbbcccdddeee
fffggghhhiiijjj
fffggghhhiiijjj
fffggghhhiiijjj
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
*: APL can be written in its own (legacy) single-byte charset that maps APL symbols to the upper 128 byte values. Therefore, for the purpose of scoring, a program of N chars that only uses ASCII characters and APL symbols can be considered to be N bytes long.
GolfScript, 20 characters
n%(~{.{*}+@1/%n+*}+/
Takes all input from STDIN, first line is the scaling factor, the rest the multiline-input. You can try the example online.
Input
3
ab
cd
Output
aaabbb
aaabbb
aaabbb
cccddd
cccddd
cccddd
Code
n% # Split the input into separate lines
(~ # Take the first line and evaluate (factor)
{ # {...}+/ adds the factor to the code block and loops over
# the remaining lines (i.e. the factor will be the top of stack
# for each line of input
.{ # Same thing, duplicate factor and add it to code block and
# loop over each character (1/ splits the string into chars)
* # multiply single-char string with factor
}+@1/%
n+ # Join string by adding a newline
* # Multiply the line by the factor (left from the . operation)
}+/
J, 20 17 characters
f=.([#&.|:#)];._2
Defines a verb f
that does what is required. Usage:
3 f a
aaaccc
aaaccc
aaaccc
bbbddd
bbbddd
bbbddd
where a
is the input string.
On Windows an extra character is required to remove the \r
:
f=.([#&.|:#)}:;._2
Explanation:
];._2
chops the input string into chunks based on the last character of the string, which in this case will be a \n
. Windows has \r\n
so we need to use }:
to chop an extra character off: }:;._2
. Cut verb documentation
The rest of the code (with the exception of the assignment f=.
) is a fork.
It breaks down like this: [ #&.|: #
If a
is our input string the calculation will be 3 # a
(we'll call this result x
), then 3 [ a
(we'll call this result y
) then y #&.|: x
.
3 # a
just makes three copies of every member of a
. Copy verb documentation
This turns
ab
cd
into
aaabbb
cccddd
3 [ a
just returns 3. Left verb documentation
Finally y #&.|: x
is y
copy under transpose x
. The #
works as before, but the &.|:
tells J to transpose the input first and then transpose it back when it's finished. Under conjunction documentation, transpose verb documentation.
The transpose turns
aaabbb
cccddd
into
ac
ac
ac
bd
bd
bd
then the copy changes it to
aaaccc
aaaccc
aaaccc
bbbddd
bbbddd
bbbddd
and transposing it back gives you
aaabbb
aaabbb
aaabbb
cccddd
cccddd
cccddd