(* https://gist.github.com/masquerade0324/68f4f3fd3ab897fbe1ad *) fun bs xs 0 = xs | bs (x::y::ys) n = if (x