Run Length Decoding

20

1

Write the shortest code in the language of your choice to perform run length decoding of the given string.

The string will be supplied as input on stdin in the form

CNCNCNCNCNCNCNCN

where each C could be any printable ASCII character and each N is a digit 1 to 9 (inclusive).

Sample input:

:144,1'1

Corresponding output:

:4444,'

Coding man

Posted 2013-10-19T08:13:47.923

Reputation: 1 193

Answers

28

Brainfuck, 34 characters

,[>,>++++++[<-------->-]<[<.>-]<,]

alephalpha

Posted 2013-10-19T08:13:47.923

Reputation: 23 988

5Wow. A brainfuck solution that can compete with other solutions? – Johannes Kuhn – 2013-10-19T14:49:21.420

13

Shakespeare Programming Language, 406 bytes

.
Ajax,.
Ford,.
Act I:.
Scene I:.
[Enter Ajax and Ford]
Scene II:.
Ford:
Open your mind.Is sky nicer than you?If so, let us return to scene IV.
Ajax:
Open your mind.You is sum you and sum big big big big big big pig and big big big big cat!
Scene III:.
Ford:
Speak thy mind.
Ajax:
You is sum you and pig!Is you as big as zero?If so, let us return to scene II.Let us return to scene III.
Scene IV:.
[Exeunt]

Ungolfed version:

The Decoding of the Lengths of Veronan Runs - A Drama of PPCG.

Romeo, quite a character.
Juliet, Romeo's lover and multiplicand.

Act I: In which the lengths of runs are decoded.

Scene I: A silent entrance.

[Enter Romeo and Juliet]

Scene II: In which neither Romeo nor Juliet believes the other open-minded.

Juliet:
  Open your mind. Is my mother jollier than thou? If so,
  we must proceed to scene IV.

Romeo:
  Open your mind. Thou art the sum of thyself and the sum of my good aunt and
  the difference between nothing and the quotient of the square of twice the sum
  of thy foul fat-kidneyed goat and thy death and thy evil variable!

Scene III: In which Romeo snaps and brutally insults Juliet.

Juliet:
  Speak thy mind.

Romeo:
  Thou art the sum of thyself and a hog! Art thou as rotten as nothing? If so,
  let us return to scene II. Let us return to scene III.

Scene IV: Finale.

[Exeunt]

I'm using drsam94's Python SPL compiler, which has a few bugs (which is why, for instance, I use Open your mind instead of Open thy mind in the golfed version).

To run this program, use:

$ python splc.py rld.spl > rld.c
$ gcc rld.c -o rld.exe
$ echo -n ":144,1'1" | ./rld
:4444,'

How it works

SPL is an esoteric programming language designed to make programs look like Shakespeare plays. It does this by using characters as variables, and processing is performed by having the characters say things to one another.

The Decoding of the Lengths of Veronan Runs - A Drama of PPCG.

This is the title of the play; it's ignored by the compiler.

Romeo, quite a character.
Juliet, Romeo's lover and multiplicand.

Here we're declaring the variables used in the rest of the program. Everything betwen , and . is ignored by the compiler. In this case, we declare Romeo, used to hold the character being decoded, and Juliet, used to hold the run length of the character.

Act I: In which the lengths of runs are decoded.

Here we declare the first and only act in the program. Acts and scenes are like labels; they can be jumped to at any time by using let us return to scene II or some variant of that. We only use one act, because it's sufficient for our needs. Again, anything between : and . is ignored by the compiler.

Scene I: A silent entrance.

Here we declare the first scene. Scenes are numbered in Roman numerals: the first is Scene I, the second Scene II, and so on.

[Enter Romeo and Juliet]

This is a stage direction; in it, we tell the Romeo and Juliet variables to come onto the "stage". Only two variables can be on the "stage" at once; the stage is used so that the compiler can figure out which variable is addressing which when they speak. Because we have only two variables, Romeo and Juliet will stay onstage for the length of the program.

Scene II: In which neither Romeo nor Juliet believes the other open-minded.

Another scene declaration. Scene II will be jumped to in order to decode another run-length.

Juliet:

This form of declaration means that Juliet is going to start speaking. Everything until the next Romeo:, stage direction, or scene/act declaration will be a line spoken by Juliet, and thus "me" will refer to Juliet, "you"/"thou" to Romeo, etc.

Open your mind.

This command stores the ordinal value of single character from STDIN in Romeo.

Is my mother jollier than thou?

In SPL, nouns translate to either 1 or -1 depending on whether they are positive or negative. In this case, my mother translates to 1. Adjectives (positive or negative) multiply their noun by 2.

This is a question; in it, Juliet asks if my mother (AKA 1) is "jollier" than Romeo. Comparatives either translate to less than (if they are negative, like worse) or greater than (if they are positive, like jollier). Therefore, this question boils down to Is 1 greater than you?.

The reason we ask this question is to detect the end of the input. Since the value of EOF varies by platform, but is usually less than 1, we use this to detect it.

If so, we must proceed to scene IV.

If the preceding question evaluated to true, we jump to scene IV—which is simply the end of the program. In short, if we detect an EOF, we end the program.

Romeo:

It's now Romeo's line: "me" and "you" refer to Romeo and Juliet, respectively.

Open your mind.

Again, this statement puts the ordinal value of a single character from STDIN into Juliet, which in this case is the run-length of the character stored in Romeo.

Thou art the sum of thyself and the sum of my good aunt and the difference 
between nothing and the quotient of the square of twice the sum of thy foul
fat-kidneyed goat and thy death and thy evil variable!

This one's too long to go over in great detail, but just trust me in that it translates to Juliet -= 48. We do this because Juliet holds the ASCII value of a numeral, and ord('0') == 48; in subtracting 48, we translate from the ASCII value of a number to the number itself.

Scene III: In which Romeo snaps and brutally insults Juliet.

Another scene declaration. This one is for the loop in which we repeatedly print the character value of Romeo, Juliet times.

Juliet:
  Speak thy mind.

This statement causes Romeo to print his value as a character; that is, whatever character value was previously stored in Romeo is now output.

Romeo:
  Thou art the sum of thyself and a hog!

A hog is a negative noun, so a hog translates to -1; therefore, this statement evaluates to Juliet -= 1.

Art thou as rotten as nothing?

Romeo here asks if Juliet is "as rotten as", or equal to, 0.

If so, let us return to scene II.

If Juliet's value is 0, we loop back to scene II to decode another character's run-length.

Let us return to scene III.

Else, we loop back to scene III to output Romeo's character again.

Scene IV: Finale.

[Exeunt]

This final scene declaration is just a marker for the end of the program. The [Exeunt] stage direction is necessary to get the compiler to actually generate the final scene.

Copper

Posted 2013-10-19T08:13:47.923

Reputation: 3 684

6

GolfScript, 10 characters

2/{1/~~*}/

Howard

Posted 2013-10-19T08:13:47.923

Reputation: 23 109

5

perl, 27 characters

print<>=~s/(.)(.)/$1x$2/ger

John Dvorak

Posted 2013-10-19T08:13:47.923

Reputation: 9 048

This seems unnecessarily verbose: print<>=~s/(.)(.)/$1x$2/ger. I'm also fairly sure you meant $1x$2, and not the other way around. – primo – 2013-10-19T11:17:52.963

@primo true - I didn't know about the r flag and I couldn't find it. Thanks. As for other part - sorry, I misread the spec. I'll edit when I can. – John Dvorak – 2013-10-19T11:26:42.977

BTW /r is documented in perlop and was added in v5.14.0

– psxls – 2013-10-20T13:34:59.423

Using the -p flag let you drop print and <>, so answer will become simply: s/(.)(.)/$1x$2/ge -> 17chars +1 for -p -> 18. – F. Hauri – 2013-12-04T16:52:42.830

4

R 67

x=strsplit(readline(),"")[[1]];cat(rep(x[c(T,F)],x[c(F,T)]),sep="")

flodel

Posted 2013-10-19T08:13:47.923

Reputation: 2 345

+1 I had no idea rep would coerce the times argument from characters to integers automatically. Brilliant. – plannapus – 2013-10-21T06:59:27.010

4

Python 3, 52

Python 3 allows me to merge the approaches of my two python2 solutions.

s=input()
t=''
while s:a,b,*s=s;t+=a*int(b)
print(t)

boothby

Posted 2013-10-19T08:13:47.923

Reputation: 9 038

149: s=input() while s:a,b,*s=s;print(a*int(b),end='') – Cees Timmerman – 2016-08-23T14:53:16.900

Python 2 raw_input matches Python 3 input. So first line must by s=input() – AMK – 2013-12-08T18:07:55.303

46 bytes – movatica – 2019-08-30T15:05:09.420

3

APL (22)

,/{⍺/⍨⍎⍵}/↑T⊂⍨~⎕D∊⍨T←⍞

Explanation:

  • T←⍞: store input in T
  • T⊂⍨~⎕D∊⍨T: split T on those characters that aren't digits
  • : turn it into a 2-by-N/2 matrix
  • {⍺/⍨⍎⍵}/: on each row of the matrix (/), replicate (/) the first character () by the eval () of the second character ()
  • ,/: concatenate the output of each row

marinus

Posted 2013-10-19T08:13:47.923

Reputation: 30 224

3

Ruby, 30 bytes

gsub!(/(.)(.)/){$1*$2.to_i}

27 bytes code + 3 bytes to run it with the -p flag:

$ ruby -p rld.rb <<< ":144,1'1"
:4444,'

daniero

Posted 2013-10-19T08:13:47.923

Reputation: 17 193

2

8086 assembly, 106 98 characters

l:
mov ah,8
int 21h
mov bl,al
int 21h
sub al,48
mov cl,al
xor ch,ch
mov al,bl
mov ah,14
p:
int 10h
loop p
jmp l

If the numbers were before the characters in the input stream, two lines (18 characters) could be shaved off of this.

Mike C

Posted 2013-10-19T08:13:47.923

Reputation: 1 169

Just removed a redundant "mov ah,8" – Mike C – 2013-10-20T08:39:12.373

2You should post compiled byte count rather than our assembler char count. Rules abuse FTW – arrdem – 2013-12-04T21:11:25.640

What about dq 21cdc38821cd08b4 d888ed30c188482c e8ebfce210cd14b4 for 53 characters? I don't see where it handles non-uppercase characters or eof though... – Jason Goemaat – 2013-12-04T22:17:41.220

arrdem: Good idea. I wonder if it's even breaking the rules if I hand-assemble it in a hex editor. I'd still be directly writing the code, just on a lower level than asm source. :)

Jason: I don't see anything about EOF in the rules. It's stdin, just hit ctrl-c to stop it. Also why wouldn't it handle lowercase letters? – Mike C – 2013-12-05T22:24:53.290

Generally machine code is counted by byte count in comparison to source code count for interpreted or compiled languages, as there really is no reasonable alternative. – Joe Z. – 2013-12-07T05:01:12.397

I count your code as 24 bytes assembled. You can -2 bytes by using push ax instead of mov bl,al and pop ax instead of mov al,bl. Also you can -2 more by removing the xor ch,ch since CH is init'd to 0 by DOS (http://www.fysnet.net/yourhelp.htm).

– 640KB – 2019-07-29T20:33:27.763

2

GNU SED, 122 + 2 (-r)

#n
s/.*/\n&\a987654321\v\v\v\v\v\v\v\v\v/
:a
s/\n(.)(.)(.*\a.*\2.{9}(.*))/\1\n\4\3/
tb
bc
:b
s/(.)\n\v/\1\1\n/
tb
ba
:c
P

Needs to be run with the -r flag
May be reduced to 110 + 2 by replacing \v with the unprintable 0x0B and \a with 0x07

Hasturkun

Posted 2013-10-19T08:13:47.923

Reputation: 1 206

+1 (\2.{9} is a great idea) splendid! – F. Hauri – 2013-12-04T22:50:11.180

2

C, 65 chars

Gets the input as a parameter.

main(p,v)char*p,**v;{
    for(p=v[1];*p;--p[1]<49?p+=2:0)putchar(*p);
}

ugoren

Posted 2013-10-19T08:13:47.923

Reputation: 16 527

I can't get past this with gcc: error: first parameter of 'main' (argument count) must be of type 'int'. Is there a command line switch? – Darren Stone – 2013-12-04T18:18:48.430

@DarrenStone, this code isn't 100% standard compliant. I don't use the first parameter as a parameter, so its type doesn't matter. Most compilers don't mind so much. – ugoren – 2013-12-05T20:16:42.890

Ok, thanks. I'm envious of your golf-friendlier compiler! :) – Darren Stone – 2013-12-05T21:07:04.253

2

Perl, 19 18 characters

perl -pe 's/(.)(.)/$1x$2/ge'

The rules for counting switches on the command-line are here.

breadbox

Posted 2013-10-19T08:13:47.923

Reputation: 6 893

2

Haskell, 58 56 characters

f[]=[]
f(x:y:s)=replicate(read[y])x++f s
main=interact$f

My first real attempt at golfing anything, so there's probably some improvement to be made here.

Silvio Mayolo

Posted 2013-10-19T08:13:47.923

Reputation: 1 817

I'm getting 57 bytes for this? You can replace replicate x y with [1..x]>>[y]. Thus your second line can be replaced with f(x:y:s)=(['1'..y]>>[x])++f s, which brings it down to 53 bytes. – Angs – 2016-10-12T16:18:46.130

1read[y] saves two characters – MtnViewMark – 2013-12-06T20:48:32.523

@MtnViewMark Thanks. I put it in. – Silvio Mayolo – 2013-12-07T22:54:28.093

2

Forth, 45 characters

BEGIN KEY KEY 48 - 0 DO DUP EMIT LOOP 0 UNTIL

Tested with pforth on OS X.

Darren Stone

Posted 2013-10-19T08:13:47.923

Reputation: 5 072

2

C, 68 characters

@ugoren's answer in C is slightly shorter, but this answer complies with the requirement that "the string will be supplied as input on stdin."

n;main(c){for(;;){c=getchar(),n=getchar()-48;while(n--)putchar(c);}}

Darren Stone

Posted 2013-10-19T08:13:47.923

Reputation: 5 072

You can shave off a character by dropping "int " and declaring c and n as parameters of main, another by using for(;;) instead of while(1), and finally two more by dropping the braces on the innermost while loop. – Stuntddude – 2013-12-04T11:09:15.523

Thanks, @Stuntddude! I applied the loop and brace suggestions, but I'm struggling with "declaring c and n as parameters of main". Still, this shaved 3 chars. Cheers. – Darren Stone – 2013-12-04T18:21:33.977

Since main() is a function, you can give it parameters, like: main(c,n){ ... } which will be passed 1 by default when the program is run. – Stuntddude – 2013-12-04T22:55:30.497

Thanks @Stuntddude. I'm aware of that and can take advantage of the 1st int arg, but compiler(s) I use complain error: second parameter of 'main' (argument array) must be of type 'char **' so I can't get away with main(c,n); I must use main(int c,char **n). Could be a platform or gcc thing. – Darren Stone – 2013-12-04T23:15:32.927

My compiler lets me do n;main(c) but not main(n,c) -- good enough! :) – Darren Stone – 2013-12-04T23:25:55.203

2

Python, 63 62 characters

print''.join([c*int(n)for c,n in zip(*[iter(raw_input())]*2)])

Darren Stone

Posted 2013-10-19T08:13:47.923

Reputation: 5 072

Nice trick with iter there... I think I'll use it myself! – boothby – 2013-12-04T07:24:55.733

2

Windows PowerShell, 55 chars

-join((read-host)-split'(..)'|%{(""+$_[0])*(""+$_[1])})

I get the feeling that this can be golfed down more, specifically with the casts from char to string and int, but I don't have the time to keep working on it right now.

goric

Posted 2013-10-19T08:13:47.923

Reputation: 271

2

05AB1E, 6 5 bytes

2ι`ÅΓ

-1 byte thanks to @Grimy.

Outputs as a list of characters.

Try it online.

Old 6 bytes answer without run-length decode builtin:

2ôε`×?

Try it online.

Explanation:

2ι      # Uninterleave the (implicit) input-string in two parts
        #  i.e. ":144,1'3" → [":4,'","1413"]
  `     # Push both separated to the stack
   ÅΓ   # Run-length decode
        #  i.e. ":4,'" and "1413" → [":","4","4","4","4",",","'","'","'"]
        # (after which the result is output implicitly)

2ô      # Split the (implicit) input-string into parts of size 2
        #  i.e. ":144,1'3" → [":1","44",",1","'3"]
  ε     # Loop over each of these pairs:
   `    #  Push both characters separated to the stack
    ×   #  Repeat the first character the digit amount of times as string
        #   i.e. "'" and "3" → "'''"
     ?  #  And print it without trailing newline

Kevin Cruijssen

Posted 2013-10-19T08:13:47.923

Reputation: 67 575

12ι`ÅΓ is 5 bytes. Would be sad if the RLE built-in didn't win an RLE challenge. – Grimmy – 2019-08-30T14:27:46.633

@Grimy Ah, that's indeed better, thanks! :) – Kevin Cruijssen – 2019-08-30T16:50:57.450

2

Japt -P, 8 bytes

Input as an array of characters, output as a string.

ò crÈpY°

Try it

ò crÈpYn     :Implicit input of character array
ò            :Groups of 2
   r         :Reduce each pair
    È        :By passing them through the following function as [X,Y]
     p       :  Repeat X
      Yn     :    Y, converted to an integer, times
             :Implicitly join and output

Shaggy

Posted 2013-10-19T08:13:47.923

Reputation: 24 623

Oh, c​r​e​epy!​ – Khuldraeseth na'Barya – 2019-07-27T20:52:10.577

@Khuldraesethna'Barya, it can also be ò crÏ°îX if you find it too creepy! – Shaggy – 2019-07-27T20:53:48.047

2

Malbolge Unshackled (20-trit rotation variant), 4,494e6 bytes

Size of this answer exceeds maximum postable program size (eh), so the code is located in my GitHub repository.

How to run this?

This might be a tricky part, because naive Haskell interpreter will take ages upon ages to run this. TIO has decent Malbogle Unshackled interpreter, but sadly I won't be able to use it (limitations).

The best one I could find is the fixed 20-trit rotation width variant, that performs very well, decompressing 360 bytes per hour.

To make the interpreter a bit faster, I've removed all the checks from Matthias Lutter's Malbolge Unshackled interpreter.

My modified version can run around 6,3% faster.

#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

const char* translation = "5z]&gqtyfr$(we4{WP)H-Zn,[%\\3dL+Q;>U!pJS72Fh"
        "OA1CB6v^=I_0/8|jsb9m<.TVac`uY*MK'X~xDl}REokN:#?G\"i@";

typedef struct Word {
    unsigned int area;
    unsigned int high;
    unsigned int low;
} Word;

void word2string(Word w, char* s, int min_length) {
    if (!s) return;
    if (min_length < 1) min_length = 1;
    if (min_length > 20) min_length = 20;
    s[0] = (w.area%3) + '0';
    s[1] = 't';
    char tmp[20];
    int i;
    for (i=0;i<10;i++) {
        tmp[19-i] = (w.low % 3) + '0';
        w.low /= 3;
    }
    for (i=0;i<10;i++) {
        tmp[9-i] = (w.high % 3) + '0';
        w.high /= 3;
    }
    i = 0;
    while (tmp[i] == s[0] && i < 20 - min_length) i++;
    int j = 2;
    while (i < 20) {
        s[j] = tmp[i];
        i++;
        j++;
    }
    s[j] = 0;
}

unsigned int crazy_low(unsigned int a, unsigned int d){
    unsigned int crz[] = {1,0,0,1,0,2,2,2,1};
    int position = 0;
    unsigned int output = 0;
    while (position < 10){
        unsigned int i = a%3;
        unsigned int j = d%3;
        unsigned int out = crz[i+3*j];
        unsigned int multiple = 1;
        int k;
        for (k=0;k<position;k++)
            multiple *= 3;
        output += multiple*out;
        a /= 3;
        d /= 3;
        position++;
    }
    return output;
}

Word zero() {
    Word result = {0, 0, 0};
    return result;
}

Word increment(Word d) {
    d.low++;
    if (d.low >= 59049) {
        d.low = 0;
        d.high++;
        if (d.high >= 59049) {
            fprintf(stderr,"error: overflow\n");
            exit(1);
        }
    }
    return d;
}

Word decrement(Word d) {
    if (d.low == 0) {
        d.low = 59048;
        d.high--;
    }else{
        d.low--;
    }
    return d;
}

Word crazy(Word a, Word d){
    Word output;
    unsigned int crz[] = {1,0,0,1,0,2,2,2,1};
    output.area = crz[a.area+3*d.area];
    output.high = crazy_low(a.high, d.high);
    output.low = crazy_low(a.low, d.low);
    return output;
}

Word rotate_r(Word d){
    unsigned int carry_h = d.high%3;
    unsigned int carry_l = d.low%3;
    d.high = 19683 * carry_l + d.high / 3;
    d.low = 19683 * carry_h + d.low / 3;
    return d;
}

// last_initialized: if set, use to fill newly generated memory with preinitial values...
Word* ptr_to(Word** mem[], Word d, unsigned int last_initialized) {
    if ((mem[d.area])[d.high]) {
        return &(((mem[d.area])[d.high])[d.low]);
    }
    (mem[d.area])[d.high] = (Word*)malloc(59049 * sizeof(Word));
    if (!(mem[d.area])[d.high]) {
        fprintf(stderr,"error: out of memory.\n");
        exit(1);
    }
    if (last_initialized) {
        Word repitition[6];
        repitition[(last_initialized-1) % 6] =
                ((mem[0])[(last_initialized-1) / 59049])
                    [(last_initialized-1) % 59049];
        repitition[(last_initialized) % 6] =
                ((mem[0])[last_initialized / 59049])
                    [last_initialized % 59049];
        unsigned int i;
        for (i=0;i<6;i++) {
            repitition[(last_initialized+1+i) % 6] =
                    crazy(repitition[(last_initialized+i) % 6],
                        repitition[(last_initialized-1+i) % 6]);
        }
        unsigned int offset = (59049*d.high) % 6;
        i = 0;
        while (1){
            ((mem[d.area])[d.high])[i] = repitition[(i+offset)%6];
            if (i == 59048) {
                break;
            }
            i++;
        }
    }
    return &(((mem[d.area])[d.high])[d.low]);
}

unsigned int get_instruction(Word** mem[], Word c,
        unsigned int last_initialized,
        int ignore_invalid) {
    Word* instr = ptr_to(mem, c, last_initialized);
    unsigned int instruction = instr->low;
    instruction = (instruction+c.low + 59049 * c.high
            + (c.area==1?52:(c.area==2?10:0)))%94;
    return instruction;
}

int main(int argc, char* argv[]) {
    Word** memory[3];
    int i,j;
    for (i=0; i<3; i++) {
        memory[i] = (Word**)malloc(59049 * sizeof(Word*));
        if (!memory) {
            fprintf(stderr,"not enough memory.\n");
            return 1;
        }
        for (j=0; j<59049; j++) {
            (memory[i])[j] = 0;
        }
    }
    Word a, c, d;
    unsigned int result;
    FILE* file;
    if (argc < 2) {
        // read program code from STDIN
        file = stdin;
    }else{
        file = fopen(argv[1],"rb");
    }
    if (file == NULL) {
        fprintf(stderr, "File not found: %s\n",argv[1]);
        return 1;
    }
    a = zero();
    c = zero();
    d = zero();
    result = 0;
    while (!feof(file)){
        unsigned int instr;
        Word* cell = ptr_to(memory, d, 0);
        (*cell) = zero();
        result = fread(&cell->low,1,1,file);
        if (result > 1)
            return 1;
        if (result == 0 || cell->low == 0x1a || cell->low == 0x04)
            break;
        instr = (cell->low + d.low + 59049*d.high)%94;
        if (cell->low == ' ' || cell->low == '\t' || cell->low == '\r'
                || cell->low == '\n');
        else if (cell->low >= 33 && cell->low < 127 &&
                (instr == 4 || instr == 5 || instr == 23 || instr == 39
                    || instr == 40 || instr == 62 || instr == 68
                    || instr == 81)) {
            d = increment(d);
        }
    }
    if (file != stdin) {
        fclose(file);
    }
    unsigned int last_initialized = 0;
    while (1){
        *ptr_to(memory, d, 0) = crazy(*ptr_to(memory, decrement(d), 0),
                *ptr_to(memory, decrement(decrement(d)), 0));
        last_initialized = d.low + 59049*d.high;
        if (d.low == 59048) {
            break;
        }
        d = increment(d);
    }
    d = zero();

    unsigned int step = 0;
    while (1) {
        unsigned int instruction = get_instruction(memory, c,
                last_initialized, 0);
        step++;
        switch (instruction){
            case 4:
                c = *ptr_to(memory,d,last_initialized);
                break;
            case 5:
                if (!a.area) {
                    printf("%c",(char)(a.low + 59049*a.high));
                }else if (a.area == 2 && a.low == 59047
                        && a.high == 59048) {
                    printf("\n");
                }
                break;
            case 23:
                a = zero();
                a.low = getchar();
                if (a.low == EOF) {
                    a.low = 59048;
                    a.high = 59048;
                    a.area = 2;
                }else if (a.low == '\n'){
                    a.low = 59047;
                    a.high = 59048;
                    a.area = 2;
                }
                break;
            case 39:
                a = (*ptr_to(memory,d,last_initialized)
                        = rotate_r(*ptr_to(memory,d,last_initialized)));
                break;
            case 40:
                d = *ptr_to(memory,d,last_initialized);
                break;
            case 62:
                a = (*ptr_to(memory,d,last_initialized)
                        = crazy(a, *ptr_to(memory,d,last_initialized)));
                break;
            case 81:
                return 0;
            case 68:
            default:
                break;
        }

        Word* mem_c = ptr_to(memory, c, last_initialized);
        mem_c->low = translation[mem_c->low - 33];

        c = increment(c);
        d = increment(d);
    }
    return 0;
}

It's working!

It's working

Krzysztof Szewczyk

Posted 2013-10-19T08:13:47.923

Reputation: 3 819

1

Python, 78 72 66 char

d=raw_input()
print"".join([x*int(d[i+1])for i,x in enumerate(d)if~i&1])

s=raw_input()
print"".join(i*int(j)for i,j in zip(s[::2],s[1::2]))

Coding man

Posted 2013-10-19T08:13:47.923

Reputation: 1 193

1

GolfScript (10 chars)

2/{)15&*}/

Peter Taylor

Posted 2013-10-19T08:13:47.923

Reputation: 41 901

1

J - 24

;@(_2(<@#~".)/\])@1!:1 3

The point of this submission is to use the infix adverb.

jpjacobs

Posted 2013-10-19T08:13:47.923

Reputation: 3 440

1

Python 2, 58

This is inspired by Darren Stone's python solution -- iterator abuse!

x=iter(raw_input())
print''.join(a*int(next(x))for a in x)

This is my original solution (60 chars)

s=raw_input()
t=''
while s:t+=s[0]*int(s[1]);s=s[2:]
print t

A different approach is 3 chars longer:

f=lambda a,b,*x:a*int(b)+(x and f(*x)or'')
print f(raw_input())

boothby

Posted 2013-10-19T08:13:47.923

Reputation: 9 038

1

Befunge, 49 chars

>~:25*-      v
$>\1-:v:-*68~_@
$^ ,:\_v
^      <

saeedn

Posted 2013-10-19T08:13:47.923

Reputation: 1 241

1

K, 35

{,/(#).'|:'"*I"$/:(2*!-_-(#x)%2)_x}

tmartin

Posted 2013-10-19T08:13:47.923

Reputation: 3 917

,/{(. y)#x}.'0N 2# for 18 bytes. – streetster – 2019-07-26T11:51:04.087

1

Jelly, 10 bytes

s2µṪV$€x@Ẏ

Try it online!

GOLFSCRIPT TIE JELLY DAT IMPOSSIBLE WAAAAAT!?

Jelly, 10 bytes

Ḋm2V€x@m2$

Try it online!

Erik the Outgolfer

Posted 2013-10-19T08:13:47.923

Reputation: 38 134

1

Java: 285 charas

import java.util.Scanner;public class A{public static void main(String args[]){Scanner s = new Scanner(System.in);while(s.hasNext()){String t=s.next();for(int i=0;i<t.length();i++) {for(int j=0; j<(Byte.valueOf(t.substring(i+1,i+2)));j++){System.out.print(t.substring(i,i+1));}i++;}}}}

masterX244

Posted 2013-10-19T08:13:47.923

Reputation: 3 942

Use static blocks instead of a main, and compile it with Java6! – Fabinout – 2013-12-04T10:52:51.840

1

Befunge-98, 22 chars

>#@~~"0"-v
^#:\,:\-1<_

FireFly

Posted 2013-10-19T08:13:47.923

Reputation: 7 107

1

Whitespace, 135

LSSSLSSSSLSLSTLTSTTTSLSSSSTSSSSLTSSTLTTTTLSSSSLSLSTLTSTTTSSSTTSSSSLTSSTLSSSSLSLSLTSTLSSSTLTSSTSTSSTLTLSSLSLSSLLSSTLSLLSLLLSLSLLSSTTLLLL

(Replace S,T,L with Space,Tab,Linefeed characters.)

Try it online [here].

Explanation:

"assembly"      whitespace                                      stack
----------      ----------                                      -----
s:              LSS SL      ;input loop                         []
    push 0      SS SSL                                          [0]
    dup         SLS                                             [0,0]
    getc        TLTS        ;input & store char c               [0]
    rcl         TTT         ;recall c                           [c]
    dup         SLS                                             [c,c]
    push 16     SS STSSSSL                                      [c,c,16]
    sub         TSST                                            [c,c-16]
    jlt  tt     LTT TTL     ;exit if ord(c) < 16                [c]       
    push 0      SS SSL                                          [c,0]
    dup         SLS                                             [c,0,0]
    getc        TLTS        ;input & store char n               [c,0]
    rcl         TTT         ;recall n                           [c,n]
    push 48     SS STTSSSSL ;convert n to m = ord(n)-ord('0')   [c,n,48]
    sub         TSST                                            [c,m]

ss:             LSS SSL     ;inner loop outputs c, m times      [c,m]
    dup         SLS                                             [c,m,m]
    jeq  t      LTS TL      ;if m==0, stop outputting this c    [c,m]
    push 1      SS STL      ;otherwise decr m                   [c,m,1]
    sub         TSST                                            [c,m-1]
    copy 1      STS STL     ;copy c to tos                      [c,m-1,c]
    putc        TLSS        ;output this c                      [c,m-1]
    jmp  ss     LSL SSL     ;loop back to output this c again   [c,m-1]

t:              LSS TL                                          [c,m]
    pop         SLL                                             [c]
    pop         SLL                                             []
    jmp  s      LSL SL      ;loop back to get the next c,n      []

tt:             LSS TTL                                         [c]
    end         LLL         ;exit

r.e.s.

Posted 2013-10-19T08:13:47.923

Reputation: 2 872

1

Clojure (107)

(pr(apply str(map #(apply str(repeat(Integer/parseInt(str(second %)))(first %)))(partition 2(read-line)))))

This feels exceptionally long for being Clojure, if someone can do better, please post it.

Headmastersquall

Posted 2013-10-19T08:13:47.923

Reputation: 41

60 or 73 bytes at https://codegolf.stackexchange.com/a/188823/59617 ;)

– NikoNyrh – 2019-07-26T12:35:53.223

1

K (oK), 17 bytes

Solution:

,/{(.y)#x}.'0N 2#

Try it online!

Explanation:

,/{(.y)#x}.'0N 2# / the solution
            0N 2# / reshape input into Nx2 grid
  {      }.'      / apply lambda to each pair of inputs
       #x         / take from x
   (  )           / do this together
    .y            / value y (ie "5" => 5)
,/                / flatten

streetster

Posted 2013-10-19T08:13:47.923

Reputation: 3 635

1

><>, 28 24 bytes

Saved 4 bytes thanks to Jo King!

/1-:?v
\$o:$<-*c4i;?(0:i

Try it online!

This was very interesting to golf the form. You can see my process below.

Alternatives

i:0(?;i4c*->:    ?v
           ^$o:$-1<

/?      <:-*c4i;?(0:i
\1-$:o$:^0

/?    :<-*c4i;?(0:i
\1-$:o$^.00

/?    :<-*c4ip1c;?(0:i
\1-c1go^.00

/?    :<-*c4ip1c;?(0:i
\1-c1go^.00

/?}-1<:-*c4i;?(0:i[0
\:o}:^.00

/?}-1<:-*c4i;?(0:i[0
\:o}:^00

0/?}-1<:-*c4i;?(0:i[
0\:o}:^

Conor O'Brien

Posted 2013-10-19T08:13:47.923

Reputation: 36 228

@JoKing nice! thanks! – Conor O'Brien – 2019-07-28T01:54:23.447

1

Perl 6, 20 bytes

{S:g{(.)(.)}=$0 x$1}

Try it online!

Anonymous codeblock containing a regex that replaces each pair of characters in the input with the first one repeated by the second.

Jo King

Posted 2013-10-19T08:13:47.923

Reputation: 38 234

1

8088 Assembly, IBM PC DOS, 24 bytes

Binary xxd dump:

00000000: d1ee add0 e88a c8ad 80ec 308a dcb4 0ecd  ..........0.....
00000010: 10fe cb75 f8e2 f0c3                      ...u....

Unassembled listing:

D1 EE       SHR  SI, 1          ; point SI to DOS PSP (080H) 
AD          LODSW               ; load input length into AL 
D0 E8       SHR  AL, 1          ; half input length to get number of CN pairs 
8A C8       MOV  CL, AL         ; move into counter 
        C_LOOP: 
AD          LODSW               ; Load pair: C = AL, N = AH 
80 EC 30    SUB  AH, '0'        ; ASCII convert N to binary 
8A DC       MOV  BL, AH         ; BL is counter for number of reps of C 
        N_LOOP: 
B4 0E       MOV  AH, 0EH        ; BIOS teletype output function 
CD 10       INT  10H            ; call BIOS, display C 
FE CB       DEC  BL             ; decrement loop counter 
75 F8       JNZ  N_LOOP         ; if end of N loop, move to next C 
E2 F0       LOOP C_LOOP         ; loop through all C's 
C3          RET                 ; return to DOS 

Standalone DOS executable program. Input via command line, output to console.

enter image description here

640KB

Posted 2013-10-19T08:13:47.923

Reputation: 7 149

1

Brachylog, 11 bytes

ġ₂{ẹịᵗj₎}ᵐc

Try it online!

          c    The output is the concatenation of
  {     }ᵐ     the result of mapping
   ẹịᵗj₎       repeating the first element by the second converted to an integer
ġ₂             over the length-2 chunks of the input.

Unrelated String

Posted 2013-10-19T08:13:47.923

Reputation: 5 300

1

C# - 108 105 bytes

void f(){var s=Console.ReadLine();for(int i=0;i<s.Length;i+=2)Console.Write(new string(s[i],s[i+1]-48));}

Explanation:

void f()
{
    var s = Console.ReadLine(); // Read the input from STDIN.

    // Loop until the end of the string, and increment our index counter by 2 at each iteration.
    for (int i = 0; i < s.Length; i += 2) 

        Console.Write(new string(s[i], s[i + 1] - 48)); // Create (s[i + 1] - 48) copies of the current character, and print it.
        // s[i + 1] - 48 implicitly casts the character at s[i + 1] to its integer digit form. 
}

Yytsi

Posted 2013-10-19T08:13:47.923

Reputation: 3 582

Please add an explanation to help people less familiar with C# although it may seem simple enough, short answers with no code do get auto-flagged – Rohan Jhunjhunwala – 2016-08-22T11:31:25.827

@RohanJhunjhunwala Sure. I'll add it when I get home. My C++ answer will also have it then. – Yytsi – 2016-08-22T13:03:59.833

@RohanJhunjhunwala Explanation added. Does it look good to you? – Yytsi – 2016-08-22T20:57:11.660

1Looks good, good work! – Rohan Jhunjhunwala – 2016-08-22T21:01:26.813

1

JavaScript (ES6), 40 bytes

s=>s.replace(/../g,v=>v[0].repeat(v[1]))

f=
  s=>s.replace(/../g,v=>v[0].repeat(v[1]))
;
console.log(f(":144,1'1"))

Hedi

Posted 2013-10-19T08:13:47.923

Reputation: 1 857

1

PHP, 51 bytes

for(;--$z?:($c=$argn[$i++]).$z=$argn[$i++];)echo$c;

Try it online!

PHP, 54 bytes

for(;~$c=$argn[$i++];)echo str_repeat($c,$argn[$i++]);

Try it online!

PHP, 54 bytes

for(;~$c=$argn[$i++];)echo str_pad($c,$argn[$i++],$c);

Try it online!

Jörg Hülsermann

Posted 2013-10-19T08:13:47.923

Reputation: 13 026

1

RProgN, 55 Bytes

S y = '' x = y L ¿ y pop y pop \ rep x . 'x' = y L } x

Explained

S y =               # Convert the input to a backwards stack, assign it to y.
'' x =              # Assign a blank string to x
y L                 # Push the length of y
¿                   # While the top of the stack is truthy, popping.
    y pop           # Push the top value of y to the stack.
    y pop           # Twice.
    \               # Swap them around, so we get C 1 instead of 1 C
    rep             # Repeat the string. (C 1 times in the above example)
    x . 'x' =       # Append it to the back of x, and re-assign it. We use the back because we're starting at the END of the string.
    y L             # Push the length of y for the next itteration of the loop.
}                   #
x                   # Push x, and implicitly print it.

Try it Online!

ATaco

Posted 2013-10-19T08:13:47.923

Reputation: 7 898

0

Ahead, 12 bytes

~W:k-1'ii@j~

Explained

Single line Ahead boards are nice because you can explain them without some kind of diagram.

(Program effectively loops in reverse by floating)

~            float to next ~ (to end of line)
          ~  stop floating (end of line, turn around)
         j   jump next
       i     read char from input
        @    bounce here and die if input is empty, else continue west
      i      read digit char from input
   -1'       subtract '1 (49) from input char to get digit value
  :          dup first char that many times
 W           Write stack to output as chars
~            (repeat until head dies from empty input)

Try it online!

snail_

Posted 2013-10-19T08:13:47.923

Reputation: 1 982

0

Clojure, 60 bytes

#(apply str(for[[c n](partition 2 %)_(range(-(int n)48))]c))

I assume we can take the input as an argument and return the string. If not this grows to 73 bytes:

#(pr(apply str(for[[c n](partition 2(read-line))_(range(-(int n)48))]c))

NikoNyrh

Posted 2013-10-19T08:13:47.923

Reputation: 2 361

0

SmileBASIC, 54 bytes

LINPUT S$WHILE I<LEN(S$)?S$[I]*VAL(S$[I+1]);
I=I+2WEND

Alternative (same size):

LINPUT S$WHILE""<S$?SHIFT(S$)*VAL(S$[1]);
S$[0]="
WEND

Really wanted to write ?SHIFT(S$)*VAL(SHIFT(S$)) but expressions are evaluated right to left, so the shifts would happen in the wrong order...

12Me21

Posted 2013-10-19T08:13:47.923

Reputation: 6 110

0

Python 2, 40 bytes

f=lambda s:s and s[0]*int(s[1])+f(s[2:])

Try it online!

Chas Brown

Posted 2013-10-19T08:13:47.923

Reputation: 8 959

0

Senva, 33 bytes

I was first making a big answer with a large code into the back-memory, but finally I made that :

1'(`>0.>{@}0'{v}1'0,>48-0,-<~>$>$

Here is an explanation :

1'  // Go to the second cell, the first will be used to store an information
(   // Input a string
`   // Go to the last cell (at the last character of the string)
>   // Make a new cell after the string
0.  // Store a 0 to mark the end of the string
>   // Make a new cell
{@} // Store this adress into the back-memory
0'  // Go to the 1st cell
{v} // Paste the adress, now the 1st cell contains the adress which points after the '0' which marks the end of the string
1'  // Go to the 2nd cell (the beginning of the string)
0,  // While we do NOT encounter a zero (while the string is not terminated)
  >   // Go to the next cell (the repeat number)
  48- // Substract 48 to get the number (the string was stored as an ASCII chain)
  0,  // While this cell is not equal to 0 (higher than 0)
    - // Decrease the cell
    < // Go to the cell which contains the character to repeat
    ~ // Display it
    > // Go to the number
  $ // End of the loop
  > // Go to the next number
$ // End of the loop

So we make a loop across the string, and a second loop into which display the C character `` times.

ClementNerma

Posted 2013-10-19T08:13:47.923

Reputation: 111

0

Gema, 17 16 characters

??=@repeat{$2;?}

Sample run:

bash-4.3$ gema '??=@repeat{$2;?}' <<< ":144,1'1"
:4444,'

Try it online!

manatwork

Posted 2013-10-19T08:13:47.923

Reputation: 17 865

0

C++ - 151 144 142 bytes

#include <iostream>
#include <string>
void f(){std::string p;std::cin>>p;for(int i=0,j;i<p.size();i+=2)for(j=48;j<p[i+1];j++)std::cout<<p[i];}

Way too long. I should probably just use an character pointer instead and forget the whole string thing.

2 bytes saved by @PeterTaylor!

Explanation:

void f()
{
    std::string p; // A string to hold the input.
    std::cin >> p; // Read the input from STDIN, and source to <p>.

    // Loop until the end of the string <p>, withs index jumps of 2 at each iteration.
    for(int i = 0, j; i < p.size(); i += 2)

        // Loop (p[i + 1] - 48) times, and print the current character each time.
        /* p[i + 1] - 48 is a neat way to convert the next character in the string
           to its integer digit from. */
        for(j = 48; j < p[i + 1]; j++)
            std::cout << p[i]; // Print the character we are at.
}

Yytsi

Posted 2013-10-19T08:13:47.923

Reputation: 3 582

for(j=0;j<p[i+1]-48;j++): since you're not using j inside the loop, you can save two chars with for(j=48;j<p[i+1];j++) – Peter Taylor – 2016-08-23T07:41:46.050

@PeterTaylor Good catch, thanks! – Yytsi – 2016-08-23T07:45:46.700

0

><> - 36 Bytes

i:01-=?; l2=?v
v?=*68:ro:r-1<
>~~d0.

This solution can be run without using the input flag or preloading the stack, although both of those methods could cut down on bytes. If there is any interest, I can describe how it works to anyone who is curious.

Try it here!

L. Steer

Posted 2013-10-19T08:13:47.923

Reputation: 57

0

JavaScript, 40 bytes

f=v=>v&&v[0].repeat(v[1])+f(v.slice(2))

Recursive. Expand first 2 characters and call self with remainder of string.

Grax32

Posted 2013-10-19T08:13:47.923

Reputation: 1 282