Skip to main content
Fixed to conform to rules.
Source Link

MATLAB 175175 193

R2014a

Fun with fprintf. I hope I didn't miscount, first timer here.

a='e a = 'a time ';b='teen';b = 'teen-hundreds wer%1$sforwere ';for%sfor';for i=1i = length([]):length(b);fprintf(['The eigh',b,'rum' rum.\nThe nine',b,'fun' fun.\nThe two-thousands ar%1$stoare %sto run\na civilized classroom.\n'],a,a,a);end

Ungolfed

a = 'e a'a time ';
b = 'teen-hundreds wer%1$sforwere ';%sfor';
for i = 1length([]):length(b);
    fprintf( 
        [ 
            'The eigh',
            b,
            'rum' rum.\nThe nine',
            b,
            'fun' fun.\nThe two-thousands ar%1$stoare %sto run\na civilized classroom.\n'
        ],
        a,
        a,
        a
    );
end

Note that fprintf prints to MATLAB's console by default, unless a valid file identifier is supplied as the first argument. The character sequence %1$s instructs fprintfThe character sequence %1$s instructs fprintf to print the first argument after the format string as a string. In this case, the variable b needs to be 25 characters long, so using %s instead of %1$s actually costs a couple more characters overall, once all strings have been manipulated.

Edit: fixed to print the first argument after the format string as a string. In this case, the variable b needsconform to be 25 characters long, so using %s instead of %1$s actually costs a couple more characters overall, once all strings have been manipulatedrules. Lesson learned: don't post early morning.

MATLAB 175

R2014a

Fun with fprintf. I hope I didn't miscount, first timer here.

a='e a time ';b='teen-hundreds wer%1$sfor ';for i=1:length(b);fprintf(['The eigh',b,'rum.\nThe nine',b,'fun.\nThe two-thousands ar%1$sto run\na civilized classroom.\n'],a);end

Ungolfed

a = 'e a time ';
b = 'teen-hundreds wer%1$sfor ';
for i = 1:length(b);
    fprintf( 
        [ 
            'The eigh',
            b,
            'rum.\nThe nine',
            b,
            'fun.\nThe two-thousands ar%1$sto run\na civilized classroom.\n'
        ],
        a
    );
end

Note that fprintf prints to MATLAB's console by default, unless a valid file identifier is supplied as the first argument. The character sequence %1$s instructs fprintf to print the first argument after the format string as a string. In this case, the variable b needs to be 25 characters long, so using %s instead of %1$s actually costs a couple more characters overall, once all strings have been manipulated.

MATLAB 175 193

R2014a

Fun with fprintf. I hope I didn't miscount, first timer here.

a = 'a time ';b = 'teen-hundreds were %sfor';for i = length([]):length(b);fprintf(['The eigh',b,' rum.\nThe nine',b,' fun.\nThe two-thousands are %sto run\na civilized classroom.\n'],a,a,a);end

Ungolfed

a = 'a time ';
b = 'teen-hundreds were %sfor';
for i = length([]):length(b);
    fprintf(
        [
            'The eigh',
            b,
            ' rum.\nThe nine',
            b,
            ' fun.\nThe two-thousands are %sto run\na civilized classroom.\n'
        ],
        a,
        a,
        a
    );
end

Note that fprintf prints to MATLAB's console by default, unless a valid file identifier is supplied as the first argument. The character sequence %1$s instructs fprintf to print the first argument after the format string as a string. In this case, the variable b needs to be 25 characters long, so using %s instead of %1$s actually costs a couple more characters overall, once all strings have been manipulated.

Edit: fixed to conform to rules. Lesson learned: don't post early morning.

Source Link

MATLAB 175

R2014a

Fun with fprintf. I hope I didn't miscount, first timer here.

a='e a time ';b='teen-hundreds wer%1$sfor ';for i=1:length(b);fprintf(['The eigh',b,'rum.\nThe nine',b,'fun.\nThe two-thousands ar%1$sto run\na civilized classroom.\n'],a);end

Ungolfed

a = 'e a time ';
b = 'teen-hundreds wer%1$sfor ';
for i = 1:length(b);
    fprintf( 
        [ 
            'The eigh',
            b,
            'rum.\nThe nine',
            b,
            'fun.\nThe two-thousands ar%1$sto run\na civilized classroom.\n'
        ],
        a
    );
end

Note that fprintf prints to MATLAB's console by default, unless a valid file identifier is supplied as the first argument. The character sequence %1$s instructs fprintf to print the first argument after the format string as a string. In this case, the variable b needs to be 25 characters long, so using %s instead of %1$s actually costs a couple more characters overall, once all strings have been manipulated.