Skip to content

Instantly share code, notes, and snippets.

View Shamrock-Frost's full-sized avatar
🐻

Brendan Seamas Murphy Shamrock-Frost

🐻
View GitHub Profile
newtype Doggo = BigOl Pupper
newtype Pupper = Tiny Doggo
@Shamrock-Frost
Shamrock-Frost / map.hs
Created November 3, 2016 05:37
Recursion in haskell
data List a = Nil | Cons a (List a)
map :: (a -> b) -> List a -> List b
map f Nil = Nil
map f (Cons x xs) = Cons (f x) (map f xs)
@Shamrock-Frost
Shamrock-Frost / Sierpinski.hs
Last active November 12, 2016 09:58
A functional Sierpinski triangle
{-# LANGUAGE DeriveFunctor, DeriveFoldable, PatternSynonyms #-}
import Graphics.Gloss (animate, Display(InWindow), white, Picture(Polygon))
import Data.Bifunctor (bimap)
import Data.Monoid ((<>))
import Data.Foldable (fold)
data TriTree a = Branch (TriTree a) (TriTree a) (TriTree a) | Leaf a deriving (Functor, Foldable)
instance Applicative TriTree where
@Shamrock-Frost
Shamrock-Frost / Integral.hs
Created November 17, 2016 16:27
Hackerrank solution
{-# LANGUAGE ConstraintKinds, DeriveFunctor #-}
import Text.Printf (printf)
import Data.Foldable (fold)
import Data.Bifunctor (bimap)
import Data.Monoid ((<>))
type PolynomialAble pow num = (Integral pow, Floating num)
data Monomial pow = Ln | ToThe pow deriving (Functor, Eq, Show)
@Shamrock-Frost
Shamrock-Frost / CList.hs
Created December 30, 2016 18:10
A constraint-indexed heterogeneous list type. N. B. I'm 100% sure this has been done before
{-# LANGUAGE GADTs, ConstraintKinds, KindSignatures #-}
module CList (CList(..)) where
import GHC.Exts (Constraint)
infixr 9 `Cons`
data CList :: (* -> Constraint) -> * where
Nil :: CList k
Cons :: k x => x -> CList k -> CList k
@Shamrock-Frost
Shamrock-Frost / define-test
Last active January 24, 2017 20:33
Broken Define
#lang s-exp "./stlc-core.rkt"
(define x : Nat 5)
(S x)
public static String repeat(String orig, int n) throws IllegalArgumentException {
if(n < 0) throw new IllegalArgumentException("Argument was negative");
else if(n == 0) return "";
else if(n == 1) return orig; // this removes the need for 2 unneeded concatenations
else if(n % 2 == 0) return repeat(orig + orig, n / 2);
else return orig + repeat(orig + orig, n / 2);
}
public static int mystery6(int n, int k) {
if(n == k || k == 0) return 1;
return mystery6(n-1,k-1) + mystery6(n-1,k);
}
@Shamrock-Frost
Shamrock-Frost / pink-bliss-theme.el
Created March 29, 2017 04:36
Slightly modified pink bliss
;;; pink-bliss.el --- a pink color theme for Emacs
;; Copyright (C) 2005–2015 Alex Schroeder <[email protected]>
;; This file is not part of GNU Emacs.
;; This is free software; you can redistribute it and/or modify it under
;; the terms of the GNU General Public License as published by the Free
;; Software Foundation; either version 2, or (at your option) any later
;; version.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define TRIALS 10000000
// double in range -1 to 1
#define RANDVAR() ((double)rand() / RAND_MAX * 2.0 - 1.0)
double trial(void);