Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,39 @@
using System;
using System.Collections;
namespace RosettaCode {
class SierpinskiTriangle {
int len;
BitArray b;
public SierpinskiTriangle(int n) {
if (n < 1) {
throw new ArgumentOutOfRangeException("Order must be greater than zero");
}
len = 1 << (n+1);
b = new BitArray(len+1, false);
b[len>>1] = true;
}
public void Display() {
for (int j = 0; j < len / 2; j++) {
for (int i = 0; i < b.Count; i++) {
Console.Write("{0}", b[i] ? "*" : " ");
}
Console.WriteLine();
NextGen();
}
}
private void NextGen() {
BitArray next = new BitArray(b.Count, false);
for (int i = 0; i < b.Count; i++) {
if (b[i]) {
next[i - 1] = next[i - 1] ^ true;
next[i + 1] = next[i + 1] ^ true;
}
}
b = next;
}
}
}

View file

@ -0,0 +1,8 @@
namespace RosettaCode {
class Program {
static void Main(string[] args) {
SierpinskiTriangle t = new SierpinskiTriangle(4);
t.Display();
}
}
}

View file

@ -0,0 +1,16 @@
using static System.Console;
class Sierpinsky
{
static void Main(string[] args)
{
int order;
if(!int.TryParse(args.Length > 0 ? args[0] : "", out order)) order = 4;
int size = (1 << order);
for (int y = size - 1; y >= 0; y--, WriteLine())
{
for (int i = 0; i < y; i++) Write(' ');
for (int x = 0; x + y < size; x++)
Write((x & y) != 0 ? " " : "* ");
}
}
}

View file

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
public static List<String> Sierpinski(int n)
{
var lines = new List<string> { "*" };
string space = " ";
for (int i = 0; i < n; i++)
{
lines = lines.Select(x => space + x + space)
.Concat(lines.Select(x => x + " " + x)).ToList();
space += space;
}
return lines;
}
static void Main(string[] args)
{
foreach (string s in Sierpinski(4))
Console.WriteLine(s);
}
}

View file

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static List<string> Sierpinski(int n)
{
return Enumerable.Range(0, n).Aggregate(
new List<string>(){"*"},
(p, i) => {
string SPACE = " ".PadRight((int)Math.Pow(2, i));
var temp = new List<string>(from x in p select SPACE + x + SPACE);
temp.AddRange(from x in p select x + " " + x);
return temp;
}
);
}
static void Main ()
{
foreach(string s in Sierpinski(4)) { Console.WriteLine(s); }
}
}