This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace HeapSort { | |
public static class Program { | |
static void Main(string[] args) { | |
int[] data = {3, 7, 1, 5, 9, 2}; | |
Sort(data); | |
foreach (var i in data) Console.Write(i + " "); | |
Console.WriteLine(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace QuickSort { | |
public static class Program { | |
public static void Main(string[] args) { | |
int[] data = {3, 7, 1, 5, 9, 2}; | |
Sort(data); | |
foreach (var i in data) Console.Write(i + " "); | |
Console.WriteLine(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestFixture] | |
public class NewtonTest { | |
[Test] | |
public void InitialGuessIsCorrect() { | |
Assert.AreEqual(1.0, Newton.SquareRoot(1.0)); | |
} | |
[Test] | |
public void ResultGetsCloseEnough() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Newton { | |
public static double SquareRoot(double input) { | |
if (input < 0.0) throw new ArgumentOutOfRangeException(); | |
if (input == 0.0) return input; | |
var guess = 1.0; | |
while (true) { | |
var newGuess = CalculateNewGuess(input, guess); | |
if (CloseEnough(guess, newGuess)) return newGuess; | |
guess = newGuess; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PiSymbolType extends SymbolType implements Translation { | |
public PiSymbolType () { | |
super("Pi"); | |
wikiMatcher(new Matcher().string("!pi")); | |
htmlTranslation(this); | |
} | |
public String toTarget(Translator translator, Symbol symbol) { | |
return Double.toString(Math.PI); | |
} |