Solved Day 3

main
s00ner 2022-12-03 11:01:45 -05:00
parent 1fd63649f6
commit f226fd7429
2 changed files with 325 additions and 0 deletions

300
day03/input Normal file
View File

@ -0,0 +1,300 @@
shzsFcPssFhjFssBzdpRcNHNZrpdJdJVJZ
fwvMCntfCCbSbSbtDgDNrDtDtJHZVH
GbCwwbwwnGrLhBzjFFFsWPhL
PpCqRsqqmmtCwMJC
LHFrLLHDSNHlfWNhDzmjzzJlJzPJMvPJjQ
SGSWDNrhZhPDSWDZLgVVRgbRppgpGVnpnn
GRRjbVjmJZlgMRzzrN
FpDptHpfHfnpPTvDFTWpFPnPcMfNCClNrzcVcrMMzVsCZlsZ
TFTQDnvLHPFDtVbLwbjdGjdwwJ
lhljvvhCjjzhjszzBPmnmGVZMGzG
FbTcTwbtSFdtcMPnTBPQVnnBZT
SFMpHDtNDSSbSdwppvgJWjJCJJgWgvlJHH
wzNCWpzCzJnWWpRRNdJrgHLhjfbLrHrchV
lBMStmPmmLQDPQZlshrdhgrfrcrrddgHgs
mvGDGQSvDPBlGMLGCvCWpNvpzRWFwqRw
stBttBThtDZqPWssPWZp
gRggwwggCGFSBBvPRpHZZrHdZLZq
ccFJGCNJmmGQzbTDhnQhBBnB
HJqMqtZbJMmJTqtLtVMqhpfphNdQfhfzzjhhlHll
rWSBrnwFwWCvwWCwBgPgCgzjQccQhhgRzcdQzjfcNfzR
CWBCwCvCvvwssWLMtJJGMdMZJsGV
nFwSFQwsNrrsssSwCrhrCNnfcCRgJRMJTJcMfRzMCMCRvW
DdbGdLZLttllWWvTzgzzgR
ZqGzPdLtDjBjDZGPZVmnhQFwqrFQhVFnss
sNNpCjttjsJjSpgpWjslCTnqqSVffrnhSfDhmhrhfm
dBwcGzbPBHbbwZcwJbcTTFDFFFDVrdVmFdnDqf
HzGcczQPHGwzPzGHRctWlvRgtvJlvNlJvRNj
cFNCFdvcCHvFBCZcwBfRSpttGhDmCghGShmSRt
QjLnTTzQVzTTnLMqhDgPhGDDSjGPrgSh
T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ddtHScbWbMjt
NmzqhzCCqmzffhCCqrhhLLnPvpnTPPgpGTTBSL
ShhfLSDDFMPQddpMrDgNbjzffqqqzgcjbqZR
sCstmwJwVBtmTltVmTVbRbcbcRvqvrZvBRvZbR
VwCnwnVrrrWShWPHHDdQFL
pbpDpWjZMmFCmmmb
jTjtJLJgJncCFmnJFC
LvhvhTQhBSdRNtLNsSszlGrHSGjZDlGf
JrhvTNJJhhCrtVtcrNLwDBSBwqzDwQVbBLQS
RnCgHmHHGMdPsGMfDlDqlSQbQnQQDbzD
RdPMPsmWHmjfMffPcCWrptcprpFTFrFp

25
day03/solution.rb Executable file
View File

@ -0,0 +1,25 @@
#!/bin/env ruby
require 'pry'
def item_priority(item)
adjust = (item == item.upcase ? 38 : 96)
item.ord - adjust
end
sacks = File.readlines('./input').map(&:strip).map { |sack| sack.chars.each_slice(sack.size / 2).map(&:join) }
items = sacks.map { |comp1, comp2| [comp1.chars.uniq, comp2.chars.uniq].flatten.sort.join.scan(/(.)\1/).flatten[0] }
items.map! { |item| item_priority(item) }
puts "Part 1 Solution: #{items.sum}"
## Part2
elves = sacks.map(&:join).each_slice(3).to_a
elves.map! do |group|
group.map { |item| item.chars.uniq.join }.join.chars.sort.join.scan(/(.)\1\1/).flatten[0]
end
elves.map! { |item| item_priority(item) }
puts "Part 2 Solution: #{elves.sum}"
#binding.pry