Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@wanooknox
wanooknox / FizzBuzzTest.java
Created February 28, 2019 19:10
This is a quick Fizz Buzz exercise I did to teach a high school student the concepts behind TDD. Method naming and code structure could be better, but I just needed to illustrate a point. I felt the exercise went well and I thought it might be worth while to keep the code.
package com.wanooknox.fizzbuzz;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class FizzBuzzTest {
private FizzBuzzEngine fizzBuzzEngine;
@wanooknox
wanooknox / fizzbuzz.js
Created April 23, 2015 18:39
A FizzBuzz paradise. More variants to come.
for (i = 0; i < 100; i++)
{
var test = "";
if (i % 3 == 0) //multiple of 3
{ test += "fizz"; }
if (i % 5 == 0) //multiple of 5
{ test += "buzz"; }
if (test == "") //no multiple
{ test = i; }
document.write(test + "<br \>"); //print

#PAWNED!

######CMPT317 - KIRK MCCULLOCH – 11146754 ######MARCH 4, 2015

##PROBLEM DESCRIPTION Pawned is a simple game based on chess, which is played on a 5 by 6 board. Each player has five pawns (black or white) placed along either the top or bottom rows. Similar to how a pawn moves in chess, in Pawned a pawn can only move forwards, or attack on the left and right diagonals. Additionally, pawns in Pawned cannot move two spaces on their first move, they are restricted to single space moves. The goal of the game is to get one of your pawns to the opponent's side of the board.

In any given turn, players are required to make a move if a valid move is available. If a player cannot move any of their pawns (e.g. all pawns are stuck with an opponent's pawn in the square directly in front), then the player must pass and the turn changes to the opponent. The game ends when one player reaches the opposite side or all pawns on the board are unable to move, in which case the player with the most pawns wins.

@wanooknox
wanooknox / Matrix.cs
Created March 12, 2013 02:50
Recursive matrix determinants by cofactor expansion. Contains Minor, Cofactor, CofactorMatrix, Transpose, Adjoint, and Inverse methods. The corresponding IMatrix, AMatrix, and full Matrix class structure is not mine to post. Structure assumes matrix indexing is 1 based, not 0 based.
public double Minor(int row, int col)
{
//can only calculate a Minor value if the matrix is square
if (this.Rows != this.Cols)
{
throw new ApplicationException("Number of rows does not match number of columns");
}
//the sub matrix
Matrix subMatrix = (Matrix)this.NewMatrix(this.Rows - 1, this.Cols - 1);