This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [bitmap.hpp] | |
#ifndef __BITMAP_HPP__ | |
#define __BITMAP_HPP__ | |
#include <cstdint> | |
#include <vector> | |
typedef struct {uint8_t R, G, B;} RGB; | |
namespace Color { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [dynamic_bitset.hpp] | |
#ifndef __DYNAMIC_BITSET_HPP__ | |
#define __DYNAMIC_BITSET_HPP__ | |
#include <string> | |
#include <vector> | |
#include <stdexcept> | |
#include "dynamic_bitset.h" | |
class dynamic_bitset { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* 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]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* 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 *) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(** 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
OlderNewer