Skip to content

Update C# files fit the new CSharp repository. Fix import. #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// submitted by Julian Schacher (jspp) with great help by gustorn and Marius Becker
using System.Collections.Generic;

namespace ArcaneAlgorithmArchive.ComputationalMathematics.DecisionProblems.GaleShapley
namespace StableMarriageProblem
{
public static class GaleShapleyAlgorithm<TFollow, TLead>
where TFollow : Person<TFollow, TLead>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;

namespace ArcaneAlgorithmArchive.Extensions
namespace StableMarriageProblem
{
public static class ListExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// submitted by Julian Schacher (jspp) with great help by gustorn and Marius Becker
using System.Collections.Generic;

namespace ArcaneAlgorithmArchive.ComputationalMathematics.DecisionProblems.GaleShapley
namespace StableMarriageProblem
{
public class Person<TSelf, TPref>
where TSelf : Person<TSelf, TPref>
Expand Down
138 changes: 67 additions & 71 deletions chapters/decision_problems/stable_marriage/code/cs/Program.cs
Original file line number Diff line number Diff line change
@@ -1,71 +1,67 @@
// submitted by Julian Schacher (jspp) with great help by gustorn and Marius Becker
using System;
using System.Collections.Generic;
using ArcaneAlgorithmArchive.ComputationalMathematics.DecisionProblems.GaleShapley;
using ArcaneAlgorithmArchive.Extensions;

namespace ArcaneAlgorithmArchiveCLI
{
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine("GaleShapley");
// Using men and women as an example.
var men = new List<Man>()
{
new Man("A"),
new Man("B"),
new Man("C"),
new Man("D"),
new Man("E")
};
var women = new List<Woman>()
{
new Woman("F"),
new Woman("G"),
new Woman("H"),
new Woman("I"),
new Woman("J"),
};

var random = new Random();

foreach (var man in men)
{
man.Choices = new List<Woman>(women).Shuffle(random);
Console.WriteLine(man.Name + ":");
foreach (var choice in man.Choices)
Console.Write(choice.Name);
Console.WriteLine();
}
foreach (var woman in women)
{
woman.Choices = new List<Man>(men).Shuffle(random);
Console.WriteLine(woman.Name + ":");
foreach (var choice in woman.Choices)
Console.Write(choice.Name);
Console.WriteLine();
}

GaleShapleyAlgorithm<Woman, Man>.RunGaleShapleyAlgorithm(women, men);

foreach (var woman in women)
{
Console.WriteLine(woman.Name + " : " + woman?.Partner.Name);
}
Console.WriteLine();
}
}

// for GaleShapley
public class Man : Person<Man, Woman>
{
public Man(string name) : base(name) { }
}

public class Woman : Person<Woman, Man>
{
public Woman(string name) : base(name) { }
}
}
// submitted by Julian Schacher (jspp) with great help by gustorn and Marius Becker
using System;
using System.Collections.Generic;

namespace StableMarriageProblem
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("GaleShapleyAlgorithm");
// Using men and women as an example.
var men = new List<Man>()
{
new Man("A"),
new Man("B"),
new Man("C"),
new Man("D"),
new Man("E")
};
var women = new List<Woman>()
{
new Woman("F"),
new Woman("G"),
new Woman("H"),
new Woman("I"),
new Woman("J"),
};

var random = new Random();

foreach (var man in men)
{
man.Choices = new List<Woman>(women).Shuffle(random);
Console.WriteLine(man.Name + ":");
foreach (var choice in man.Choices)
Console.Write(choice.Name);
Console.WriteLine();
}
foreach (var woman in women)
{
woman.Choices = new List<Man>(men).Shuffle(random);
Console.WriteLine(woman.Name + ":");
foreach (var choice in woman.Choices)
Console.Write(choice.Name);
Console.WriteLine();
}

GaleShapleyAlgorithm<Woman, Man>.RunGaleShapleyAlgorithm(women, men);

foreach (var woman in women)
{
Console.WriteLine(woman.Name + " : " + woman?.Partner.Name);
}
}
}

public class Man : Person<Man, Woman>
{
public Man(string name) : base(name) { }
}

public class Woman : Person<Woman, Man>
{
public Woman(string name) : base(name) { }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
// submitted by Julian Schacher (jspp)
using System;

namespace ArcaneAlgorithmArchive.FundamentalAlgorithms.EuclideanAlgorithm
namespace EuclideanAlgorithm
{
public static class EuclideanAlgorithm
{
Expand Down
18 changes: 18 additions & 0 deletions chapters/euclidean_algorithm/code/cs/EuclideanAlgorithm/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// submitted by Julian Schacher (jspp)
using System;

namespace EuclideanAlgorithm
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("EuclideanAlgorithm");
int check = EuclideanAlgorithm.EuclidMod(64 * 67, 64 * 81);
int check2 = EuclideanAlgorithm.EuclidSub(128 * 12, 128 * 77);

Console.WriteLine(check);
Console.WriteLine(check2);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// submitted by Julian Schacher (jspp)
namespace ArcaneAlgorithmArchive.FundamentalAlgorithms.EuclideanAlgorithm
namespace EuclideanAlgorithmMdAdditional
{
public class EuclideanAlgorithmMdAdditional
{
Expand Down Expand Up @@ -28,15 +28,4 @@ public static int EuclidMod(int a, int b)
return a;
}
}
class MainClass
{
public static void Main(string[] args)
{
int check = EuclideanAlgorithm.EuclidMod(64 * 67, 64 * 81);
int check2 = EuclideanAlgorithm.EuclidSub(128 * 12, 128 * 77);

Console.WriteLine(check);
Console.WriteLine(check2);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// submitted by Julian Schacher (jspp)
using System;

namespace EuclideanAlgorithmMdAdditional
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("EuclideanAlgorithmMdAdditional");
int checkMdAdditional = EuclideanAlgorithmMdAdditional.EuclidMod(64 * 67, 64 * 81);
int checkMdAdditional2 = EuclideanAlgorithmMdAdditional.EuclidSub(128 * 12, 128 * 77);

Console.WriteLine(checkMdAdditional);
Console.WriteLine(checkMdAdditional2);
}
}
}
9 changes: 6 additions & 3 deletions chapters/euclidean_algorithm/euclidean.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ The algorithm is a simple way to find the *greatest common divisor* (GCD) of two
{% sample lang="c" %}
[import:18-33, lang="c_cpp"](code/c/euclidean_example.c)
{% sample lang="cs" %}
[import:6-17, lang="csharp"](code/cs/EuclideanAlgorithmMdAdditional.cs)
[import:6-17, lang="csharp"](code/cs/EuclideanAlgorithmMdAdditional/EuclideanAlgorithmMdAdditional.cs)
{% sample lang="clj" %}
[import:1-7, lang="clojure"](code/clojure/euclidean_example.clj)
{% sample lang="cpp" %}
Expand Down Expand Up @@ -60,7 +60,7 @@ Modern implementations, though, often use the modulus operator (%) like so
{% sample lang="c" %}
[import:4-16, lang="c_cpp"](code/c/euclidean_example.c)
{% sample lang="cs" %}
[import:19-29, lang="csharp"](code/cs/EuclideanAlgorithmMdAdditional.cs)
[import:19-29, lang="csharp"](code/cs/EuclideanAlgorithmMdAdditional/EuclideanAlgorithmMdAdditional.cs)
{% sample lang="clj" %}
[import:8-12, lang="clojure"](code/clojure/euclidean_example.clj)
{% sample lang="cpp" %}
Expand Down Expand Up @@ -93,7 +93,10 @@ The Euclidean Algorithm is truly fundamental to many other algorithms throughout
[import, lang="c_cpp"](code/c/euclidean_example.c)
{% sample lang="cs" %}
### C# #
[import, lang="csharp"](code/cs/EuclideanAlgorithmMdAdditional.cs)
EuclideanAlgorithm.cs
[import, lang="csharp"](code/cs/EuclideanAlgorithm/EuclideanAlgorithm.cs)
Program.cs
[import, lang="csharp"](code/cs/EuclideanAlgorithm/Program.cs)
{% sample lang="clj" %}
### Clojure
[import, lang="clojure"](code/clojure/euclidean_example.clj)
Expand Down
2 changes: 1 addition & 1 deletion chapters/sorting_searching/bogo/bogo_sort.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function bogo_sort(Vector{Type} a)
end
```
{% sample lang="cs" %}
[import:29-35, lang:"csharp"](code/cs/bogo.cs)
[import:9-15, lang:"csharp"](code/cs/BogoSort.cs)
{% sample lang="clj" %}
[import:6-10, lang:"clojure"](code/clojure/bogo.clj)
{% endmethod %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,11 @@
using System;
using System.Collections.Generic;

namespace ArcaneAlgorithmArchive.FundamentalAlgorithms.SortingSearching
namespace BogoSort
{
public static class Sorting
public static class BogoSort
{
public static List<T> BubbleSort<T>(List<T> list) where T : IComparable<T>
{
var length = list.Count;

for (int i = 0; i < length; i++)
{
for (int j = 1; j < length; j++)
{
if (list[j - 1].CompareTo(list[j]) > 0)
{
var temp = list[j - 1];
list[j - 1] = list[j];
list[j] = temp;
}
}
}

return list;
}

public static List<T> BogoSort<T>(List<T> list) where T : IComparable<T>
public static List<T> RunBogoSort<T>(List<T> list) where T : IComparable<T>
{
while (!IsSorted(list))
list = Shuffle(list, new Random());
Expand Down
24 changes: 24 additions & 0 deletions chapters/sorting_searching/bogo/code/cs/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// submitted by Julian Schacher (jspp)
using System;
using System.Collections.Generic;

namespace BogoSort
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("BogoSort");
var listBogo = new List<int>() { 1, 2, 6, 4, 9, 54, 3, 2, 7, 15 };
Console.Write("unsorted: ");
foreach (var number in listBogo)
Console.Write(number + " ");
Console.WriteLine();
listBogo = BogoSort.RunBogoSort(listBogo);
Console.Write("sorted: ");
foreach (var number in listBogo)
Console.Write(number + " ");
Console.WriteLine();
}
}
}
2 changes: 1 addition & 1 deletion chapters/sorting_searching/bubble/bubble_sort.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function bubble_sort(Vector{Type} a)
end
```
{% sample lang="cs" %}
[import:9-27, lang:"csharp"](code/cs/Sorting.cs)
[import:9-27, lang:"csharp"](code/cs/BubbleSort.cs)
{% endmethod %}

... And that's it for the simplest bubble sort method.
Expand Down
29 changes: 29 additions & 0 deletions chapters/sorting_searching/bubble/code/cs/BubbleSort.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// submitted by Julian Schacher (jspp)
using System;
using System.Collections.Generic;

namespace BubbleSort
{
public static class BubbleSort
{
public static List<T> RunBubbleSort<T>(List<T> list) where T : IComparable<T>
{
var length = list.Count;

for (int i = 0; i < length; i++)
{
for (int j = 1; j < length; j++)
{
if (list[j - 1].CompareTo(list[j]) > 0)
{
var temp = list[j - 1];
list[j - 1] = list[j];
list[j] = temp;
}
}
}

return list;
}
}
}
24 changes: 24 additions & 0 deletions chapters/sorting_searching/bubble/code/cs/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// submitted by Julian Schacher (jspp)
using System;
using System.Collections.Generic;

namespace BubbleSort
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("BubbleSort");
var listBubble = new List<int>() { 1, 2, 6, 4, 9, 54, 3, 2, 7, 15 };
Console.Write("unsorted: ");
foreach (var number in listBubble)
Console.Write(number + " ");
Console.WriteLine();
listBubble = BubbleSort.RunBubbleSort(listBubble);
Console.Write("sorted: ");
foreach (var number in listBubble)
Console.Write(number + " ");
Console.WriteLine();
}
}
}
Loading