1
0
Fork 0
This commit is contained in:
Gregory Eremin 2023-01-13 00:01:06 +01:00
parent 1d1c91cc88
commit c88f6f0c60
3 changed files with 357 additions and 0 deletions

300
inputs/3.txt Normal file
View File

@ -0,0 +1,300 @@
hDsDDttbhsmshNNWMNWGbTNqZq
VQfjnlFvnQFRdZWdVtqMGdWW
zvvvRnFFfjjlRBlBPzgQgRvvmtrmhHcptLHCDhcHHmLsBmsB
FrzFvvdTDcTnmTzdDTTzdvWmjhgVPrhSljSQSPwPjPjPjSVC
sMsGbqGsbbRqRbBMBGRMbLpNSSpjhlQljHVClhjgPjjPhlVp
sNbGtJbMfssNtvcnWFVmnvDd
TNfmdFJmfdZMQffVRQVV
jVHBCcDSjWrMZjvg
SShSbCGpcBtBtwtVLJJddmtLmT
CtpNftbNWbtSJDHqGZJFLfLr
dPsHlsRBHcZdqDFDZwwJ
snjVlvTPlPjVlQlHWjpSmzgNNzSmtpSm
qhZtSVqCqThGcGzZnnfZcB
WbddWbDwrBzcpzHpBb
DBBMFWRJDrDFWLWljCqjQjFvtCsqTjqs
vhFTzRzzTmPvbplWFtQttQQZtZhMZqcqSQ
fJVCfDfJNCLDwJNGmssZgwqgZcmtgcms
VmdVNLHGGVDBdfLCHnLGHnbWpTplWbddRTlzplWPpbFp
smwtNVqRjNmZjZBDSvzSzl
FnTJFcTTFccCrJGTLncdCCcPJZfBBDSlSJwZDlggSffvgSSf
FWTFGLFWLCPWrCnFnQWNbQVVwphhmHHbptVsss
BrrgrtgfBpPFhhgMWq
ZGvsvDGClvsSRScpGBhPphWMPhhTNh
SBSBdBZCcdwHrVQwQr
qmFqdVtqsVdzqGbwMJwGPpmPHM
ZjTjLQLLDrrLjcFhlfrGHppfbJwGpMMpGHwRCC
BTlZjrBBBcLTcDrjBlThWBjBtWNqnSzSnsSdvsFggNnqVVnv
zVvmjGgpcJnbTTTJHRHSRb
NPFrFQfCLPrdRlbtQRRvBtHb
frMLqPFMrfrPLCwqqNvjczwwnmwggGmssnmnnm
H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SSwPBwBDBwPmZhZlfZhqHTsTfltHHZfsHH
GbNbsSptQGqsdJCzsddcgzzv
DHRRnmWWmZnmRhllnHnnnMLvvLgcTVvjVhCTvgzcJgLj
RnWMlDZRlnHlmHWBFwGQqNGGPNQzPGqFwz
vSGvHpJnBLbGHBNCgfDzzChDgbCfzT
wFRslqmqTRgggQghPmQf
qjRFMjWqNNMMGHTL
fWGcQGGSRFQZhttZJfSSJflDDrwdClljVrNDdrdCFBCr
MTgvLLPPnHzMbDwdlNbMBwMM
mnTvnnPTcNmmJJWN
qqbbQQnbWrqGgnWqvZpVzMCZjCgfjZCSVM
ldcmDPDhmlFBHPDddLBVFDHLppZpjSCjjNfwNMwCpSMwhCMp
FtDdsHPcHmdHVPLtHsdtBHQnsbvnTRRTRsRRqbqvqWnJ
hhtBtPrgbbhhgjZjjCCHHNpNDHpffHWCvr
LGFLVwswsJMSgFwMMpddSvpHCCdDdvCpvm
sGsFsQLsVsLFnnFTJQthjcjQqhRcBZZtRg

55
ocaml/3.ml Normal file
View File

@ -0,0 +1,55 @@
#use "lib/file_utils.ml" ;;
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
in
let sum_of_priorities fn str =
let chars = List.sort_uniq compare (list_of_chars str) in
List.fold_left fn 0 chars
in
let sum_rucksack_priorities lines =
let rucksack_priority str =
let len2 = (String.length str)/2 in
let comp1 = String.sub str 0 len2 in
let comp2 = String.sub str len2 len2 in
let char_priority agg c =
if String.contains comp2 c
then (agg + priority_of_item c)
else agg
in
sum_of_priorities char_priority comp1
in
List.fold_left (+) 0 (List.map rucksack_priority lines)
in
let rec sum_badge_priorities sum lines =
let common_badge_priority str1 str2 str3 =
let char_priority agg c =
if String.contains str2 c && String.contains str3 c
then (agg + priority_of_item c)
else agg
in
sum_of_priorities char_priority str1
in
match lines with
| [] -> sum
| hd1 :: tl1 -> match tl1 with
| [] -> failwith "number of rows must be divisible by 3"
| hd2 :: tl2 -> match tl2 with
| [] -> failwith "number of rows must be divisible by 3"
| hd3 :: tl3 -> sum_badge_priorities (sum + common_badge_priority hd1 hd2 hd3) tl3
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 sum1 = sum_rucksack_priorities lines in
let sum2 = sum_badge_priorities 0 lines in
Printf.printf "Part 1: %d\n" sum1;
Printf.printf "Part 2: %d\n" sum2

View File

@ -4,3 +4,5 @@ let read_file filename =
close_in ch; close_in ch;
s s
;; ;;
let list_of_chars str = List.init (String.length str) (String.get str)