Enlarge ASCII art

65

6

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

Specifically, each character must turn into an n by n box of that character, where n is the integer argument. For example, an input of

ab
cd

and 3 will result in

aaabbb
aaabbb
aaabbb
cccddd
cccddd
cccddd

This is , so the shortest code in bytes wins.

Doorknob

Posted 2014-01-27T01:49:14.427

Reputation: 68 138

ascii art looks interesting on the questions list – Justin – 2014-01-27T16:49:33.547

6I 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 – 2014-01-28T01:58:01.867

5

@AmeliaBR See here.

– Howard – 2014-01-28T14:22:26.657

Answers

37

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.

Tobia

Posted 2014-01-27T01:49:14.427

Reputation: 5 455

@MarkPlotnick I recently went back to the Gilman and Rose book and my copy (third edition) does mention at least on Chapter 14, under Replication and compression on two-dimensional arrays. – Tobia – 2015-01-17T17:00:18.143

@Tobia Thanks. I went back to my first edition and read more closely, and it is mentioned there. – Mark Plotnick – 2015-01-20T16:58:02.470

2Wow. That. Is. Just. Awesome. I. Am. Severely. Awestruck. By. This. Code. I would like to offer more than a mere +1, but my rep is quite low for a bounty yet. – Erik the Outgolfer – 2016-09-29T12:07:19.167

@EriktheGolfer I recommend learning APL, even if you'll never use it for anything serious. Dyalog APL is the best interpreter, if you look carefully you should find a free (as in beer) version. Their manuals and snippet repositories are free and are the best too. If you want a gentler approach, the Gilman and Rose book we were discussing is still the best book. You can find it used for a few bucks. – Tobia – 2016-09-29T14:55:59.730

@Tobia Generally, I'm into [tag:kolmogorov-complexity] constant output challenges, so /// or Jelly would suffice there. Besides, I'm learning Jelly now, and APL has some strange symbols that I can't type, but I might learn it. It's not a golfing language though. – Erik the Outgolfer – 2016-09-29T18:03:01.183

1... :O How does it work? – Doorknob – 2014-01-27T21:44:44.857

4@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 – 2014-01-27T21:50:42.333

6Beautiful 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 – 2014-01-27T21:58:15.130

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 – 2014-01-28T09:35:52.930

@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 https://github.com/ngn/apl

– Tobia – 2014-01-28T13:51:07.433

35

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)
}+/

Howard

Posted 2014-01-27T01:49:14.427

Reputation: 23 109

Hey! You've got a better input format, score and time than me :-/ +1 – John Dvorak – 2014-01-27T06:14:11.233

Also, I'm kinda lost reading it. – John Dvorak – 2014-01-27T06:17:50.850

2@JanDvorak Added some explanation. – Howard – 2014-01-27T06:22:15.720

Wow. Today I've learned 1/. I also need to use value function + more. – John Dvorak – 2014-01-27T06:41:24.550

Trying to figure out how to use GolfScript. echo inputFile | ./golfscript.rb scriptFile gives me an error... – Cory Klein – 2014-01-27T20:38:43.067

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 – 2014-01-28T14:00:52.107

@IlmariKaronen You're right, the echo was the problem. facepalm, what a newb mistake. – Cory Klein – 2014-01-28T15:41:34.130

19

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

Gareth

Posted 2014-01-27T01:49:14.427

Reputation: 11 678

This is shorter: [##"1 Also, I'm not sure about the unwritten rules of golfing in J, but I'd say the string splitting and the assignment could be omitted, given the question's loose requirements. I certainly did so in my APL answer. Example: 2 ([##"1) 'abcde',:'fghij' – Tobia – 2015-01-21T22:41:24.517

4Windows sucks, eh? :P – cjfaure – 2014-01-27T11:20:48.637

@Trimsty Indeed it does. – Gareth – 2014-01-27T11:30:02.067

17

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

MtnViewMark

Posted 2014-01-27T01:49:14.427

Reputation: 4 779

15

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

Mark Plotnick

Posted 2014-01-27T01:49:14.427

Reputation: 1 231

I should point out though, that I use 5 chars turning the string input into a character array, so you only beat me by 1 character really. :-) – Gareth – 2014-01-27T16:28:24.447

2J is hobbled by that pesky design goal in which operators are restricted to the ASCII character set. :) – Mark Plotnick – 2014-01-27T16:59:36.767

2Though, 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 – 2014-01-27T19:43:38.563

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 – 2014-01-27T23:03:35.310

1@Volatility Hm. That's really weird, sorry, didn't know :P – cjfaure – 2014-01-28T08:51:59.107

13

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
$ 

Digital Trauma

Posted 2014-01-27T01:49:14.427

Reputation: 64 644

I don't have an idea how this works but it works! – Tomas – 2014-01-27T09:57:13.593

1Variable n violates rule 1: “may NOT be hardcoded”. – manatwork – 2014-01-27T10:32:17.590

1Just use $1 and remove n=3;, you will even save 4 characters and maybe the {} in the printf too. – Tomas – 2014-01-27T11:14:07.733

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 – 2014-01-27T13:42:04.947

@manatwork - my assumption was that it was the input text that shouldn't be hardcoded. But I think you're right, and using $1 allows extra golfing. Thanks for the tips! – Digital Trauma – 2014-01-27T15:40:23.757

1@Tomas - You've probably figured out how it works by now, but I added a description in case you're interested. – Digital Trauma – 2014-01-28T00:44:24.387

Awesome demonstration of power of shell!! ( Ungolfed version may prefer syntaxe printf -v r %$1s to prevent useless forks, but this implie 1 more char... :-) – F. Hauri – 2014-01-29T06:59:32.583

@F.Hauri - interesting! In fact we could do printf -vr %$1s for the same number of chars. But would a fork occur in the former case, given printf is a bash-builtin? – Digital Trauma – 2014-01-29T19:00:20.487

@DigitalTrauma Yes, it's the only way to modify environment (a fork can't modify parent environment). And yes, -vr work without adding one char. It's definitively a better solution;-) – F. Hauri – 2014-01-29T19:31:16.183

9

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.

Tomas

Posted 2014-01-27T01:49:14.427

Reputation: 2 333

1Cool. But you not need to capture the matched characters: s/./$&x$n/ge. – manatwork – 2014-01-27T10:27:14.653

8

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

manatwork

Posted 2014-01-27T01:49:14.427

Reputation: 17 865

1A 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 – 2014-01-28T18:09:49.420

Doh. I tried dozens of approaches to shorten the assignment to n, but I missed the ternary operator. Thank you, @Ventero. – manatwork – 2014-01-29T08:45:17.023

6

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

cjfaure

Posted 2014-01-27T01:49:14.427

Reputation: 4 213

5

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

Doorknob

Posted 2014-01-27T01:49:14.427

Reputation: 68 138

5

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.

Justin

Posted 2014-01-27T01:49:14.427

Reputation: 19 757

7Just noticed; the nsa is watching your every input – Justin – 2014-01-27T04:59:50.140

Shortest code in bytes. Wouldn't that then include newlines? Shouldn't your count be 112? – cjfaure – 2014-01-27T10:55:20.507

Sorry, I meant 111. – cjfaure – 2014-01-27T11:48:34.843

@Trimsty you are right; I thought wordcounter.net counted newlines. – Justin – 2014-01-27T16:36:49.687

You can remove the []s of your list comprehensions to get generator expressions, which will work just as well. – Waleed Khan – 2014-01-27T18:47:46.027

2Make 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 – 2014-01-27T20:45:06.247

I don't think you need a at all: i=input;n,s=int(i()),i() ... while s:print('\n'.join([''.join(c*n for c in s)]*n);s=i() – Steven Rumbalski – 2014-01-28T21:25:50.160

@StevenRumbalski small problem with your method (other than a missing )); it prints for each line, not at the very end. – Justin – 2014-01-29T06:54:18.713

5

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*

John Dvorak

Posted 2014-01-27T01:49:14.427

Reputation: 9 048

5

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

Danny

Posted 2014-01-27T01:49:14.427

Reputation: 1 563

1Are you sure the input is correct? – manatwork – 2014-01-27T14:54:13.677

Ah, your right it should be abcd typo :/ – Danny – 2014-01-27T14:58:19.370

2The 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 – 2014-01-27T15:01:24.457

@Gareth darn, missed that too. Should be fixed now. – Danny – 2014-01-27T15:12:26.173

2You 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 – 2014-01-27T15:24:55.030

3Yeah, 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 – 2014-01-28T00:39:20.720

1Spare another byte by replacing for(k=0;k<f;k++) with for(k=0;k++<f;) – Yurii Shylov – 2014-01-28T08:35:01.603

Doesn't seem optimal to write out System.out.print twice; I'd suggest something like making an empty string, append to it instead of the first ...print and then println it at the end. – daniero – 2014-01-28T11:07:43.530

Reusing a[0] and appending to it to print, ended up with the same amount of chars for me. – Danny – 2014-01-28T13:15:13.133

2Hm 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.out.println())for(j=0;j<a[i/f].length();j++)for(k=0;k++<f;)System.out.print(a[i/f].charAt(j));}} – daniero – 2014-01-28T13:25:32.273

3Another 4 bytes: Integer.valueOf(a[0]) -> new Integer(a[0]) – Yurii Shylov – 2014-01-28T15:17:24.413

Thanks all. Seems I still need to learn a few trick on minifying my code. – Danny – 2014-01-28T15:27:33.550

5

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

Timwi

Posted 2014-01-27T01:49:14.427

Reputation: 12 158

这太有意思了!你是原创者对吧? – theGreenCabbage – 2014-01-28T21:50:05.843

@theGreenCabbage 对了. 踢木外 是 这个 电脑语言 的 创始人 – Justin – 2014-01-29T07:09:36.947

1@Timwi sorry for calling you 踢木外 (kick wood outside, pronounced tea-moo-why)... – Justin – 2014-01-29T07:13:12.950

@Quincunx: Hehe, I found it funny :) But the final i is pronounced [iː], not [ɑi]; how would you write it in Chinese now? – Timwi – 2014-01-30T14:09:19.767

@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 http://www.mdbg.net/chindict/chindict.php)

– Justin – 2014-01-30T18:29:25.680

Due to the trainwreck that is Mandarin, nothing is pronounced /wi:/ despite Mandarin having /i:/. The closest are /wei/ /wai/ /i:/ – ithisa – 2014-02-01T16:41:05.793

3

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  

barbermot

Posted 2014-01-27T01:49:14.427

Reputation: 111

3

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
    }
}

jurgenb

Posted 2014-01-27T01:49:14.427

Reputation: 131

2Mazzy suggested function m($n,$s){-split$s|%{,(-join($_-split''|%{$_*$n}))*$n}} for 63 bytes – ovs – 2018-06-04T09:36:09.200

2

dzaima

Posted 2014-01-27T01:49:14.427

Reputation: 19 048

2

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)))

Try it online!

Otherwise, 83 bytes:

function(s,n)write(rep(el(strsplit(gsub("([^\n])",strrep("\\1",n),s),"\n")),e=n),1)

Try it online!

J.Doe

Posted 2014-01-27T01:49:14.427

Reputation: 2 379

2

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.

mazzy

Posted 2014-01-27T01:49:14.427

Reputation: 4 832

2

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.

gggg

Posted 2014-01-27T01:49:14.427

Reputation: 1 715

1This is the first Julia golf I've seen. – cjfaure – 2014-01-28T08:51:04.290

@Trimsty http://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 – 2014-01-28T15:14:23.833

@plannapus Interesting! There's a new, rare esolang called ~-~! that I've used as well, though it's terrible for golfing. – cjfaure – 2014-01-29T17:07:52.953

1

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="
")

Try it online!

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.

JayCe

Posted 2014-01-27T01:49:14.427

Reputation: 2 655

congrats on 1K by the way! :-) – Giuseppe – 2018-06-05T17:52:52.340

ty :-) ! It's great to see R answers to most questions and even multiple answers to some questions. – JayCe – 2018-06-05T17:56:33.323

1

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

draegtun

Posted 2014-01-27T01:49:14.427

Reputation: 1 592

1

K, 20

.....

{,/y#',:',/'y#'/:x} 

tmartin

Posted 2014-01-27T01:49:14.427

Reputation: 3 917

1

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
  )  
)

Sylwester

Posted 2014-01-27T01:49:14.427

Reputation: 3 678

0

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);}

Try it online!

gastropner

Posted 2014-01-27T01:49:14.427

Reputation: 3 264

Suggest for(char*p;*s;s=p+!!*p instead of char*p;for(;*s;s=*p?++p:p – ceilingcat – 2018-09-10T17:01:44.397

0

Japt, 11 bytes

yW=_mpVÃmWR

Try it online!

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.

Bubbler

Posted 2014-01-27T01:49:14.427

Reputation: 16 616

0

K (ngn/k), 17 bytes

{,/+x#,+,/+x#,+y}

Try it online!

ngn

Posted 2014-01-27T01:49:14.427

Reputation: 11 449

0

Japt -R, 10 bytes

·ËVÆDmpV÷

Try it online

Shaggy

Posted 2014-01-27T01:49:14.427

Reputation: 24 623

0

05AB1E, 12 bytes

U|εSX×JXи}˜»

Try it online.

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"

Kevin Cruijssen

Posted 2014-01-27T01:49:14.427

Reputation: 67 575

0

PHP, 115 bytes

function f($s,$l){foreach(explode("
",$s)as$a)for($i=$l;$i--;)echo preg_replace('/./',str_repeat('$0',$l),$a)."
";}

Try it online!

Jo.

Posted 2014-01-27T01:49:14.427

Reputation: 974

0

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

petermeissner

Posted 2014-01-27T01:49:14.427

Reputation: 101

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 – 2014-01-27T14:38:36.460

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 – 2014-01-27T15:08:21.120

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 – 2014-01-27T15:10:26.380

Otherwise, it's a nice attempt (my own shortest attempt is still in the 200 characters or so :) ) – plannapus – 2014-01-27T15:15:59.097

@manatwork ok, no error anymore wihtout loading stringr – petermeissner – 2014-01-27T20:57:04.343

@plannapus thanks for the comments, I added a cat ... as every character in every string (provided as character vector) is repeated it really should scale the any asci-art :-) – petermeissner – 2014-01-27T20:58:52.757

0

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))]

Dennis Jaheruddin

Posted 2014-01-27T01:49:14.427

Reputation: 1 848

0

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))));
 }

microbian

Posted 2014-01-27T01:49:14.427

Reputation: 2 297

0

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*

Test it here.

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.

Martin Ender

Posted 2014-01-27T01:49:14.427

Reputation: 184 808

I realize this is an old answer, but you can save a byte by using a function instead: {N/1$fe*e*N*} – Esolanging Fruit – 2018-09-09T05:49:57.093

0

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.

ATaco

Posted 2014-01-27T01:49:14.427

Reputation: 7 898

0

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@aquu records 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 line
  • gg0 returns to the very beginning
  • qbyy2P2jkddj@bq@b uses the same technique as @a to 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@aqu records 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.

Christian Rondeau

Posted 2014-01-27T01:49:14.427

Reputation: 301