Complete The Pattern #1

Complete The Pattern #1

Task:

You have to write a function pattern which creates the following pattern upto n number of rows.

  • If the Argument is 0 or a Negative Integer then it should return ""

Pattern:

1
22
333
....
.....
nnnnnn

Note: There are no spaces in the pattern

Hint: Use \n in string to jump to next line

 

无形装逼最为致命,居然喜欢上用Linq了

using System;
using System.Linq;

public class Kata
{
  public string Pattern(int n)
  {
    // Happy Coding ^_^
     string result = string.Empty;
            if (n > 0)
            {
                result = string.Join(Environment.NewLine, Enumerable.Range(1, n).Select(item => string.Join(string.Empty, Enumerable.Repeat(item, item))));
            }
            return result;
  }
}
时间: 2024-10-12 03:39:02

Complete The Pattern #1的相关文章

Complete The Pattern #6 - Odd Ladder

Complete The Pattern #6 - Odd Ladder Task: You have to write a function pattern which creates the following pattern (see examples) up to the desired number of rows. If the Argument is 0 or a Negative Integer then it should return "" i.e. empty s

Compensating Transaction Pattern(事务修正模式)

Undo the work performed by a series of steps, which together define an eventually consistent operation, if one or more of the steps fail. Operations that follow the eventual consistency model are commonly found in cloud-hosted applications that imple

Circuit Breaker Pattern(断路器模式)

Handle faults that may take a variable amount of time to rectify when connecting to a remote service or resource. This pattern can improve the stability and resiliency of an application.在连接到一个远程服务或资源时,处理故障可能需要一个变量的时间来纠正.这种模式可以提高应用程序的稳定性和弹性. Context a

JavaScript Module Pattern: In-Depth

The module pattern is a common JavaScript coding pattern. It’s generally well understood, but there are a number of advanced uses that have not gotten a lot of attention. In this article, I’ll review the basics and cover some truly remarkable advance

Competing Consumers Pattern (竞争消费者模式)

Enable multiple concurrent consumers to process messages received on the same messaging channel. This pattern enables a system to process multiple messages concurrently to optimize throughput, to improve scalability and availability, and to balance t

Learning JavaScript Design Patterns The Module Pattern

The Module Pattern Modules Modules are an integral piece of any robust application's architecture and typically help in keeping the units of code for a project both cleanly separated and organized. In JavaScript, there are several options for impleme

Class Pattern

java.util.regex Class Pattern java.lang.Object java.util.regex.Pattern All Implemented Interfaces: Serializable public final class Pattern extends Object implements Serializable A compiled representation of a regular expression. A regular expression,

模式识别(Pattern Recognition)书单

Recommended Books Here is a list of books which I have read and feel it is worth recommending to friends who are interested in computer science. Machine Learning Pattern Recognition and Machine Learning Christopher M. Bishop A new treatment of classi

Compute Resource Consolidation Pattern 计算资源整合模式

Consolidate multiple tasks or operations into a single computational unit. This pattern can increase compute resource utilization, and reduce the costs and management overhead associated with performing compute processing in cloud-hosted applications