Skip to content

Instantly share code, notes, and snippets.

View jfacoustic's full-sized avatar

Josh Mathews jfacoustic

View GitHub Profile
@jfacoustic
jfacoustic / interestCalculator.clj
Created January 1, 2020 19:16
Calculates interest in clojure
(defn calculate-interest
[apy base deposit months]
(if (= months 0)
( + base (* base apy))
(do (def newBase (+ base deposit))
(if (= (mod months 12) 0)
(calculate-interest apy (+ newBase (* newBase apy)) deposit (dec months))
(calculate-interest apy newBase deposit (dec months))))))
@jfacoustic
jfacoustic / vec_op.cu
Created December 22, 2019 17:32
Function Ptr Cuda Kernel
// CUDA function ptr example
// For basic vector operations
// Based on Chapter 2 of Programming Massively Parallel Processors 3rd Edition Kirk & Hwu
#include <stdio.h>
#include <cuda.h>
__global__ void addKernel(float * a, float * b, float * c, int n) {
int i = blockDim.x * blockIdx.x + threadIdx.x;
if(i < n) {
@jfacoustic
jfacoustic / fibonacci.cpp
Last active July 3, 2017 02:19
Fibonacci with GMPXX; dynamic and traditional implimentations
#include <iostream>
#include <vector>
#include <ctime>
#include <gmpxx.h>
using namespace std;
mpz_class fibNorm(int n) {
if (n <= 1 ) return n;
return fibNorm(n-1) + fibNorm(n-2);
}
@jfacoustic
jfacoustic / mandelbrot.cu
Last active October 10, 2016 03:32
Mandelbrot Set calculated with CUDA: using resources from CUDA by Example at https://developer.nvidia.com/cuda-example
#include "../common/book.h"
#include "../common/cpu_bitmap.h"
#define DIM 1000
//From Wikipedia's article on the Mandelbrot Set:
__device__ int mandelbrot( int xa, int ya, float s, float xpos, float ypos) {
float x0 = s * (float) (DIM/2 -xa)/((float)DIM/2) + xpos;
float y0 = s * (float)(DIM/2 -ya )/((float)DIM/2) + ypos;
int m = 0;
@jfacoustic
jfacoustic / sphere.cpp
Created September 29, 2016 02:11
Creates a vertex array to draw a sphere in OpenGL
#include <vector>
#include <cmath>
struct vec3 {
float x, y, z;
void set(float X, float Y, float Z)
{
x = X;
y = Y;
z = Z;