| Bytes | Lang | Time | Link |
|---|---|---|---|
| 072 | JavaScript Node.js | 240720T063133Z | Andrew B |
| 003 | Vyxal j | 210530T102914Z | emanresu |
| 009 | Japt R | 180910T114242Z | Shaggy |
| 078 | JavaScript Node.js | 210530T104611Z | user1006 |
| 115 | PHP | 180912T070728Z | Jo. |
| 8372 | R | 180909T143351Z | J.Doe |
| 012 | 05AB1E | 180910T124449Z | Kevin Cr |
| 054 | Powershell | 180910T111652Z | mazzy |
| 002 | Canvas | 180908T160449Z | dzaima |
| 125 | R | 180604T173248Z | JayCe |
| 017 | K ngn/k | 180604T023754Z | ngn |
| 011 | Japt | 180604T001336Z | Bubbler |
| 113 | C gcc | 171226T152508Z | gastropn |
| nan | Vim | 160928T211620Z | Christia |
| 100 | RProgN 100 Bytes Windows NonCompeting | 160927T065830Z | ATaco |
| 079 | Rebol | 140127T211735Z | draegtun |
| 014 | CJam | 150520T143708Z | Martin E |
| 007 | APL | 140127T214035Z | Tobia |
| nan | Edit This solution is now invalid because the semantics of the 銻 instruction has changed. I didn’t realise that I’d already made use of the instruction when I changed it. You can | 140127T214003Z | Timwi |
| 096 | Powershell | 140201T160237Z | jurgenb |
| 048 | Bash/sed script | 140127T052041Z | Digital |
| 007 | J | 140129T104937Z | barbermo |
| 049 | Ruby | 140127T102515Z | manatwor |
| 158 | Extended BrainFuck | 140128T213020Z | Sylweste |
| 020 | K | 140128T164039Z | tmartin |
| 177 | C# | 140128T163430Z | microbia |
| 217 | Java | 140127T144408Z | Danny |
| 020 | MATLAB | 140128T133333Z | Dennis J |
| 074 | Julia | 140127T225046Z | gggg |
| 093 | Python 3 | 140127T043724Z | Justin |
| 089 | R | 140127T132051Z | petermei |
| 011 | APL | 140127T161522Z | Mark Plo |
| 022 | PERL | 140127T100455Z | Tomas |
| 017 | J | 140127T111644Z | Gareth |
| 084 | Python 3 | 140127T105409Z | cjfaure |
| 020 | GolfScript | 140127T060816Z | Howard |
| 023 | Golfscript | 140127T061218Z | John Dvo |
| 049 | Haskell | 140127T054805Z | MtnViewM |
| 029 | GolfScript | 140127T014914Z | Doorknob |
JavaScript (Node.js), 72 bytes
(x,c)=>(x+`
`).replace(/[^\n]*\n/g,k='$&'.repeat(c)).replace(/[^\n]/g,k)
Vyxal j, 3 bytes
•εf
I/O is as lists of lines. The j flag formats the output into ASCII art.
• # Repeat each character of each line by the number
ε # Repeat each line by the number
f # Flatten
Japt -R, 10 9 bytes
·cÈVÇXmpV
·cÈVÇXmpV :Implicit input of string U and integer V
· :Split U on newlines
c :Flat map
È :By passing each X through the following function
VÇ : Map the range [0,V)
Xm : Map each character in X
pV : Repeat V times
:Implicit output joined with newlines
JavaScript (Node.js), 78 bytes
n=>k=>n.split`
`.map(e=>(e.replace(/./g,l=>l.repeat(k))+`
`).repeat(k)).join``
No JavaScript answer yet, so decided to try it out.
PHP, 115 bytes
function f($s,$l){foreach(explode("
",$s)as$a)for($i=$l;$i--;)echo preg_replace('/./',str_repeat('$0',$l),$a)."
";}
R, 83/72 bytes
Alt approach using regexps
If we're allowed a trailing newline, 72 bytes:
function(s,n)cat(gsub("([^
]*
)",r,gsub("([^
])",r<-strrep("\\1",n),s)))
Otherwise, 83 bytes:
function(s,n)write(rep(el(strsplit(gsub("([^\n])",strrep("\\1",n),s),"\n")),e=n),1)
05AB1E, 12 bytes
U|εSX×JXи}˜»
Explanation:
U # Take the integer input, and store it in variable `X`
# i.e. 3
| # Take the rest of the input-lines as list
# i.e. ["ab","cd"]
ε } # Map each line to:
S # Convert the line to a list of characters
# i.e. "ab" → ["a","b"]
X× # And repeat each character `X` amount of times
# i.e. ["a","b"] and 3 → ["aaa","bbb"]
J # Join the line back together
# i.e. ["aaa","bbb"] → "aaabbb"
Xи # And repeat that line `X` amount of times
# i.e. "aaabbb" and 3 → ["aaabbb","aaabbb","aaabbb"]
˜ # Flatten the list of lists
# i.e. [["aaabbb","aaabbb","aaabbb"],["cccddd","cccddd","cccddd"]]
# → ["aaabbb","aaabbb","aaabbb","cccddd","cccddd","cccddd"]
» # And join by newline (which we implicitly output)
# i.e. ["aaabbb","aaabbb","aaabbb","cccddd","cccddd","cccddd"]
# → "aaabbb\naaabbb\naaabbb\ncccddd\ncccddd\ncccddd"
Powershell, 54 bytes
param($s,$n)$s-replace'.',('$0'*$n)-split'
'|%{,$_*$n}
Test script:
$f = {
param($s,$n)$s-replace'.',('$0'*$n)-split'
'|%{,$_*$n}
}
@(
@"
ab
cd
"@
,
@"
OOOOOO OOOOOO OOOOOO OOOOOOO OOOOOO OOOOOO OO OOOOOOO
OO OO OO OO OO OO OO OO OO OO OO
OO OO OO OO OO OOOOO OO OOO OO OO OO OOOOO
OO OO OO OO OO OO OO OO OO OO OO OO
OOOOOO OOOOOO OOOOOO OOOOOOO OOOOOO OOOOOO OOOOOOO OO
"@
) | % {
&$f $_ 3
}
Explanation:
$s-replace'.',('$0'*$n)repeats each symbol exept new line.-split'``n'splits the wide string by new line|%{,$_*$n}repeats each line as an array element and returns array
The result is an array of wide and repeated strings.
R, 125 bytes
function(s,n,x=utf8ToInt(s),m=matrix(x[u<-x!=10],,sum(!u)+1))for(i in 1:ncol(m))cat(rep(intToUtf8(rep(m[,i],e=n)),n),sep="
")
Converts string to UTF8, puts into a matrix whose columns are lines of text (removing newlines), and then repeats each char and the generated lines before printing separeated by newlines.
Japt, 11 bytes
yW=_mpVÃmWR
Unpacked & How it works
UyW=Z{ZmpV} mWR
Input: U = 2D string, V = magnification
Uy map over columns of U...
Z{ZmpV} a function that repeats each char V times
W= assign this function to W
m and map again...
R over rows...
W the function W
JS's Assign-Anywhere™ trick in action.
C (gcc), 113 bytes
i,j;f(s,n)char*s;{char*p;for(;*s;s=*p?++p:p)for(i=n;i--;puts(""))for(p=s;*p&&*p^10;p++)for(j=n;j--;)putchar(*p);}
Vim, 39 keystrokes (excluding input, not competing)
the gotcha and the reason this is not competing is because the input has to be entered twice. Replace both 2 with your own input.
qayl2phxl@aquu:%norm @a<cr>gg0qbyy2P2jkddj@bq@b
Explanation
qayl2phxl@aquurecords a macro that yanks a character, paste it and move to the next one, then replays itself. Then it undoes the changes. Because we want the loop not to be infinite, we don't delete the character, which means we have to delete the extraneous one but still finish with a movement that fails on the last char.:%norm @a<cr>runs the macro on every linegg0returns to the very beginningqbyy2P2jkddj@bq@buses the same technique as@ato copy every line, but with a recursive macro.
I know this can be golfed more, e.g. by traversing backwards for line duplication but because of the multiple input entry requirement, I will stop there and mark this answer as non competing.
Previous answer (32 keystrokes, only doubles)
qaylpl@aqu:%norm @a<cr>:%s/.*/&\r&<cr>
Explanation
qaylpl@aqurecords a macro that yanks a character, paste it and move to the next one, then replays itself. Undo the change.:%norm @a<cr>runs the macro on every line:%s/.*/&\r&<cr>doubles every line
I wanted to do a nested macro, but the inner one (characters) stops the outer one (lines)... So I have to run two commands, adding quite a few keystrokes to an otherwise simple solution.
RProgN 100 Bytes (Windows) Non-Competing
'l' asoc
'i' asoc
i '[^
]' '%0' l rep replace '[^
]*' '%0
' l rep 'z' asoc z 1 z len 1 - sub replace
RProgN doesn't have character escapes as of writing, which makes any handling of new lines require a physical new line. As such, this answer (and any input) has to use CRLFs, instead of just LFs. :(
Also, the 'rep' function was only added after this challenge was issued, as such, this is non-competing.
Rebol - 87 79
r: do input while[d: input][forskip d r[insert/dup d d/1 r - 1]loop r[print d]]
Nicely formatted version:
r: do input
while [d: input] [
forskip d r [insert/dup d d/1 r - 1]
loop r [print d]
]
Usage example:
rebol -qw --do 'Rebol[]r: do input while[d: input][forskip d r[insert/dup d d/1 r - 1]loop r[print d]]' <<< "3
ab
cd"
aaabbb
aaabbb
aaabbb
cccddd
cccddd
cccddd
NB. This code only works in Rebol 2 at this moment (The INPUT function used is not fully implemented in Rebol 3 yet).
CJam, 14 bytes
CJam is newer than this challenge (and the main feature I'm using is actually very recent), so this answer wouldn't be eligible for being accepted - but it's not beating APL anyway, so...
l~qN/1$e*fe*N*
Explanation
With the new e* which repeats each character in a string, this is really straightforward:
l~ e# Read and eval the scale factor.
qN/ e# Read the rest of the input as the ASCII art and split into lines
1$e* e# Copy the scale factor and repeat each line by it.
fe* e# Repeat the characters in each line by the scale factor.
N* e# Join with newlines.
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.
(Edit: This solution is now invalid because the semantics of the 銻 instruction has changed. I didn’t realise that I’d already made use of the instruction when I changed it. You can, however, fix ths program by simply changing it to the newer instruction 壹.)
Sclipting, 19 characters
Expects the input to be separated by \n (no \r) and the first line to contain the multiplying factor.
겠坼銻標⑴가殲各標⓶各①復終겠併①復終
Explanation
겠坼 | split everything at \n
銻 | get first element (the factor)
標 | mark
⑴가殲 | bring list to front; remove first element (the factor)
各 | for each line...
標⓶ | mark
各①復終 | for each character, multiply it
겠併 | add a newline and concatenate everything above the mark
①復 | multiply that
終 | end of loop
At the end, the stack will look like this:
[ factor, mark, line1, line2, line3, ... ]
Everything above the mark is automatically concatenated and output, the rest discarded.
Powershell (96)
function m($n,$s){$s.split("`n")|%{$l="";$_.ToCharArray()|%{$c=$_;1..$n|%{$l+=$c}};1..$n|%{$l}}}
Thought I'd give this a shot in PS.
Using piping into foreach's (%) to keep it short here, but the function and ToCharArray are making it take a hit it brevity.
To use it, you call it from the command line like this:
PS C:\> m 3 "ab
>> cd"
>>
aaabbb
aaabbb
aaabbb
cccddd
cccddd
cccddd
Here's the non-minimised version:
function f($n, $s)
{
$s.split("`n") | % { # split input into separate lines
$l="" # initialize an output line
$_.ToCharArray() | % { # split line into chars
$c=$_ ; 1..$n | % { # add n chars to the line
$l+=$c
}
}
1..$n | % {$l} # output the line n times
}
}
Bash/sed script, 48 chars
printf -vr %$1s
sed -n s/./${r// /&}/g${r// /;p}
Save as a script, chmod +x and run:
$ ./asciiexpand 3 <<< $'ab\ncd'
aaabbb
aaabbb
aaabbb
cccddd
cccddd
cccddd
$
How does it work?
The meat of it is in the sed command. For example, if n=3, then the sed command is expanded to something like:
sed -n 's/./&&&/g;p;p;p'
This compound sed command can be broken up into:
s/./&&&/g- this substitute command matches each character and replaces it with the character repeated 3 times- 3x
pcommands - this just prints the whole pattern space (i.e. the current line) 3 times
We pass -n to sed to tell it not to print anything unless explicitly told to, so we have full control of what is printed and how many times.
I couldn't figure out a quick way to generate arbitrary-length repeating strings directly in sed, so I used some bash tricks instead:
printf -vr "%3s"
This prints a string (not specified, i.e. empty), with 3 leading spaces, and assigns the result to the bash variable r.
We then use bash parameter expansion to transform this string of spaces to what we need substituted into the sed expression:
$ echo ${r// /&}
&&&
$ echo ${r// /;p}
;p;p;p
$
I was able to get away with removing quotes around the printf format specifier and the sed expression, as none of the characters within need escaping in the bash shell.
Character count:
$ submission='r=`printf %$1s`
> sed -n s/./${r// /&}/g${r// /;p}'
$ echo ${#submission}
48
$
J, 7 chars
([#"1#)
Exact same thing as in @Tobia's APL answer, but in ascii chars.
a =. ' 0 ',.'0 0',.' 0 '
a
0
0 0
0
2 ([#"1#) a
00
00
00 00
00 00
00
00
Ruby: 64 49 characters
All data received on STDIN: first line the scaling factor, then the ASCII art.
BEGIN{n=gets.to_i}
$_=[$_.gsub(/./){$&*n}]*n*$/
Sample run:
bash-4.2$ ruby -lpe 'BEGIN{n=gets.to_i};$_=[$_.gsub(/./){$&*n}]*n*$/' <<< '3
> ab
> cd'
aaabbb
aaabbb
aaabbb
cccddd
cccddd
cccddd
Ruby: 44 41 characters
Assuming that every input line is terminated with line separator. Thanks to @Ventero.
$.<2?n=$_.to_i: $><<$_.gsub(/./){$&*n}*n
Sample run:
bash-4.2$ ruby -ne '$.<2?n=$_.to_i: $><<$_.gsub(/./){$&*n}*n' <<< '3
> ab
> cd'
aaabbb
aaabbb
aaabbb
cccddd
cccddd
cccddd
Extended BrainFuck : 158
{a<]<[->+}3>,>3+[->4+[-<<4->>]&a>+<<]<+[-<,[>10+[-<->>+<]<[[->>+<<]3>[->[->+&a&a#3<+>>]>>]<[-]<<]>>[>[-4<[<]>[.>]>>.>]4<[-]<[-]4>[-]]>>[->+<]>[-<+<+>>]4<+<]>]
It turns into:
Brainfuck: 185
>>>,>+++[->++++[-<<---->>]<]<[->+>+<<]<+[-<,[>++++++++++[-<->>+<]<[[->>+<<]>>>[->[->+<]<[->+<]<[->+<<<+>>]>>]<[-]<<]>>[>[-<<<<[<]>[.>]>>.>]<<<<[-]<[-]>>>>[-]]>>[->+<]>[-<+<+>>]<<<<+<]>]
It requires an interpreter that either has 0 or no change as EOF marker. beef, available from Ubuntu repos, works swell:
$ ( echo -n 2
> cat <<eof
> BBBB RRRR AAA IIII NN NN FFFFF * * * KK KK
> BB BB RR RR AA AA II NNN NN FF * KK KK
> BBBB RRRR AAAAA II NNNNNN FFFF ***** KKKKK
> BB BB RR RR AA AA II NN NNN FF * KK KK
> BBBB RR RR AA AA IIII NN NN FF * * * KK KK
> eof
> ) | beef double.bf
BBBBBBBB RRRRRRRR AAAAAA IIIIIIII NNNN NNNN FFFFFFFFFF ** ** ** KKKK KKKK
BBBBBBBB RRRRRRRR AAAAAA IIIIIIII NNNN NNNN FFFFFFFFFF ** ** ** KKKK KKKK
BBBB BBBB RRRR RRRR AAAA AAAA IIII NNNNNN NNNN FFFF ** KKKK KKKK
BBBB BBBB RRRR RRRR AAAA AAAA IIII NNNNNN NNNN FFFF ** KKKK KKKK
BBBBBBBB RRRRRRRR AAAAAAAAAA IIII NNNNNNNNNNNN FFFFFFFF ********** KKKKKKKKKK
BBBBBBBB RRRRRRRR AAAAAAAAAA IIII NNNNNNNNNNNN FFFFFFFF ********** KKKKKKKKKK
BBBB BBBB RRRR RRRR AAAA AAAA IIII NNNN NNNNNN FFFF ** KKKK KKKK
BBBB BBBB RRRR RRRR AAAA AAAA IIII NNNN NNNNNN FFFF ** KKKK KKKK
BBBBBBBB RRRR RRRR AAAA AAAA IIIIIIII NNNN NNNN FFFF ** ** ** KKKK KKKK
BBBBBBBB RRRR RRRR AAAA AAAA IIIIIIII NNNN NNNN FFFF ** ** ** KKKK KKKK
Ungolfed EBF code:
;;;; Multiply
;;;; Takes a digit x and ASCII art on STDIN
;;;; Prints ASCI art scaled x times
;;;; Usage:
;;;; bf ebf.bf < multiply.ebf >multiply.bf
;;;; bf multiply.bf
;;; Memory map for this program
:zero
:str
:flag
:tmp
:dup
:num
;;; Macros
;; EOL support. Comment out the body of the two
;; macros below to only support 0 and no change
;; Some interpreters use -1
{eol_start
+(-
}
{eol_end
)
}
;; macro that reads a digit.
;; the actual number is one more than input
;; ^12 uses 3 cells from origin
{read_number
, ; read char
^1 3+(-^2 4+(-^ 4-)) ; reduce by 3*4*4=48
}
;; duplicate current element
;; to the left using the right as tmp
{copy_left
(-^1+)^1(-^0+<+)
}
;; Duplicate char n times while
;; shifting to the right
{handle_char
$str(-$tmp+) ; copy the char to tmp
$dup(-$num(->+) ; for each dup move num
$dup(-$num+) ; and dup one step to the right
$tmp(-$dup+$str+) ; and copy the char back to str and to dup
@flag) ; which is the new tmp (it gets shifted to the right)
$tmp(-) ; clear char when done
}
{handle_linefeed
$dup(- ; for each dup
$zero[<]> ; go to beginnning of string
[.>]@str ; print string
$tmp. ; print newline
)
$zero[-]<[-]>@zero ; clean last two chars
$tmp(-) ; remove line feed
}
;;; Main program
;; read number
$tmp &read_number
$tmp (-$dup+$num+)
;$tmp,[-] ; uncomment to require a newline before asci art
$flag+(-
$str = ,
( ;; NB! The line containing EOF will not be printed!
&eol_start
$flag 10+(-$str-$tmp+)
if $str is not linefeed (
&handle_char
) $tmp ( linefeed
&handle_linefeed
)
$num ©_left ; we need two copies of the duplicate dupber
$flag+ ; flag to
&eol_end
)
)
K, 20
.....
{,/y#',:',/'y#'/:x}
C# (177)
public string e(string i,int x){return string.Join("",i.Split('\n').Select(a=>string.Join("",Enumerable.Repeat(string.Join("",a.ToCharArray().Select(c=>new string(c,x))),x))));}
Expects input string "i" containing new lines "\n" as the delimiter.
Formatted
public string e(string i, int x)
{
return string.Join("", i.Split('\n').Select(a => string.Join("", Enumerable.Repeat( string.Join("", a.ToCharArray().Select(c => new string(c, x))), x))));
}
Java - 217
First try at golfing. Seems like Java isn't the language to do it in.
enum M{;public static void main(String[]a){int f=new Integer(a[0]),i=0,j,k;a=a[1].split("\n");for(;++i<a.length*f;System.out.println())for(j=0;++j<a[i/f].length();)for(k=0;k++<f;)System.out.print(a[i/f].charAt(j));}}
On Windows you need to replace "\n" with "\r\n".
java M 3 "ab
cd"
aaabbb
aaabbb
aaabbb
cccddd
cccddd
cccddd
MATLAB: 20 characters
['' imresize(ans,n)]
This solution assumes that the image is stored in a file called startup.m and that it is allowed to give the amount of replications to matlab when calling it, this can be done by means of: !matlab -r "n=3"&
MATLAB, call without argument: 23 characters
load;['' imresize(s,n)]
Unlike the first solution, the latter two assume that the amount of replications may not be expected in the call. For these solutions the original string and number are expected in a file called matlab.mat in your current directory.
MATLAB, mathematical alternative: 27 characters
load;['' kron(s,ones(1,n))]
Julia, 74 chars/bytes
julia> f(i,n)=print(prod([(prod(["$c"^n for c in l])*"\n")^3 for l in split(i)]))
f (generic function with 1 method)
julia> f("ab\ncd",3)
aaabbb
aaabbb
aaabbb
cccddd
cccddd
cccddd
7 less if I just return the string. julia> is the interactive prompt.
Python 3 - 109 107 93
i=input;n,s,a=int(i()),i(),[]
while s:a+=[''.join(c*n for c in s)]*n;s=i()
print('\n'.join(a))
First, input the number, then the string. Should be self-explanatory...
Thanks to Waleed Khan for suggesting removing the []
Thanks to Volatility for suggesting having a be a list.
R - 89
M=function(I,N) cat(paste(lapply(lapply(strsplit(I,""),rep,e=N),paste,collapse=""),"\n"))
I <- c("aa aa aa", "bbb bbb bbb", "c c c c c c")
N <- 3
I
# aa aa aa
# bbb bbb bbb
# c c c c c c"
M(I,N)
# aaaaaa aaaaaa aaaaaa
# bbbbbbbbb bbbbbbbbb bbbbbbbbb
# ccc ccc ccc ccc ccc ccc
APL, 11 chars
@Gareth did essentially the same thing first, in J, so this APL entry is just for exhibition, not competition - he's the winner.
E←{⍉⍺/⍉⍺/⍵}
Usage: magnification in left arg (⍺), art in the form of a 2d character matrix in right arg (⍵).
⍺/⍵ will replicate elements across each row of a vector or matrix (2/'O O' becomes 'OO OO').
⍉⍺/⍉ will transpose that, replicate the elements, transpose that.
(If we were going for clarity instead of program length, the code could have been E←{⍺/[1]⍺/⍵} )
I←5 32⍴' OOOOOO OOOOOO OOOOOO OOOOOOOOO OO OO OO OO OO OO OO OO OO OO OOOOO OO OO OO OO OO OO OOOOOO OOOOOO OOOOOO OOOOOOO'
I
OOOOOO OOOOOO OOOOOO OOOOOOO
OO OO OO OO OO OO
OO OO OO OO OO OOOOO
OO OO OO OO OO OO
OOOOOO OOOOOO OOOOOO OOOOOOO
3 E I
OOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOOO
OOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOOO
OOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOOO
OOOOOO OOOOOO OOOOOO OOOOOO OOOOOO OOOOOO
OOOOOO OOOOOO OOOOOO OOOOOO OOOOOO OOOOOO
OOOOOO OOOOOO OOOOOO OOOOOO OOOOOO OOOOOO
OOOOOO OOOOOO OOOOOO OOOOOO OOOOOO OOOOOOOOOOOOOOO
OOOOOO OOOOOO OOOOOO OOOOOO OOOOOO OOOOOOOOOOOOOOO
OOOOOO OOOOOO OOOOOO OOOOOO OOOOOO OOOOOOOOOOOOOOO
OOOOOO OOOOOO OOOOOO OOOOOO OOOOOO OOOOOO
OOOOOO OOOOOO OOOOOO OOOOOO OOOOOO OOOOOO
OOOOOO OOOOOO OOOOOO OOOOOO OOOOOO OOOOOO
OOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOOO
OOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOOO
OOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOOO
PERL, 41 39 25 22 chars
PERL, simple and effective - created right for the task. When invoked with -pi3, where 3 is the parameter n:
s/./$&x$^I/ge;$_ x=$^I
Classical solution (39 chars):
$n=<>;print map{s/./$&x$n/ge;"$_"x$n}<>
Classical solution needs the n is specified in the first line of input, e.g.
3
ab
cd
Thanks @manatwork for the $& trick.
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
Python 3 - 84
Not the shortest but a different answer nonetheless. An interesting one-liner.
n=int(input())
for i in eval(input()):print(((''.join(j*n for j in i)+'\n')*n)[:-1])
Put in a number first, then the ASCII art as a Python list, e.g.:
C:\Users\User4\Desktop>c:/python33/python.exe golf.py
3
["aabb","bbcc","ccdd"]
aaaaaabbbbbb
aaaaaabbbbbb
aaaaaabbbbbb
bbbbbbcccccc
bbbbbbcccccc
bbbbbbcccccc
ccccccdddddd
ccccccdddddd
ccccccdddddd
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)
}+/
Golfscript, 23 characters
~(:i;n/{{{.}i*}:c%c}%n*
I've decided to write an entire program because it has less overhead than even an anonymous function does:
~(:i;- eval the input, then decrement the multiplier, store it asiand discard.n/{...}%n*- split by newlines, map each line, join by newlines{...}:c%c, - take a block, apply it on map-each element, then apply it to the whole line.{.}i*- duplicate this elementitimes
Live demo: http://golfscript.apphb.com/?c=OyciYWJjCmRlZiIzJwp%2BKDppO24ve3t7Ln1pKn06YyVjfSVuKg%3D%3D
Example usage:
;'"abc
def"3'
~(:i;n/{{{.}i*}:c%c}%n*
Haskell, 49 bytes
x=(=<<).replicate
e n=unlines.x n.map(x n).lines
The enlarge function is e, which takes a count and a string, and returns a string:
λ: putStrLn $ e 3 "ab\ncd\n"
aaabbb
aaabbb
aaabbb
cccddd
cccddd
cccddd
GolfScript, 29 characters
{:i;n/{1/:c;{c{i*}/n}i*}/}:f;
This defines a block f, that when called will produce the desired output. It assumes arguments are on the stack (because that's basically how arguments are passed in GolfScript).
Ungolfed (does that even make sense? :P):
{:i;n/{ # for each line...
1/:c; # save characters of string in c
{ # i times...
c{ # for each character...
i*
}/
n
}i*
}/}:f;
# Test run
"ab
cd" 3 f