Update format and add merlin to nix-shell

This commit is contained in:
Vladan Popovic 2020-12-29 06:28:32 +01:00
parent a0a5e5f447
commit aac66f7764
5 changed files with 27 additions and 31 deletions

12
day1.ml
View File

@ -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))

26
day4.ml
View File

@ -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))

View File

@ -24,16 +24,14 @@ let read_lines name =
let part1 filename =
read_lines filename
|> List.map (fun x -> x
|> (String.concat "")
|> 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.map (fun x -> x |> List.map set_of_string
|> List.fold_left CS.inter all_char_set
|> CS.cardinal)
|> List.fold_left (+) 0

View File

@ -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

View File

@ -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"
'';
}