Skip to main content
Commonmark migration
Source Link

MATL, 12 bytes

tnEXyPY+c!Us

Input is a string. Try it online!

###Explanation

Explanation

Consider input '123' as an example.

The code duplicates the input (t) and builds an identity matrix (Xy) of size twice the input length (nE):

1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0
0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1

then flips it upside down (P):

0 0 0 0 0 1
0 0 0 0 1 0
0 0 0 1 0 0
0 0 1 0 0 0
0 1 0 0 0 0
1 0 0 0 0 0

The input string, interpreted as ASCII codes of the digits, is equivalent to the numeric row vector

49 50 51

Full-size two-dimensional convolution (Y+) of the above vector and matrix gives

 0  0  0  0  0 49 50 51
 0  0  0  0 49 50 51  0
 0  0  0 49 50 51  0  0
 0  0 49 50 51  0  0  0
 0 49 50 51  0  0  0  0
49 50 51  0  0  0  0  0

Interpreting those numbers back as ASCII codes (c) gives the following char matrix, with char 0 represented as space:

     123
    123 
   123  
  123   
 123    
123

Transposition (!) transforms this into

     1
    12
   123
  123 
 123  
123   
23    
3     

Interpreting each row as a number (U) gives the numeric column vector

  1
 12
123
123
123
123
 23
  3

and summing it (s) gives the final result, 531.

MATL, 12 bytes

tnEXyPY+c!Us

Input is a string. Try it online!

###Explanation

Consider input '123' as an example.

The code duplicates the input (t) and builds an identity matrix (Xy) of size twice the input length (nE):

1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0
0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1

then flips it upside down (P):

0 0 0 0 0 1
0 0 0 0 1 0
0 0 0 1 0 0
0 0 1 0 0 0
0 1 0 0 0 0
1 0 0 0 0 0

The input string, interpreted as ASCII codes of the digits, is equivalent to the numeric row vector

49 50 51

Full-size two-dimensional convolution (Y+) of the above vector and matrix gives

 0  0  0  0  0 49 50 51
 0  0  0  0 49 50 51  0
 0  0  0 49 50 51  0  0
 0  0 49 50 51  0  0  0
 0 49 50 51  0  0  0  0
49 50 51  0  0  0  0  0

Interpreting those numbers back as ASCII codes (c) gives the following char matrix, with char 0 represented as space:

     123
    123 
   123  
  123   
 123    
123

Transposition (!) transforms this into

     1
    12
   123
  123 
 123  
123   
23    
3     

Interpreting each row as a number (U) gives the numeric column vector

  1
 12
123
123
123
123
 23
  3

and summing it (s) gives the final result, 531.

MATL, 12 bytes

tnEXyPY+c!Us

Input is a string. Try it online!

Explanation

Consider input '123' as an example.

The code duplicates the input (t) and builds an identity matrix (Xy) of size twice the input length (nE):

1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0
0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1

then flips it upside down (P):

0 0 0 0 0 1
0 0 0 0 1 0
0 0 0 1 0 0
0 0 1 0 0 0
0 1 0 0 0 0
1 0 0 0 0 0

The input string, interpreted as ASCII codes of the digits, is equivalent to the numeric row vector

49 50 51

Full-size two-dimensional convolution (Y+) of the above vector and matrix gives

 0  0  0  0  0 49 50 51
 0  0  0  0 49 50 51  0
 0  0  0 49 50 51  0  0
 0  0 49 50 51  0  0  0
 0 49 50 51  0  0  0  0
49 50 51  0  0  0  0  0

Interpreting those numbers back as ASCII codes (c) gives the following char matrix, with char 0 represented as space:

     123
    123 
   123  
  123   
 123    
123

Transposition (!) transforms this into

     1
    12
   123
  123 
 123  
123   
23    
3     

Interpreting each row as a number (U) gives the numeric column vector

  1
 12
123
123
123
123
 23
  3

and summing it (s) gives the final result, 531.

added 5 characters in body
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372

MATL, 12 bytes

tnEXyPY+c!Us

Input is a string.

   Try it online!

###Explanation

Consider input '123' as an example.

The code duplicates the input (t) and builds an identity matrix (Xy) of size twice the input length (nE):

1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0
0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1

then flips it upside down (P):

0 0 0 0 0 1
0 0 0 0 1 0
0 0 0 1 0 0
0 0 1 0 0 0
0 1 0 0 0 0
1 0 0 0 0 0

The input string, interpreted as ASCII codes of the digits, is equivalent to the numeric row vector

49 50 51

TwoFull-size two-dimensional convolution (Y+) of the above matrix and vector and matrix gives

 0  0  0  0  0 49 50 51
 0  0  0  0 49 50 51  0
 0  0  0 49 50 51  0  0
 0  0 49 50 51  0  0  0
 0 49 50 51  0  0  0  0
49 50 51  0  0  0  0  0

Interpreting those numbers back as ASCII codes (c) gives the following char matrix, with char 0 represented as space:

     123
    123 
   123  
  123   
 123    
123

Transposition (!) transforms this into

     1
    12
   123
  123 
 123  
123   
23    
3     

Interpreting each row as a number (U) gives the numeric column vector

  1
 12
123
123
123
123
 23
  3

and summing it (s) gives the final result, 531.

MATL, 12 bytes

tnEXyPY+c!Us

Input is a string.

 Try it online!

###Explanation

Consider input '123' as an example.

The code duplicates the input (t) and builds an identity matrix (Xy) of size twice the input length (nE):

1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0
0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1

then flips it upside down (P):

0 0 0 0 0 1
0 0 0 0 1 0
0 0 0 1 0 0
0 0 1 0 0 0
0 1 0 0 0 0
1 0 0 0 0 0

The input string, interpreted as ASCII codes of the digits, is equivalent to the numeric row vector

49 50 51

Two-dimensional convolution (Y+) of the above matrix and vector gives

 0  0  0  0  0 49 50 51
 0  0  0  0 49 50 51  0
 0  0  0 49 50 51  0  0
 0  0 49 50 51  0  0  0
 0 49 50 51  0  0  0  0
49 50 51  0  0  0  0  0

Interpreting those numbers back as ASCII codes (c) gives the following char matrix, with char 0 represented as space:

     123
    123 
   123  
  123   
 123    
123

Transposition (!) transforms this into

     1
    12
   123
  123 
 123  
123   
23    
3     

Interpreting each row as a number (U) gives the numeric column vector

  1
 12
123
123
123
123
 23
  3

and summing it (s) gives the final result, 531.

MATL, 12 bytes

tnEXyPY+c!Us

Input is a string.  Try it online!

###Explanation

Consider input '123' as an example.

The code duplicates the input (t) and builds an identity matrix (Xy) of size twice the input length (nE):

1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0
0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1

then flips it upside down (P):

0 0 0 0 0 1
0 0 0 0 1 0
0 0 0 1 0 0
0 0 1 0 0 0
0 1 0 0 0 0
1 0 0 0 0 0

The input string, interpreted as ASCII codes of the digits, is equivalent to the numeric row vector

49 50 51

Full-size two-dimensional convolution (Y+) of the above vector and matrix gives

 0  0  0  0  0 49 50 51
 0  0  0  0 49 50 51  0
 0  0  0 49 50 51  0  0
 0  0 49 50 51  0  0  0
 0 49 50 51  0  0  0  0
49 50 51  0  0  0  0  0

Interpreting those numbers back as ASCII codes (c) gives the following char matrix, with char 0 represented as space:

     123
    123 
   123  
  123   
 123    
123

Transposition (!) transforms this into

     1
    12
   123
  123 
 123  
123   
23    
3     

Interpreting each row as a number (U) gives the numeric column vector

  1
 12
123
123
123
123
 23
  3

and summing it (s) gives the final result, 531.

added 1260 characters in body
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372

MATL, 12 bytes

tnEXyPY+c!Us

Input is a string.

Try it online!Try it online!

###Explanation

Consider input '123' as an example.

The code duplicates the input (t) and builds an identity matrix (Xy) of size twice the input length (nE):

1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0
0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1

then flips it upside down (P):

0 0 0 0 0 1
0 0 0 0 1 0
0 0 0 1 0 0
0 0 1 0 0 0
0 1 0 0 0 0
1 0 0 0 0 0

The input string, interpreted as ASCII codes of the digits, is equivalent to the numeric row vector

49 50 51

Two-dimensional convolution (Y+) of the above matrix and vector gives

 0  0  0  0  0 49 50 51
 0  0  0  0 49 50 51  0
 0  0  0 49 50 51  0  0
 0  0 49 50 51  0  0  0
 0 49 50 51  0  0  0  0
49 50 51  0  0  0  0  0

Interpreting those numbers back as ASCII codes (c) gives the following char matrix, with char 0 represented as space:

     123
    123 
   123  
  123   
 123    
123

Transposition (!) transforms this into

     1
    12
   123
  123 
 123  
123   
23    
3     

Interpreting each row as a number (U) gives the numeric column vector

  1
 12
123
123
123
123
 23
  3

and summing it (s) gives the final result, 531.

MATL, 12 bytes

tnEXyPY+c!Us

Input is a string.

Try it online!

MATL, 12 bytes

tnEXyPY+c!Us

Input is a string.

Try it online!

###Explanation

Consider input '123' as an example.

The code duplicates the input (t) and builds an identity matrix (Xy) of size twice the input length (nE):

1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0
0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1

then flips it upside down (P):

0 0 0 0 0 1
0 0 0 0 1 0
0 0 0 1 0 0
0 0 1 0 0 0
0 1 0 0 0 0
1 0 0 0 0 0

The input string, interpreted as ASCII codes of the digits, is equivalent to the numeric row vector

49 50 51

Two-dimensional convolution (Y+) of the above matrix and vector gives

 0  0  0  0  0 49 50 51
 0  0  0  0 49 50 51  0
 0  0  0 49 50 51  0  0
 0  0 49 50 51  0  0  0
 0 49 50 51  0  0  0  0
49 50 51  0  0  0  0  0

Interpreting those numbers back as ASCII codes (c) gives the following char matrix, with char 0 represented as space:

     123
    123 
   123  
  123   
 123    
123

Transposition (!) transforms this into

     1
    12
   123
  123 
 123  
123   
23    
3     

Interpreting each row as a number (U) gives the numeric column vector

  1
 12
123
123
123
123
 23
  3

and summing it (s) gives the final result, 531.

Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372
Loading