Skip to content

Instantly share code, notes, and snippets.

View jediwhale's full-sized avatar

Mike Stockdale jediwhale

  • Syterra Software Inc.
View GitHub Profile
@jediwhale
jediwhale / Heapsort.cs
Created April 17, 2019 18:32
Heapsort
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();
@jediwhale
jediwhale / Quicksort.cs
Created April 17, 2019 18:31
Quicksort
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();
[TestFixture]
public class NewtonTest {
[Test]
public void InitialGuessIsCorrect() {
Assert.AreEqual(1.0, Newton.SquareRoot(1.0));
}
[Test]
public void ResultGetsCloseEnough() {
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;
}
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);
}