From aac66f776476492da65e92a21fc58d5575cca929 Mon Sep 17 00:00:00 2001 From: Vladan Popovic Date: Tue, 29 Dec 2020 06:28:32 +0100 Subject: [PATCH] Update format and add merlin to nix-shell --- day1.ml | 12 ++++-------- day4.ml | 26 ++++++++++++-------------- day6.ml | 14 ++++++-------- day8.ml | 2 +- default.nix | 4 ++++ 5 files changed, 27 insertions(+), 31 deletions(-) diff --git a/day1.ml b/day1.ml index 326ef44..fc26c8b 100644 --- a/day1.ml +++ b/day1.ml @@ -47,11 +47,7 @@ let rec get_2020_triple l = let test_input = [1721; 979; 366; 299; 675; 1456;] -let () = - assert ((get_2020_pair test_input) = 514579) -let () = - print_endline (string_of_int (get_2020_pair input_day1)) -let () = - assert ((get_2020_triple test_input) = 241861950) -let () = - print_endline (string_of_int (get_2020_triple input_day1)) +let () = assert ((get_2020_pair test_input) = 514579) +let () = print_endline (string_of_int (get_2020_pair input_day1)) +let () = assert ((get_2020_triple test_input) = 241861950) +let () = print_endline (string_of_int (get_2020_triple input_day1)) diff --git a/day4.ml b/day4.ml index 5eb1ed8..28d1b66 100644 --- a/day4.ml +++ b/day4.ml @@ -23,18 +23,18 @@ type passport = } let passport_of_string s = - let map = String.split_on_char ' ' s + let hmap = String.split_on_char ' ' s |> List.map (String.split_on_char ':') - |> List.map (fun [k; v] -> (k, v)) in + |> List.filter_map (fun el -> match el with [k; v] -> Some (k, v) | _ -> None) in try Some - { byr = int_of_string (List.assoc "byr" map) - ; iyr = int_of_string (List.assoc "iyr" map) - ; eyr = int_of_string (List.assoc "eyr" map) - ; hgt = List.assoc "hgt" map - ; hcl = List.assoc "hcl" map - ; ecl = List.assoc "ecl" map - ; pid = List.assoc "pid" map - ; cid = List.assoc_opt "cid" map + { byr = int_of_string (List.assoc "byr" hmap) + ; iyr = int_of_string (List.assoc "iyr" hmap) + ; eyr = int_of_string (List.assoc "eyr" hmap) + ; hgt = List.assoc "hgt" hmap + ; hcl = List.assoc "hcl" hmap + ; ecl = List.assoc "ecl" hmap + ; pid = List.assoc "pid" hmap + ; cid = List.assoc_opt "cid" hmap } with Not_found -> None @@ -68,7 +68,5 @@ let part2 l = |> List.length -let () = - print_endline (string_of_int (read_file_rev filename |> part1)) -let () = - print_endline (string_of_int (read_file_rev filename |> part2)) +let () = print_endline (string_of_int (read_file_rev "day4.input" |> part1)) +let () = print_endline (string_of_int (read_file_rev "day4.input" |> part2)) diff --git a/day6.ml b/day6.ml index 96fa610..dc7f96f 100644 --- a/day6.ml +++ b/day6.ml @@ -24,18 +24,16 @@ let read_lines name = let part1 filename = read_lines filename - |> List.map (fun x -> x - |> (String.concat "") - |> set_of_string - |> CS.cardinal) + |> List.map (fun x -> x |> (String.concat "") + |> set_of_string + |> CS.cardinal) |> List.fold_left (+) 0 let part2 filename = read_lines filename - |> List.map (fun x -> x - |> List.map set_of_string - |> List.fold_left CS.inter all_char_set - |> CS.cardinal) + |> List.map (fun x -> x |> List.map set_of_string + |> List.fold_left CS.inter all_char_set + |> CS.cardinal) |> List.fold_left (+) 0 let () = print_endline (string_of_int (part1 "day6.input")) diff --git a/day8.ml b/day8.ml index 36caccd..ddee6d2 100644 --- a/day8.ml +++ b/day8.ml @@ -48,7 +48,7 @@ let rec swap_from idx ins = let fix instructions = let rec aux idx ins instructions = try run ins - with e -> let (i, ins) = swap_from idx (Array.copy instructions) in + with _ -> let (i, ins) = swap_from idx (Array.copy instructions) in aux i ins instructions in aux 0 (Array.copy instructions) instructions diff --git a/default.nix b/default.nix index cd97f74..2994a05 100644 --- a/default.nix +++ b/default.nix @@ -26,9 +26,13 @@ stdenv.mkDerivation rec { findlib utop dune + merlin + ocamlformat + opam ]; shellHook = '' alias utop="utop -init ${ocamlInit}" alias ocaml="ocaml -init ${ocamlInit}" + export MERLIN_SITE_VIM="${ocamlPackages.merlin}/share/merlin/vim" ''; }