Skip to content

Instantly share code, notes, and snippets.

@pocarist
pocarist / heap.ml
Created January 29, 2016 08:19
Meldable Heap (OCaml version)
module type OrderedType = sig
type t
val compare : t -> t -> int
end
module type S =
sig
type elt
type t
val empty: t
@pocarist
pocarist / FizzBuzz.fs
Created September 26, 2023 16:04
FizzBuzz written using F# sequence
let fizz =
Seq.initInfinite (fun i -> if (i+1) % 3 = 0 then "Fizz" else "")
let buzz =
Seq.initInfinite (fun i -> if (i+1) % 5 = 0 then "Buzz" else "")
let fizzbuzz =
Seq.mapi2 (fun i f b -> match f + b with "" -> string (i + 1) | x -> x) fizz buzz
fizzbuzz
|> Seq.take 100
|> Seq.iter (printfn "%s")
// https://twitter.com/e869120/status/1741475801026204116#
(*
(20 + (((23 + 12) - 31) * ((20 * (24 + 1)) + 1)))
(((20 * 23) + (((12 + 31) - 20) * 24)) * (1 + 1))
*)
let rec gcd a (b: int) = if b = 0 then a else gcd b (a % b)