Skip to content

Instantly share code, notes, and snippets.

View BrianMacIntosh's full-sized avatar

Brian MacIntosh BrianMacIntosh

View GitHub Profile
@BrianMacIntosh
BrianMacIntosh / DynamicAckermannFunction.cs
Last active February 14, 2019 19:34
Demo implementation of the Ackermann Function in C# using dynamic programming.
using System;
using System.Threading;
using System.Collections.Generic;
namespace ConsoleApplication1
{
class Program
{
private static int answer;
private static int iterations = 0;
@BrianMacIntosh
BrianMacIntosh / gcd.c
Last active December 29, 2015 07:19
Calculate the GCD (greatest common denominator) of two integers using the Euclidean algorithm. Recursive or iterative functions.
//Helper fn
int pgcdr(int a, int b)
{
if (a) return pgcdr(b % a, a);
else return b;
}
//Recursive gcd fn
int gcdr(int a, int b)
{
@BrianMacIntosh
BrianMacIntosh / RasterLineIterator.cs
Created November 3, 2013 21:37
This class provides a mechanism to iterate through the pixels in a rasterized line. The pixels are returned in order by distance from the point 'start'. The iterator acts like a raycast, not like e.g. Bresenham's line algorithm, in that it returns every pixel intersected by the ray.
using System;
// RasterLineIterator.cs
// 3 November 2013
// Author: Brian MacIntosh
/// <summary>
/// A simple two-dimensional vector. Replace with any 2d vector class.
/// </summary>
class Vector2