Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Power-set/C-sharp/power-set-1.cs
Normal file
20
Task/Power-set/C-sharp/power-set-1.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
public IEnumerable<IEnumerable<T>> GetPowerSet<T>(List<T> list)
|
||||
{
|
||||
return from m in Enumerable.Range(0, 1 << list.Count)
|
||||
select
|
||||
from i in Enumerable.Range(0, list.Count)
|
||||
where (m & (1 << i)) != 0
|
||||
select list[i];
|
||||
}
|
||||
|
||||
public void PowerSetofColors()
|
||||
{
|
||||
var colors = new List<KnownColor> { KnownColor.Red, KnownColor.Green,
|
||||
KnownColor.Blue, KnownColor.Yellow };
|
||||
|
||||
var result = GetPowerSet(colors);
|
||||
|
||||
Console.Write( string.Join( Environment.NewLine,
|
||||
result.Select(subset =>
|
||||
string.Join(",", subset.Select(clr => clr.ToString()).ToArray())).ToArray()));
|
||||
}
|
||||
7
Task/Power-set/C-sharp/power-set-2.cs
Normal file
7
Task/Power-set/C-sharp/power-set-2.cs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
public IEnumerable<IEnumerable<T>> GetPowerSet<T>(IEnumerable<T> input) {
|
||||
var seed = new List<IEnumerable<T>>() { Enumerable.Empty<T>() }
|
||||
as IEnumerable<IEnumerable<T>>;
|
||||
|
||||
return input.Aggregate(seed, (a, b) =>
|
||||
a.Concat(a.Select(x => x.Concat(new List<T>() { b }))));
|
||||
}
|
||||
23
Task/Power-set/C-sharp/power-set-3.cs
Normal file
23
Task/Power-set/C-sharp/power-set-3.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
using System;
|
||||
class Powerset
|
||||
{
|
||||
static int count = 0, n = 4;
|
||||
static int [] buf = new int [n];
|
||||
|
||||
static void Main()
|
||||
{
|
||||
int ind = 0;
|
||||
int n_1 = n - 1;
|
||||
for (;;)
|
||||
{
|
||||
for (int i = 0; i <= ind; ++i) Console.Write("{0, 2}", buf [i]);
|
||||
Console.WriteLine();
|
||||
count++;
|
||||
|
||||
if (buf [ind] < n_1) { ind++; buf [ind] = buf [ind - 1] + 1; }
|
||||
else if (ind > 0) { ind--; buf [ind]++; }
|
||||
else break;
|
||||
}
|
||||
Console.WriteLine("n=" + n + " count=" + count);
|
||||
}
|
||||
}
|
||||
22
Task/Power-set/C-sharp/power-set-4.cs
Normal file
22
Task/Power-set/C-sharp/power-set-4.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
class Powerset
|
||||
{
|
||||
static int n = 4;
|
||||
static int [] buf = new int [n];
|
||||
|
||||
static void Main()
|
||||
{
|
||||
rec(0, 0);
|
||||
}
|
||||
|
||||
static void rec(int ind, int begin)
|
||||
{
|
||||
for (int i = begin; i < n; i++)
|
||||
{
|
||||
buf [ind] = i;
|
||||
for (int j = 0; j <= ind; j++) Console.Write("{0, 2}", buf [j]);
|
||||
Console.WriteLine();
|
||||
rec(ind + 1, buf [ind] + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue