C # , 204 바이트
골프
(w,g,c,m)=>{string G="\n".PadLeft(++w,'G'),C="\n".PadLeft(w,'C'),M="\n".PadLeft(w,'M'),o="".PadLeft(g,'G');o+="".PadLeft(m,'M')+"".PadLeft(c,'C')+o;return o.Replace("G",G).Replace("C",C).Replace("M",M);};
언 골프
( w, g, c, m ) => {
string
G = "\n".PadLeft( ++w, 'G' ),
C = "\n".PadLeft( w, 'C' ),
M = "\n".PadLeft( w, 'M' ),
o = "".PadLeft( g, 'G' );
o +=
"".PadLeft( m, 'M' ) +
"".PadLeft( c, 'C' ) +
o;
return o
.Replace( "G", G )
.Replace( "C", C )
.Replace( "M", M );
};
언 골프 가능
// Function with 4 parameters
// w : Width
// g : Graham
// c : Chocolate
// m : Marshmallow
( w, g, c, m ) => {
// Initialization of vars with the contents
// of each line, with a new line at the end
string
G = "\n".PadLeft( ++w, 'G' ),
C = "\n".PadLeft( w, 'C' ),
M = "\n".PadLeft( w, 'M' ),
// Trick to reduce the byte count
// Initialize the output with n 'G's
o = "".PadLeft( g, 'G' );
// Add again n 'M's and n 'C's
// Append the 'G's at the end.
o +=
"".PadLeft( m, 'M' ) +
"".PadLeft( c, 'C' ) +
o;
// Replce every instance of 'G'/'C'/'M'
// with the full line
return o
.Replace( "G", G )
.Replace( "C", C )
.Replace( "M", M );
};
전체 코드
using System;
using System.Collections.Generic;
namespace Namespace {
class Program {
static void Main( String[] args ) {
Func<Int32, Int32, Int32, Int32, String> f = ( w, g, c, m ) => {
string
G = "\n".PadLeft( ++w, 'G' ),
C = "\n".PadLeft( w, 'C' ),
M = "\n".PadLeft( w, 'M' ),
o = "".PadLeft( g, 'G' );
o +=
"".PadLeft( m, 'M' ) +
"".PadLeft( c, 'C' ) +
o;
return o
.Replace( "G", G )
.Replace( "C", C )
.Replace( "M", M );
};
List<Tuple<Int32, Int32, Int32, Int32>>
testCases = new List<Tuple<Int32, Int32, Int32, Int32>>() {
new Tuple<Int32, Int32, Int32, Int32>( 1, 1, 1, 1 ),
new Tuple<Int32, Int32, Int32, Int32>( 1, 1, 1, 2 ),
new Tuple<Int32, Int32, Int32, Int32>( 1, 1, 2, 1 ),
//
// ...
//
// The link above contains the code ready to run
// and with every test from the pastebin link
//
// Yes, it contains 342 tests ready to run.
//
// I can barely fit every test on a 1080p screen...
// ... and there's 6 tests per line... Jebus...
//
};
foreach( var testCase in testCases ) {
Console.WriteLine( $"Input:\nWidth: {testCase.Item1,3} Graham: {testCase.Item2,3} Chocolate: {testCase.Item3,3} Marshmellow: {testCase.Item4,3}\nOutput:\n{f( testCase.Item1, testCase.Item2, testCase.Item3, testCase.Item4 )}\n" );
}
Console.ReadLine();
}
}
}
자료
- V1.0 -
204 bytes
- 초기 솔루션입니다.
노트