This file contains 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
def get_digit(n, num) #get the nth digit from a number | |
(num/10**n)%10 | |
end |
This file contains 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
set tabstop=2 | |
set smarttab | |
set shiftwidth=2 | |
set autoindent | |
set expandtab | |
set backspace=start,indent | |
set guifont=Inconsolata\ 14 | |
set hlsearch | |
syntax on | |
autocmd BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | |
This file contains 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
let string_rev str = | |
let rec aux idx = match idx with | |
0 -> Char.escaped (str.[0]) | |
| _ -> (Char.escaped str.[idx]) ^ (aux (idx-1)) in | |
aux ((String.length str)-1) ;; |
This file contains 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
let reverse_words str = | |
let slst = Str.split (Str.regexp_string " ") str in | |
List.fold_left (fun accum i -> accum ^ " " ^ i) " " (List.rev slst) ;; |
This file contains 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
let fizzbuzz i = match ((i mod 3), (i mod 5)) with | |
| (0,0) -> "fizzbuzz" | |
| (_,0) -> "buzz" | |
| (0,_) -> "fizz" | |
| (_,_) -> string_of_int i ;; | |
let do_fizzbuzz n = for i = 1 to n do | |
Printf.printf "%s\n" (fizzbuzz i) | |
done ;; |
This file contains 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
(* ( 'cs, 'conditions, 'actions, 'ns) *) | |
(* given a current state (cs) | |
* and condition - get the resulting actions and next state ('ns) *) | |
type 'a state = State of 'a ;; | |
type ('cs, 'cond, 'action, 'ns) st_entry = ST_Entry of ('cs * 'cond * 'action * 'ns);; | |
type state_list = st_entry list ;; | |
type ('cs, 'cond) st_cond = State_Cond of ('cs * 'cond) ;; | |
type ('action, 'ns) st_action_ns = Action_NS of ('action * 'ns);; |
This file contains 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
open Logic | |
type ('pred, 'ns) p_a_n = { pred: 'pred; | |
actions: (bexp*boolean) list; | |
ns: 'ns } deriving(Show);; | |
module type STATES = | |
sig | |
type t |
This file contains 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
(* Inspired by this puzzle from NPR: | |
http://www.npr.org/2012/01/29/146034893/this-puzzle-is-the-pits | |
(see the 'Next Weeks' challenge section there): | |
"Next Week's Challenge from listener Ed Pegg Jr.: Write the digits from | |
1 to 9 in a line. If you put times signs after the 2 and 4, a plus | |
sign after the 5, and a minus sign after the 7, you have | |
12 x 34 x 5 + 67 - 89, which equals 2018. | |
That's six years off from our current year 2012. This example uses | |
four arithmetic symbols. The object is to use just three of the | |
following arithmetic operations: addition, subtraction, multiplication |
This file contains 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
(* | |
In Ruby: | |
Say that you have a hash 'events' whose keys are the events you are | |
interested in and the values are the corresponding weights: | |
e.g. | |
events = { | |
"event1" => 5, |
This file contains 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
(*ocamlc -o test test.ml*) | |
(* the problem we're trying to solve is to have the FSM module | |
* be able to deal with different expression types | |
*) | |
module type BASETYPE = | |
sig | |
type 'a var_t | |
val set : 'a var_t -> 'a -> unit | |
val get_var_name : 'a var_t -> string | |
val get_var_val : 'a var_t -> 'a |
OlderNewer