Update format and add merlin to nix-shell
This commit is contained in:
parent
a0a5e5f447
commit
aac66f7764
5 changed files with 27 additions and 31 deletions
12
day1.ml
12
day1.ml
|
@ -47,11 +47,7 @@ let rec get_2020_triple l =
|
||||||
|
|
||||||
|
|
||||||
let test_input = [1721; 979; 366; 299; 675; 1456;]
|
let test_input = [1721; 979; 366; 299; 675; 1456;]
|
||||||
let () =
|
let () = assert ((get_2020_pair test_input) = 514579)
|
||||||
assert ((get_2020_pair test_input) = 514579)
|
let () = print_endline (string_of_int (get_2020_pair input_day1))
|
||||||
let () =
|
let () = assert ((get_2020_triple test_input) = 241861950)
|
||||||
print_endline (string_of_int (get_2020_pair input_day1))
|
let () = print_endline (string_of_int (get_2020_triple input_day1))
|
||||||
let () =
|
|
||||||
assert ((get_2020_triple test_input) = 241861950)
|
|
||||||
let () =
|
|
||||||
print_endline (string_of_int (get_2020_triple input_day1))
|
|
||||||
|
|
26
day4.ml
26
day4.ml
|
@ -23,18 +23,18 @@ type passport =
|
||||||
}
|
}
|
||||||
|
|
||||||
let passport_of_string s =
|
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 (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
|
try Some
|
||||||
{ byr = int_of_string (List.assoc "byr" map)
|
{ byr = int_of_string (List.assoc "byr" hmap)
|
||||||
; iyr = int_of_string (List.assoc "iyr" map)
|
; iyr = int_of_string (List.assoc "iyr" hmap)
|
||||||
; eyr = int_of_string (List.assoc "eyr" map)
|
; eyr = int_of_string (List.assoc "eyr" hmap)
|
||||||
; hgt = List.assoc "hgt" map
|
; hgt = List.assoc "hgt" hmap
|
||||||
; hcl = List.assoc "hcl" map
|
; hcl = List.assoc "hcl" hmap
|
||||||
; ecl = List.assoc "ecl" map
|
; ecl = List.assoc "ecl" hmap
|
||||||
; pid = List.assoc "pid" map
|
; pid = List.assoc "pid" hmap
|
||||||
; cid = List.assoc_opt "cid" map
|
; cid = List.assoc_opt "cid" hmap
|
||||||
}
|
}
|
||||||
with Not_found -> None
|
with Not_found -> None
|
||||||
|
|
||||||
|
@ -68,7 +68,5 @@ let part2 l =
|
||||||
|> List.length
|
|> List.length
|
||||||
|
|
||||||
|
|
||||||
let () =
|
let () = print_endline (string_of_int (read_file_rev "day4.input" |> part1))
|
||||||
print_endline (string_of_int (read_file_rev filename |> part1))
|
let () = print_endline (string_of_int (read_file_rev "day4.input" |> part2))
|
||||||
let () =
|
|
||||||
print_endline (string_of_int (read_file_rev filename |> part2))
|
|
||||||
|
|
6
day6.ml
6
day6.ml
|
@ -24,16 +24,14 @@ let read_lines name =
|
||||||
|
|
||||||
let part1 filename =
|
let part1 filename =
|
||||||
read_lines filename
|
read_lines filename
|
||||||
|> List.map (fun x -> x
|
|> List.map (fun x -> x |> (String.concat "")
|
||||||
|> (String.concat "")
|
|
||||||
|> set_of_string
|
|> set_of_string
|
||||||
|> CS.cardinal)
|
|> CS.cardinal)
|
||||||
|> List.fold_left (+) 0
|
|> List.fold_left (+) 0
|
||||||
|
|
||||||
let part2 filename =
|
let part2 filename =
|
||||||
read_lines filename
|
read_lines filename
|
||||||
|> List.map (fun x -> x
|
|> List.map (fun x -> x |> List.map set_of_string
|
||||||
|> List.map set_of_string
|
|
||||||
|> List.fold_left CS.inter all_char_set
|
|> List.fold_left CS.inter all_char_set
|
||||||
|> CS.cardinal)
|
|> CS.cardinal)
|
||||||
|> List.fold_left (+) 0
|
|> List.fold_left (+) 0
|
||||||
|
|
2
day8.ml
2
day8.ml
|
@ -48,7 +48,7 @@ let rec swap_from idx ins =
|
||||||
let fix instructions =
|
let fix instructions =
|
||||||
let rec aux idx ins instructions =
|
let rec aux idx ins instructions =
|
||||||
try run ins
|
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
|
aux i ins instructions
|
||||||
in aux 0 (Array.copy instructions) instructions
|
in aux 0 (Array.copy instructions) instructions
|
||||||
|
|
||||||
|
|
|
@ -26,9 +26,13 @@ stdenv.mkDerivation rec {
|
||||||
findlib
|
findlib
|
||||||
utop
|
utop
|
||||||
dune
|
dune
|
||||||
|
merlin
|
||||||
|
ocamlformat
|
||||||
|
opam
|
||||||
];
|
];
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
alias utop="utop -init ${ocamlInit}"
|
alias utop="utop -init ${ocamlInit}"
|
||||||
alias ocaml="ocaml -init ${ocamlInit}"
|
alias ocaml="ocaml -init ${ocamlInit}"
|
||||||
|
export MERLIN_SITE_VIM="${ocamlPackages.merlin}/share/merlin/vim"
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue