Skip to content

Instantly share code, notes, and snippets.

let rec separate = function
| [] -> ([],[])
| []::xs -> ([],[])
| (x::xs)::ys -> let (M,N) = separate ys
(x::M, xs::N)
let rec trans = function
| [] -> []
| x::xs -> let (q, w) = separate (x::xs) in
if List.length(q) = 0 then [] else [q] @ trans w
let rec separate = function
| [] -> ([],[])
| []::xs -> ([],[])
| (x::xs)::ys -> let (M,N) = separate ys
(x::M, xs::N)
let rec trans = function
| [] -> []
| x::xs -> let (q, w) = separate (x::xs) in
if List.length(q) = 0 then [] else [q] @ trans w
//////////Problem 6
let rec powerset = function
| [] -> [[]]
| h::t -> List.fold (fun xs t -> (h::t)::t::xs) [] (powerset t);;
type 'a stream = Cons of 'a * (unit -> 'a stream)
let rec upfrom n = Cons(n, fun () -> upfrom(n+1))
let t = upfrom 0
let rec take n (Cons(x,xsf)) = if n=0 then [] else x::(take (n-1) (xsf()))
(*Here's the map function, the rest is just to set it up or demonstrate it*)
let rec map f (Cons(x,xsf)) = Cons( (f x), fun() -> map f (xsf()))
take 10 (map (fun x -> x+x) t);;
let rec inner xs ys = match (xs,ys) with
| (x::xs,y::ys) -> (x*y) + inner xs ys
| _ -> 0
let rec separate = function
| [] -> ([],[])
| []::xs -> ([],[])
| (x::xs)::ys -> let (M,N) = separate ys
(x::M, xs::N)
type Exp =
Num of int
| Neg of Exp
| Sum of Exp * Exp
| Diff of Exp * Exp
| Prod of Exp * Exp
| Quot of Exp * Exp
let rec evaluate = function
| Num n -> Some n
module Interpret = begin
(* e -> term to replace in
x -> identifier string
t -> id replacement *)
let rec subst e x t = match e with
| ID s when s=x -> t
| IF (p,v,f) -> IF (subst p x t, subst v x t, subst f x t)
| APP (e1,e2) -> APP (subst e1 x t, subst e2 x t)
| FUN (id,c) when id=x -> FUN (id,c)
@camilopayan
camilopayan / cas-cascade.conf
Created August 24, 2011 20:24
CAS and Virtual Host Config
LoadModule auth_cas_module modules/mod_auth_cas.so
#CASDebug On
CASLoginURL https://auth.fiu.edu/cas/login
CASValidateURL https://auth.fiu.edu/cas/serviceValidate
CASAllowWildcardCert On
CASValidateServer Off
CASCookiePath /var/run/mod_auth_cas/
CASTimeout 36000
CASIdleTimeout 3600
@camilopayan
camilopayan / tomcat-connectors.xml
Created August 24, 2011 20:27
Tomcat connectors for ajp, and the overall connector on 443
<Connector port="443"
maxHttpHeaderSize="8192"
maxThreads="150"
minSpareThreads="25"
maxSpareThreads="75"
enableLookups="false"
disableUploadTimeout="true"
acceptCount="100"
scheme="https"
secure="true"
@camilopayan
camilopayan / gist:1249841
Created September 29, 2011 02:28
Number2 code
def find_mystery(length, mystery):
boxes = range(1, length+1)
step = int(sqrt(length))
count = 0
for t in range(0, length+1, step):
count = count+1
if t >= length:
print "Now checking %d and that is outta range" % t
else: