Skip to content

Instantly share code, notes, and snippets.

View zfogg's full-sized avatar
🔐
24BD65F25E5D7311F5FFB2D3EDDAE1DA7360D7F4

Zachary Fogg zfogg

🔐
24BD65F25E5D7311F5FFB2D3EDDAE1DA7360D7F4
View GitHub Profile
@zfogg
zfogg / UnitCircle.cs
Created June 21, 2011 18:52
Unit Circle
using System;
using System.Collections.Generic;
namespace Bounce
{
public class UnitCircle
{
public UnitCircle()
{
pi = Math.PI;
for (int i = 0; i < PhysicalSprites.Count; i++)
{
if (PhysicalSprites[i].IsAlive)
PhysicalSprites[i].Update(gameTime);
else
{
PhysicalSprites[i].Body.Dispose();
PhysicalSprites.RemoveAt(i);
i--;
}
public static List<Body> CreateFraming(World world, int width)
{
List<Body> bodyList = new List<Body>();
float x = WindowSize.X;
float y = WindowSize.Y;
for (float i = 0f; i <= x; i += x)
{
for (float j = 0f; j <= y; j += y)
{
@zfogg
zfogg / pyth_triplets.hs
Created April 5, 2012 03:24
Finding Pythagorean Triplets
import Data.List
import System.Environment
isPythTriplet :: (Integer, Integer, Integer) -> Bool
isPythTriplet (a, b, c) = (a^2) + (b^2) == (c^2)
-- All possible representations of three elements from xs,
-- where let xs[x] = indexof x in xs[a] < xs[b] < xs[c].
triplets :: [Integer] -> [(Integer, Integer, Integer)]
triplets xs = [ (a, b, c) | a:as <- tails xs,
def membersOfType(o, *types):
return dict(
[(m, a)
for m, a in map(lambda x: (x, getattr(o, x)), dir(o))
if any([isinstance(a, t) for t in types])])
Array::toSet = ->
s = {}
s[x] = i for x,i in @
@[v] for k,v of s
@zfogg
zfogg / Primes.java
Created July 30, 2012 05:10
Recursive Prime Sieve Class
public class Primes {
public static void main(String[] args) {
//Print the primes up to 107.
for (Integer p : new RPrimeSieve(107))
System.out.println(p);
}
}
@zfogg
zfogg / birthdayProblem.coffee
Created September 24, 2012 22:28
The answer to 'The Birthday Problem'
randomBirthdays = (n) ->
r = {}
for i in [1..n]
r[Math.floor Math.random() * 364 + 1] = true
k for k,v of r
do ->
n = 23; sum = 0
for i in [0..Math.pow 10, 4]
if n != (randomBirthdays n).length
//Correct way:
window.setInterval(function() {
$.get("/minus/new?folderurl=" + $("#folderurl").val(), function(data) {
$("#progress").html(data);
})
}, 1000);
//You had this:
window.setInterval($.get("/minus/new?folderurl=" + $("#folderurl").val(), function(data) {
qsort1 :: Ord a => [a] -> [a]
qsort1 [] = []
qsort1 (p:xs) = qsort1 lesser ++ [p] ++ qsort1 greater
where
lesser = filter (< p) xs
greater = filter (>= p) xs