Skip to content

Instantly share code, notes, and snippets.

View test_re2.ml
let () = Printexc.record_backtrace true
(* Turn a regular expression from Regenerate into an RE one. *)
let rec to_re r =
let open Regenerate.Regex in
let open Regex in
let concatenation_iter i re =
1 -- (i - 1)
|> List.fold_left (fun acc _ -> RE.concat re acc) re
in
View dfa2.ml
module DFA2 : Matching = struct
type t1 = (int * state) ref
and state =
| Split of t1 * t1
| CharSet of CSet.t * t1
| Match
module S =
Set.Make(
struct
View cont.ml
let rec factorial n =
if n = 0 then 1
else n * factorial (n - 1)
let rec factorial_acc n acc =
if n = 0 then acc
else factorial_acc (n - 1) (n * acc)
let rec factorial_cont n k =
if n = 0 then k 1
View floyd_warshall_regex.ml
(** [explode s] returns the list of the characters of the string [s].
For example, [explode "hello"] is ['h'; 'e'; 'l'; 'l'; 'o']. *)
let explode s =
List.init (String.length s) (fun i -> String.get s i)
let implode l =
let res = Bytes.create (List.length l) in
let rec imp i = function
| [] -> ()
| c :: l -> Bytes.set res i c; imp (i + 1) l in
View replace.py
import sys
import re
s = sys.argv[1]
s = re.sub('⟮', '(', s)
s = re.sub('⟯', ')', s)
s = re.sub('│', '|', s)
s = re.sub('⭑', '*', s)
s = re.sub('⁺', '+', s)
s = re.sub('?', '?', s)
View transitive_closure.ml
type graph = bool array array
let example () =
[| (* 0 1 2 3 4 *)
(*0*) [| true; true; false; true; false; |];
(*1*) [| false; true; true; false; false; |];
(*2*) [| false; false; true; false; false; |];
(*3*) [| false; false; false; true; true; |];
(*4*) [| true; false; false; false; true; |];
|]
View rpn.mll
{
open Lexing
open Printf
let newline lexbuf =
let pos = lexbuf.lex_curr_p in
lexbuf.lex_curr_p <-
{ pos with pos_lnum = pos.pos_lnum + 1; pos_bol = pos.pos_cnum }
let error lexbuf msg =
View clean.mll
rule clean = parse
| '\t'
{
print_string " ";
clean lexbuf
}
| (' ' | '\t')* '\n'
{
print_newline ();
clean lexbuf
View lexer.cpp
#include <iostream>
#include <vector>
#include <map>
#include <variant>
#include <exception>
#include <fstream>
using namespace std;
void debug(auto f) {
View dfa.cpp
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<vector<int>> dfa
{
// a b
You can’t perform that action at this time.