Improve day 3 char code math readability
This commit is contained in:
parent
b0925c89a9
commit
c14c6f5ea7
10
ocaml/3.ml
10
ocaml/3.ml
|
@ -4,9 +4,9 @@ let priority_of_item c =
|
|||
(* ASCII lower case is 97-122, upper case is 65-90 *)
|
||||
(* Lower case start at 1, upper case at 27 *)
|
||||
let code = Char.code c in
|
||||
if code > 90
|
||||
then code - 96
|
||||
else code - 65 + 27
|
||||
if code > Char.code 'Z'
|
||||
then code - (Char.code 'a') + 1
|
||||
else code - (Char.code 'A') + 27
|
||||
in
|
||||
|
||||
let sum_of_priorities fn str =
|
||||
|
@ -48,7 +48,9 @@ let rec sum_badge_priorities sum lines =
|
|||
in
|
||||
|
||||
let contents = read_file "inputs/3.txt" in
|
||||
let lines = List.filter (fun l -> String.trim l <> "") (String.split_on_char '\n' contents) in
|
||||
let lines = String.split_on_char '\n' contents
|
||||
|> List.filter (fun l -> String.trim l <> "")
|
||||
in
|
||||
let sum1 = sum_rucksack_priorities lines in
|
||||
let sum2 = sum_badge_priorities 0 lines in
|
||||
Printf.printf "Part 1: %d\n" sum1;
|
||||
|
|
Loading…
Reference in New Issue