C # , 146 ไบต์
ข้อมูล
- อินพุต
Int32[,]
m
เมทริกซ์ที่จะระเบิด
- เอาท์พุท
Int32[,]
เมทริกซ์ที่ระเบิด
แข็งแรงเล่นกอล์ฟ
(int[,] m)=>{int X=m.GetLength(0),Y=m.GetLength(1),x,y;var n=new int[X*2+1,Y*2+1];for(x=0;x<X;x++)for(y=0;y<Y;y++)n[x*2+1,y*2+1]=m[x,y];return n;}
Ungolfed
( int[,] m ) => {
int
X = m.GetLength( 0 ),
Y = m.GetLength( 1 ),
x, y;
var
n = new int[ X * 2 + 1, Y * 2 + 1 ];
for( x = 0; x < X; x++ )
for( y = 0; y < Y; y++ )
n[ x * 2 + 1, y * 2 + 1 ] = m[ x, y ];
return n;
}
อ่านได้ไม่ดี
// Takes an matrix of Int32 objects
( int[,] m ) => {
// To lessen the byte count, store the matrix size
int
X = m.GetLength( 0 ),
Y = m.GetLength( 1 ),
x, y;
// Create the new matrix, with the new size
var
n = new int[ X * 2 + 1, Y * 2 + 1 ];
// Cycle through the matrix, and fill the spots
for( x = 0; x < X; x++ )
for( y = 0; y < Y; y++ )
n[ x * 2 + 1, y * 2 + 1 ] = m[ x, y ];
// Return the exploded matrix
return n;
}
รหัสเต็ม
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestBench {
public static class Program {
private static Func<Int32[,], Int32[,]> f = ( int[,] m ) => {
int
X = m.GetLength( 0 ),
Y = m.GetLength( 1 ),
x, y,
a = X * 2 + 1,
b = Y * 2 + 1;
var
n = new int[ a, b ];
for( x = 0; x < X; x++ )
for( y = 0; y < Y; y++ )
n[ a, b ] = m[ x, y ];
return n;
};
public static Int32[,] Run( Int32[,] matrix ) {
Int32[,]
result = f( matrix );
Console.WriteLine( "Input" );
PrintMatrix( matrix );
Console.WriteLine( "Output" );
PrintMatrix( result );
Console.WriteLine("\n\n");
return result;
}
public static void RunTests() {
Run( new int[,] { { 1 } } );
Run( new int[,] { { 1, 3, 5 } } );
Run( new int[,] { { 1 }, { 3 }, { 5 } } );
Run( new int[,] { { 1, 3, 5 }, { 1, 3, 5 }, { 1, 3, 5 } } );
}
static void Main( string[] args ) {
RunTests();
Console.ReadLine();
}
public static void PrintMatrix<TSource>( TSource[,] array ) {
PrintMatrix( array, o => o.ToString() );
}
public static void PrintMatrix<TSource>( TSource[,] array, Func<TSource, String> valueFetcher ) {
List<String>
output = new List<String>();
for( Int32 xIndex = 0; xIndex < array.GetLength( 0 ); xIndex++ ) {
List<String>
inner = new List<String>();
for( Int32 yIndex = 0; yIndex < array.GetLength( 1 ); yIndex++ ) {
inner.Add( valueFetcher( array[ xIndex, yIndex ] ) );
}
output.Add( $"[ {String.Join( ", ", inner )} ]" );
}
Console.WriteLine( $"[\n {String.Join( ",\n ", output )}\n]" );
}
}
}
ข่าว
- v1.0 -
146 bytes
- โซลูชั่นเริ่มต้น
หมายเหตุ