Take the 2-minute tour ×
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.

In this challenge, you must take multiline ASCII art as input, such as:

 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      

And you will also take an integer as input. You must output the ASCII art enlarged by the amount specified with the integer. For example, if you used a second argument of 3, the output would be

   OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOOOOO                  OOOOOOOOOOOOOOOOOO         OOOOOOOOOOOOOOOOOO      OOOOOO                  OOOOOOOOOOOOOOOOOOOOO
   OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOOOOO                  OOOOOOOOOOOOOOOOOO         OOOOOOOOOOOOOOOOOO      OOOOOO                  OOOOOOOOOOOOOOOOOOOOO
   OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOOOOO                  OOOOOOOOOOOOOOOOOO         OOOOOOOOOOOOOOOOOO      OOOOOO                  OOOOOOOOOOOOOOOOOOOOO
OOOOOO                  OOOOOO            OOOOOO   OOOOOO         OOOOOO   OOOOOO                              OOOOOO                     OOOOOO            OOOOOO   OOOOOO                  OOOOOO
OOOOOO                  OOOOOO            OOOOOO   OOOOOO         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         OOOOOOOOO   OOOOOO            OOOOOO   OOOOOO                  OOOOOOOOOOOOOOO
OOOOOO                  OOOOOO            OOOOOO   OOOOOO         OOOOOO   OOOOOOOOOOOOOOO                     OOOOOO         OOOOOOOOO   OOOOOO            OOOOOO   OOOOOO                  OOOOOOOOOOOOOOO
OOOOOO                  OOOOOO            OOOOOO   OOOOOO         OOOOOO   OOOOOOOOOOOOOOO                     OOOOOO         OOOOOOOOO   OOOOOO            OOOOOO   OOOOOO                  OOOOOOOOOOOOOOO
OOOOOO                  OOOOOO            OOOOOO   OOOOOO         OOOOOO   OOOOOO                              OOOOOO            OOOOOO   OOOOOO            OOOOOO   OOOOOO                  OOOOOO
OOOOOO                  OOOOOO            OOOOOO   OOOOOO         OOOOOO   OOOOOO                              OOOOOO            OOOOOO   OOOOOO            OOOOOO   OOOOOO                  OOOOOO
OOOOOO                  OOOOOO            OOOOOO   OOOOOO         OOOOOO   OOOOOO                              OOOOOO            OOOOOO   OOOOOO            OOOOOO   OOOOOO                  OOOOOO
   OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOOOOO                  OOOOOOOOOOOOOOOOOO         OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOOOOO   OOOOOO
   OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOOOOO                  OOOOOOOOOOOOOOOOOO         OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOOOOO   OOOOOO
   OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOOOOO                  OOOOOOOOOOOOOOOOOO         OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOOOOO   OOOOOO

Full specifications:

  • I/O may be in any reasonable manner (i.e. STDIN/OUT, function arguments/return value, dialog boxes, etc.) but may NOT be hardcoded (i.e. s="[INSERT INPUT HERE]").
  • Each character must turn into an n by n box of that character, where n is the integer argument (ex. input of

    ab
    cd
    

    and 3 will result in

    aaabbb
    aaabbb
    aaabbb
    cccddd
    cccddd
    cccddd
    

    )

  • This is so the shortest code in bytes wins. If you use network access for any reason, all bytes downloaded also count against your score.
share|improve this question
    
ascii art looks interesting on the questions list –  Quincunx Jan 27 at 16:49
6  
I think you should make a secondary/bonus round for a method that introduces proper aliasing into the enlarged art. Your giant code golf art is looking pretty blocky. –  AmeliaBR Jan 28 at 1:58
5  
@AmeliaBR See here‌​. –  Howard Jan 28 at 14:22

23 Answers 23

up vote 26 down vote accepted

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.

share|improve this answer
1  
... :O How does it work? –  Doorknob Jan 27 at 21:44
3  
@DoorknobofSnow The standard representation for a multiline string is APL is a rectangular character matrix (with trailing blanks if the lines have uneven width… yes, APL is that old.) The / function (not to be confused with the / operator… yes, same symbol) duplicates and/or removes columns from a matrix according to the left-side argument. If that is a scalar (simple number) then it's replicated for all input columns. Therefore 2/m is a matrix with all columns doubled. The variant does the same, but for rows (or first-axis planes in the general case.) –  Tobia Jan 27 at 21:50
2  
Beautiful language, isn't it? It's actually pretty readable, once you learn a few dozen symbols. Much more so than the ASCII line-noise languages you see around here… –  Tobia Jan 27 at 21:58
    
Cool. Was ⌿ always in the language? It wasn't in the Gilman and Rose book, and an Iverson book on APL\360 mentions /[1] but not ⌿ . –  Mark Plotnick Jan 28 at 9:35
    
@MarkPlotnick No, it wasn't always there. I just checked the IBM APL2 reference and it doesn't mention it. But the latest ISO standard does (search for "ISO 13751", there's a pdf floating around) and all interpreters I have at my disposal recognize it: Dyalog, MicroAPL, and the recent GNU APL and github.com/ngn/apl –  Tobia Jan 28 at 13:51

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)
}+/
share|improve this answer
    
Hey! You've got a better input format, score and time than me :-/ +1 –  Jan Dvorak Jan 27 at 6:14
    
Also, I'm kinda lost reading it. –  Jan Dvorak Jan 27 at 6:17
2  
@JanDvorak Added some explanation. –  Howard Jan 27 at 6:22
    
Wow. Today I've learned 1/. I also need to use value function + more. –  Jan Dvorak Jan 27 at 6:41
2  
@CoryKlein: It would kind of help if you told us what error, but... *gazes into crystal ball* ...it may be that golfscript.rb is not marked executable, or that the first line has the wrong path to the Ruby interpreter for your system. Oh, and that echo should presumably be cat. Try cat inputFile | ruby golfscript.rb scriptFile (or just ruby golfscript.rb scriptFile < inputFile) and see if that works. –  Ilmari Karonen Jan 28 at 14:00

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
share|improve this answer
4  
Windows sucks, eh? :P –  cjfaure Jan 27 at 11:20
    
@Trimsty Indeed it does. –  Gareth Jan 27 at 11:30

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
share|improve this answer
    
+1 for blatent thievery. ;-) –  Gareth Jan 27 at 16:19
2  
J is hobbled by that pesky design goal in which operators are restricted to the ASCII character set. :) –  Mark Plotnick Jan 27 at 16:59
2  
Though, if we measure in bytes like the OP said, this is 44 bytes (implying unicode of course, not utf-8) and @Gareth's is still 17. That's the downside to languages that aren't restricted to ASCII. –  cjfaure Jan 27 at 19:43
5  
@Trimsty But APL has it's own character set which maps each character to a single byte, so arguably this is still 11 bytes. –  Volatility Jan 27 at 23:03
1  
@Volatility Hm. That's really weird, sorry, didn't know :P –  cjfaure Jan 28 at 8:51

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
share|improve this answer

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 p commands - 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
$ 
share|improve this answer
    
I don't have an idea how this works but it works! –  Tomas Jan 27 at 9:57
1  
Variable n violates rule 1: “may NOT be hardcoded”. –  manatwork Jan 27 at 10:32
1  
Just use $1 and remove n=3;, you will even save 4 characters and maybe the {} in the printf too. –  Tomas Jan 27 at 11:14
    
And as we can assume $1 will be numeric, the quotes around printf's argument are not necessary, reducing it to 52 characters: r=`printf %$1s`;sed -n "s/./${r// /&}/g${r// /;//p}". –  manatwork Jan 27 at 13:42
1  
@Tomas - You've probably figured out how it works by now, but I added a description in case you're interested. –  DigitalTrauma Jan 28 at 0:44

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.

share|improve this answer
1  
Cool. But you not need to capture the matched characters: s/./$&x$n/ge. –  manatwork Jan 27 at 10:27
    
Thanks @manatwork, I improved it even more! –  Tomas Jan 27 at 11:09
    
Wow. Perl pwns. –  cjfaure Jan 27 at 16:51

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
share|improve this answer
1  
A shorter way to set n: $.<2?n=$_.to_i: $><<$_.gsub(/./){$&*n}*n (sadly, the space after the colon is necessary, otherwise the parser gets confused). Run with ruby -n. –  Ventero Jan 28 at 18:09
    
Doh. I tried dozens of approaches to shorten the assignment to n, but I missed the ternary operator. Thank you, @Ventero. –  manatwork Jan 29 at 8:45

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
share|improve this answer

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 as i and 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 element i times

Live demo: http://golfscript.apphb.com/?c=OyciYWJjCmRlZiIzJwp%2BKDppO24ve3t7Ln1pKn06YyVjfSVuKg%3D%3D

Example usage:

;'"abc
def"3'
~(:i;n/{{{.}i*}:c%c}%n*
share|improve this answer

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
share|improve this answer

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.

share|improve this answer
7  
Just noticed; the nsa is watching your every input –  Quincunx Jan 27 at 4:59
    
Shortest code in bytes. Wouldn't that then include newlines? Shouldn't your count be 112? –  cjfaure Jan 27 at 10:55
    
Sorry, I meant 111. –  cjfaure Jan 27 at 11:48
    
@Trimsty you are right; I thought wordcounter.net counted newlines. –  Quincunx Jan 27 at 16:36
2  
Make a into a list, do a+=[''.join(c*n for c in s)]*n, then do print('\n'.join(a)) at the end. That should work. –  Volatility Jan 27 at 20:45

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
share|improve this answer
2  
The input characters need to expand downwards as well as across (so there should be 3 lines of aaabbb and 3 lines of cccddd in your output example above). –  Gareth Jan 27 at 15:01
2  
You can spare: 1 character by initializing i in the declaration instead of the for; 8 characters by using a instead of x (a=a[1].split("\n"), and change all x with a). –  manatwork Jan 27 at 15:24
3  
Yeah, with any language where just the declaration of main takes more bytes than entire programs in other languages, contestants are going to be getting bogeys. –  Mark Plotnick Jan 28 at 0:39
2  
Hm ok. Here is 3 chars saved by rearranging the outter for loop a little bit: enum M{;public static void main(String[]a){int f=Integer.valueOf(a[0]),i=-1,j,k;a=a[1].split("\n");for(;++i<a.length*f;System.o‌​ut.println())for(j=0;j<a[i/f].length();j++)for(k=0;k++<f;)System.out.print(a[i/f]‌​.charAt(j));}} –  daniero Jan 28 at 13:25
2  
Another 4 bytes: Integer.valueOf(a[0]) -> new Integer(a[0]) –  Yurii Shylov Jan 28 at 15:17

(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.

share|improve this answer
    
这太有意思了!你是原创者对吧? –  theGreenCabbage Jan 28 at 21:50
    
@theGreenCabbage 对了. 踢木外 是 这个 电脑语言 的 创始人 –  Quincunx Jan 29 at 7:09
    
@Timwi sorry for calling you 踢木外 (kick wood outside, pronounced tea-moo-why)... –  Quincunx Jan 29 at 7:13
    
@Quincunx: Hehe, I found it funny :) But the final i is pronounced [iː], not [ɑi]; how would you write it in Chinese now? –  Timwi Jan 30 at 14:09
    
@Timwi Thought that's how it is pronounced (but I couldn't think of a corresponding character). I wrote by searching and copy-pasting (on mdbg.net/chindict/chindict.php) –  Quincunx Jan 30 at 18:29

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  
share|improve this answer

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.

share|improve this answer
1  
This is the first Julia golf I've seen. –  cjfaure Jan 28 at 8:51
    
@Trimsty codegolf.stackexchange.com/search?q=julia still very rare, but they have been a few (including by one of the designers of the language actually). –  plannapus Jan 28 at 15:14
    
@plannapus Interesting! There's a new, rare esolang called ~-~! that I've used as well, though it's terrible for golfing. –  cjfaure Jan 29 at 17:07

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
    }
}
share|improve this answer

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
share|improve this answer
    
Looks interesting. But I get an error: “Error: could not find function "str_split"”. Do I need to explicitly install the stringr package to be able to run your code? (Sorry, not familiar with R.) –  manatwork Jan 27 at 14:38
    
isn't it missing a call to cat to print it as stdout? Additionally each element of the string should not just be repeated n times in length but be repeated also in breadth. –  plannapus Jan 27 at 15:08
    
You can also golf your function a bit more: <- can be =, paste0 can here be replaced by paste since you're using the collapse argument anyway and the argument each can be shorten to e. See here for some basic ideas on golfing with R. –  plannapus Jan 27 at 15:10
    
Otherwise, it's a nice attempt (my own shortest attempt is still in the 200 characters or so :) ) –  plannapus Jan 27 at 15:15
    
@manatwork ok, no error anymore wihtout loading stringr –  marvin_dpr Jan 27 at 20:57

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))]
share|improve this answer

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))));
 }
share|improve this answer

K, 20

.....

{,/y#',:',/'y#'/:x} 
share|improve this answer

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 &copy_left      ; we need two copies of the duplicate dupber
    $flag+               ; flag to 
    &eol_end
  )  
)
share|improve this answer

Rebol - 87

r: to-integer input while[d: input][forskip d r[insert/dup d d/1 r - 1]loop r[print d]]

Nicely formatted version:

r: to-integer 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: to-integer 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).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.