Skip to content

Instantly share code, notes, and snippets.

View stackoverflow.ml
permutation [1;2;3;4;5;6;7;8;9];;
Stack overflow during evaluation (looping recursion?).
View recursive_permutation.ml
let insert_all_positions x l =
let rec aux prev acc l =
match l with
| [] -> (prev @ [x]) :: acc |> List.rev
| hd::tl as l -> aux (prev @ [hd]) ((prev @ [x] @ l) :: acc) tl
in aux [] [] l;;
let rec permutation l =
match l with
View dutch_partition.ml
let swap i j a =
try
let tmp = a.(j) in
a.(j) <- a.(i);
a.(i) <- tmp; a
with
_ -> raise (Invalid_argument "out-of-range")
(* auxiliary function *)
(* a[0 .. smaller - 1] : smaller region
View dutch_partition
let swap i j a =
try
let tmp = a.(j) in
a.(j) <- a.(i);
a.(i) <- tmp; a
with
_ -> raise (Invalid_argument "out-of-range")
(* auxiliary function *)
(* a[0 .. smaller - 1] : smaller region
@channgo2203
channgo2203 / reactiveschemes.cpp
Created Jul 11, 2016
Reactive Sytem Implementation Schemes
View reactiveschemes.cpp
InitializeMemory();
foreach input_event do
ComputeOutput();
UpdateMemory();
end
InitializeMemory();
foreach period do
@channgo2203
channgo2203 / introrx.md
Created Jun 10, 2016 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
View introrx.md
@channgo2203
channgo2203 / listplus.ml
Created May 23, 2016
Extra List Implementation
View listplus.ml
let rec last l =
match l with
| [] -> None
| [x] -> Some x
| _::t -> last t
let biggest_prefix l =
let rec bpre_aux xs ys = match xs with
| [] -> ys
| [x] -> ys
@channgo2203
channgo2203 / listplus.mli
Created May 23, 2016
Extra List Interface
View listplus.mli
(**************************************************************************)
(*
* Listplus
*
*
* Copyright 2016 Van-Chan Ngo.
*
* All rights reserved. This file is distributed under the terms of
* the GNU Lesser General Public License version 2.1, with the
* special exception on linking described in the file LICENSE.
@channgo2203
channgo2203 / prob1.ml
Created May 23, 2016
Finding shortest substrings that contain all strings in a given list
View prob1.ml
(*
* find the shortest substring of str containing the strings str1 str2,...,strm in a list
*)
(* use core for more efficient with long strings *)
open Core.Std
open Printf
(*
* find substring sub in string str forward from pos
You can’t perform that action at this time.