Skip to content

Instantly share code, notes, and snippets.

View JulianCO's full-sized avatar

Julian C Osorio JulianCO

View GitHub Profile
/* Idiomatic C++11 program that prints the first 20 fibonacci numbers
It uses the standard containers and smart pointers, so this is undeniably good code */
#include <iostream>
#include <utility>
#include <memory>
#include <vector>
template<int n> struct L {public: int h; L<n-1> t;}; template<> struct L<0> {};
@JulianCO
JulianCO / algAss4
Created October 24, 2016 18:20
AlgAss3
Honours Algebra 3 (MATH 456)
=======
Assignment 4
=======
### Julian C. Osorio -- 260 656 525
### Submitted to Prof. Goren on Oct 24, 2016
##Q1
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <stdio.h>
#include "prototypes.h"
#define FITNESS fitness
const char* words[35] =
@JulianCO
JulianCO / Main.elm
Created October 4, 2015 21:42
A guacamole simulator
import Html exposing (..)
import Html.Events exposing (..)
import Html.Attributes as Attr
import StartApp.Simple as StartApp
import Json.Decode as JD
import String exposing (toInt)
import List as L
@JulianCO
JulianCO / decrypt.c
Created February 7, 2015 20:48
Toy RSA implementation. A good excuse to learn GMP.
#include <gmp.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE *cfile, *nfile, *sfile;
mpz_t c, n, s, m;
cfile = fopen("c", "r");
nfile = fopen("n", "r");
@JulianCO
JulianCO / ulam.hs
Created June 21, 2014 00:18
Generates an illustration of the Ulam spiral
import Codec.Picture -- From the package JuicyPixels
height = 300
width = 1200
primes = prune (2:[3,5..])
where
prune (x:xs) = x : (prune $ filter (not . divides x) xs)
divides a b = b `rem` a == 0
@JulianCO
JulianCO / pi.c
Created January 4, 2014 03:17
Estamating pi by using the probability that two random numbers are coprime (6/pi^2)
#include <time.h>
#include <math.h>
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
int gcd(int a, int b) {
@JulianCO
JulianCO / Deriv.hs
Last active January 1, 2016 21:29
Newton fractal generator
module Deriv where
--- Automatic differentiation implementation
data Deriv a = Deriv a a
deriving(Eq, Show)
instance (Num a) => Num (Deriv a) where
(Deriv a a') + (Deriv b b') = Deriv (a + b) (a' + b')
(Deriv a a') - (Deriv b b') = Deriv (a - b) (a' - b')
(Deriv a a') * (Deriv b b') = Deriv (a * b) (a*b' + a'*b)
@JulianCO
JulianCO / fft.hs
Created September 26, 2013 00:57
Cooley–Tukey FFT algorithm, copied more or less verbatim from wikipedia
import Data.Complex
import qualified Data.Vector.Unboxed as V
main = print test
where
test = fourier 0 (\x -> 3.2)
fourier :: Int -> (Int -> Double) -> V.Vector (Complex Double)
fourier 0 xs = V.singleton (xs 0 :+ 0)
fourier power2 xs = V.generate n fourier'
{-# LANGUAGE CPP, TemplateHaskell #-}
-----------------------------------------------------------------------------
--
-- Module : pigLatin
-- Copyright :
-- License : AllRightsReserved
--
-- Maintainer : Yu Chen Hou
-- Stability :
-- Portability :