Skip to content

Instantly share code, notes, and snippets.

View gofer's full-sized avatar

Gofer gofer

View GitHub Profile
@gofer
gofer / ppm_bitmap.cpp
Last active December 29, 2015 17:09
PPM type bitmap class
// [bitmap.hpp]
#ifndef __BITMAP_HPP__
#define __BITMAP_HPP__
#include <cstdint>
#include <vector>
typedef struct {uint8_t R, G, B;} RGB;
namespace Color {
@gofer
gofer / dynamic_bitset.cpp
Last active December 29, 2015 17:09
Original Dynamic Bitset
// [dynamic_bitset.hpp]
#ifndef __DYNAMIC_BITSET_HPP__
#define __DYNAMIC_BITSET_HPP__
#include <string>
#include <vector>
#include <stdexcept>
#include "dynamic_bitset.h"
class dynamic_bitset {
@gofer
gofer / 7seg_driver.v
Last active December 29, 2015 17:09
7seg Driver
// ACTIVE-LOW
// 0: 1000000 1: 1111001 2: 0100100 3: 0110000
// 4: 0011001 5: 0010010 6: 0000010 7: 1111000
// 8: 0000000 9: 0010000 A: 0001000 B: 0000011
// C: 1000110 D: 0100001 E: 0000110 F: 0001110
module driver_7seg(
input [3:0] in,
output [6:0] out
);
@gofer
gofer / insert_sort.sml
Last active December 30, 2015 14:19
Insert Sort
(* insert sort *)
fun insert_sort nil = nil
| insert_sort (y::ys) = let
fun insert n nil = [n]
| insert n (x::xs) = if x < n then (x::(insert n xs)) else (n::(x::xs));
in
insert y (insert_sort ys)
end;
insert_sort [5, 1, 2, 4, 1, 3];
@gofer
gofer / base.sml
Last active December 30, 2015 14:19
Map, Reduce, Filter
(* map *)
fun map f nil = nil
| map f (x::xs) = (f x)::(map f xs);
(* reduce *)
fun reduce f x0 nil = x0
| reduce f x0 (x::nil) = f x x0
| reduce f x0 (x::xs) = f x (reduce f x0 xs);
(* filter *)
@gofer
gofer / sublist.sml
Last active December 30, 2015 14:19
Sublist
(* sublist *)
fun sublist _ _ nil = nil
| sublist 0 0 (x::xs) = [x]
| sublist 0 e (x::xs) = x::(sublist 0 (e-1) xs)
| sublist b e (x::xs) = let
val b_ = b + (if b < 0 then (length (x::xs)) else 0)
in
sublist (b_-1) (e-1) xs
end;
@gofer
gofer / bubble_sort.sml
Last active December 30, 2015 14:29
Bubble Sort
(** Bubble Sort **)
fun bubble_sort nil = nil
| bubble_sort (x::xs) =
let
fun sort_aux nil = nil
| sort_aux (x::nil) = x::nil
| sort_aux (x::(y::nil)) = if x < y then x::(y::nil) else y::(x::nil)
| sort_aux (x::(y::xs)) = if x < y then x::(sort_aux (y::xs)) else y::(sort_aux (x::xs))
fun sort_ _ nil = nil
@gofer
gofer / quick_sort.sml
Last active December 30, 2015 14:39
Quick sort
(* Quick Sort *)
exception QuickSortException;
fun qsort nil = nil
| qsort (x::nil) = x::nil
| qsort (x::xs) =
let
fun fst_pair (a, b) = a
fun snd_pair (a, b) = b
fun max nil = raise QuickSortException
@gofer
gofer / debug.sml
Created December 7, 2013 14:38
Print list
(* List print for debug *)
fun print_list nil = print "nil\n"
| print_list (x::xs) =
let
fun print_list_ nil = "nil"
| print_list_ (x::nil) = String.concat([(Int.toString(x)), "\n"])
| print_list_ (x::xs) = String.concat([Int.toString x, ", ", print_list_ xs])
in
print (print_list_ (x::xs))
end;
@gofer
gofer / set.sml
Created December 19, 2013 09:16
Set.sml
signature SetSig =
sig
val empty : ''a list
val is_in : ''a -> ''a list -> bool
val is_not_in : ''a -> ''a list -> bool
val rm_elem : ''a -> ''a list -> ''a list
val isect : ''a list -> ''a list -> ''a list
val union : ''a list -> ''a list -> ''a list
val diff : ''a list -> ''a list -> ''a list
end