Skip to content

Commit f43aebc

Browse files
committed
Added "repeated combination" example
1 parent b2653bc commit f43aebc

File tree

6 files changed

+134
-0
lines changed

6 files changed

+134
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"profiles": {
3+
"RepeatedCombination": {
4+
"commandName": "Project",
5+
"commandLineArgs": "> result.txt"
6+
}
7+
}
8+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
namespace RepeatedCombination
7+
{
8+
public class RepeatedCombination
9+
{
10+
public static void Main(string[] args)
11+
{
12+
foreach (var n in Generate(new[] { 0, 1, 2 }, 3))
13+
{
14+
Console.WriteLine(string.Concat(n));
15+
}
16+
}
17+
18+
static IEnumerable<IEnumerable<T>> Generate<T>(IEnumerable<T> elements, int n) => Generate<T>(elements, n, Enumerable.Empty<T>());
19+
20+
static IEnumerable<IEnumerable<T>> Generate<T>(IEnumerable<T> elements, int n, IEnumerable<T> elementBase)
21+
{
22+
if (elementBase.Count() >= n)
23+
{
24+
yield return elementBase;
25+
yield break;
26+
}
27+
28+
foreach (var e in elements)
29+
{
30+
foreach (var item in Generate(elements, n, new List<T>(elementBase) { e }))
31+
{
32+
yield return item;
33+
}
34+
}
35+
}
36+
}
37+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.25420.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "RepeatedCombination", "RepeatedCombination.xproj", "{078A8721-7C71-4C1C-9A45-7E99CC12147C}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{078A8721-7C71-4C1C-9A45-7E99CC12147C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{078A8721-7C71-4C1C-9A45-7E99CC12147C}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{078A8721-7C71-4C1C-9A45-7E99CC12147C}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{078A8721-7C71-4C1C-9A45-7E99CC12147C}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
5+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
6+
</PropertyGroup>
7+
8+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
9+
<PropertyGroup Label="Globals">
10+
<ProjectGuid>078a8721-7c71-4c1c-9a45-7e99cc12147c</ProjectGuid>
11+
<RootNamespace>RepeatedCombination</RootNamespace>
12+
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
13+
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
14+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
15+
</PropertyGroup>
16+
17+
<PropertyGroup>
18+
<SchemaVersion>2.0</SchemaVersion>
19+
</PropertyGroup>
20+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
21+
</Project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"version": "1.0.0-*",
3+
"buildOptions": {
4+
"emitEntryPoint": true
5+
},
6+
7+
"dependencies": {
8+
"Microsoft.NETCore.App": {
9+
"type": "platform",
10+
"version": "1.0.1"
11+
}
12+
},
13+
14+
"frameworks": {
15+
"netcoreapp1.0": {
16+
"imports": "dnxcore50"
17+
}
18+
}
19+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
000
2+
001
3+
002
4+
010
5+
011
6+
012
7+
020
8+
021
9+
022
10+
100
11+
101
12+
102
13+
110
14+
111
15+
112
16+
120
17+
121
18+
122
19+
200
20+
201
21+
202
22+
210
23+
211
24+
212
25+
220
26+
221
27+
222

0 commit comments

Comments
 (0)