An optimal, purely functional implementation of the Garsia–Wachs algorithm. (21st January 2020)