Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,40 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
|
||||
class Program
|
||||
{
|
||||
static string lookandsay(string number)
|
||||
{
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
char repeat = number[0];
|
||||
number = number.Substring(1, number.Length-1)+" ";
|
||||
int times = 1;
|
||||
|
||||
foreach (char actual in number)
|
||||
{
|
||||
if (actual != repeat)
|
||||
{
|
||||
result.Append(Convert.ToString(times)+repeat);
|
||||
times = 1;
|
||||
repeat = actual;
|
||||
}
|
||||
else
|
||||
{
|
||||
times += 1;
|
||||
}
|
||||
}
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string num = "1";
|
||||
|
||||
foreach (int i in Enumerable.Range(1, 10)) {
|
||||
Console.WriteLine(num);
|
||||
num = lookandsay(num);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace RosettaCode_Cs_LookAndSay
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
Array.Resize<string>(ref args, 2);
|
||||
string ls = args[0] ?? "1";
|
||||
int n;
|
||||
if (!int.TryParse(args[1], out n)) n = 10;
|
||||
do {
|
||||
Console.WriteLine(ls);
|
||||
if (--n <= 0) break;
|
||||
ls = say(look(ls));
|
||||
} while(true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static string[] look(string input)
|
||||
{
|
||||
int i = -1;
|
||||
return Array.FindAll(Regex.Split(input, @"((\d)\2*)"),
|
||||
delegate(string p) { ++i; i %= 3; return i == 1; }
|
||||
);
|
||||
}
|
||||
|
||||
public static string say(string[] groups)
|
||||
{
|
||||
return string.Concat(
|
||||
Array.ConvertAll<string, string>(groups,
|
||||
delegate(string p) { return string.Concat(p.Length, p[0]); }
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue