Skip to content

Instantly share code, notes, and snippets.

@IwanKaramazow
Created February 10, 2020 09:28
Show Gist options
  • Save IwanKaramazow/765493b5677a56e8df38cb7e35afda70 to your computer and use it in GitHub Desktop.
Save IwanKaramazow/765493b5677a56e8df38cb7e35afda70 to your computer and use it in GitHub Desktop.
missing.ns
open BinarySearchTree
module List = Belt.List
let rec weave = (list1, list2, prefix, results) =>
switch (list1, list2) {
| (list[], _) | (_, list[]) =>
let everything = List.concatMany([prefix, list1, list2])->List.toArray
results->Js.Array2.push(everything)->ignore
| (list[hd1, ...tail1], list[hd2, ...tail2]) =>
let oldPrefix = prefix
let newPrefix = oldPrefix->List.add(hd1)
weave(tail1, tail2, newPrefix, results)
let newPrefix = oldPrefix->List.add(hd2)
weave(tail1, tail2, newPrefix, results)
()
}
let () = {
let results = []
weave(list[1, 2], list[3, 4], [])
Js.log(results)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment