Compare commits
2 Commits
22c7a9b737
...
462782ad30
Author | SHA1 | Date | |
---|---|---|---|
462782ad30 | |||
a49f204feb |
@ -1,5 +1,4 @@
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
const DRAW_SCORE: i32 = 3;
|
const DRAW_SCORE: i32 = 3;
|
||||||
const WIN_SCORE: i32 = 6;
|
const WIN_SCORE: i32 = 6;
|
||||||
const LOSE_SCORE: i32 = 0;
|
const LOSE_SCORE: i32 = 0;
|
||||||
@ -79,7 +78,7 @@ fn find_needed_shape_for_right(left: &str, win_state: WinState) -> String {
|
|||||||
},
|
},
|
||||||
WinState::Error => todo!(),
|
WinState::Error => todo!(),
|
||||||
};
|
};
|
||||||
return String::from(shape);
|
String::from(shape)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_complicated_result(left: &str, right: &str) -> i32 {
|
fn find_complicated_result(left: &str, right: &str) -> i32 {
|
||||||
@ -104,20 +103,20 @@ fn find_result(left: &str, right: &str) -> i32 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn shape_score(shape: Shape) -> i32 {
|
fn shape_score(shape: Shape) -> i32 {
|
||||||
return match shape {
|
match shape {
|
||||||
Shape::Rock => 1,
|
Shape::Rock => 1,
|
||||||
Shape::Paper => 2,
|
Shape::Paper => 2,
|
||||||
Shape::Scissors => 3,
|
Shape::Scissors => 3,
|
||||||
Shape::Error => 0,
|
Shape::Error => 0,
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
fn string_to_shape(shapestring: &str) -> Shape {
|
fn string_to_shape(shapestring: &str) -> Shape {
|
||||||
return match shapestring {
|
match shapestring {
|
||||||
"A" | "X" => Shape::Rock,
|
"A" | "X" => Shape::Rock,
|
||||||
"B" | "Y" => Shape::Paper,
|
"B" | "Y" => Shape::Paper,
|
||||||
"C" | "Z" => Shape::Scissors,
|
"C" | "Z" => Shape::Scissors,
|
||||||
_ => Shape::Error,
|
_ => Shape::Error,
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
25
day03/Cargo.lock
generated
Normal file
25
day03/Cargo.lock
generated
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "day03"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"itertools",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "either"
|
||||||
|
version = "1.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itertools"
|
||||||
|
version = "0.10.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
|
||||||
|
dependencies = [
|
||||||
|
"either",
|
||||||
|
]
|
9
day03/Cargo.toml
Normal file
9
day03/Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "day03"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
itertools = "0.10.5"
|
6
day03/exampleInput.txt
Normal file
6
day03/exampleInput.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
vJrwpWtwJgWrhcsFMMfFFhFp
|
||||||
|
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
|
||||||
|
PmmdzqPrVvPwwTWBwg
|
||||||
|
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
|
||||||
|
ttgJtRGJQctTZtZT
|
||||||
|
CrZsJsPPZsGzwwsLwLmpwMDw
|
300
day03/input.txt
Normal file
300
day03/input.txt
Normal file
@ -0,0 +1,300 @@
|
|||||||
|
vvMQnwwvrwWNfrtZJfppmSfJSmSg
|
||||||
|
BzGqjlBqBBmztHNFzDHg
|
||||||
|
llRCPlTPPqBjPhqhlBRBClhqWcTWrWNcMbQbdrdLccccrnvM
|
||||||
|
wMhwbTWpQjbpWHMQppzTHhjtlCjPSSJCCtlqRlJVFJFt
|
||||||
|
ggdvvnvDgdDmNcBrrcDntFRFqHJJtSJqvlVSRlJq
|
||||||
|
fggNNffGmcBrmBfcDzzzpHbsGTpszwwTbp
|
||||||
|
BPdPPBggrPtrpbtvPBBdgrFmhhQThGGlbbTZnzZQzZfn
|
||||||
|
ccjWRJVNcTGmnWWFmh
|
||||||
|
DMNmsMHwRNBrggdPDPdt
|
||||||
|
TfsfHLQbBtBFQbQsBmPwwlnPGZFwwdwWFZZw
|
||||||
|
MRpcvJMJVSMrVMpVSvhhnclwgWwDZgWgWgWglwcG
|
||||||
|
GCzjRJjVjSSrvfNQtLmQNsQbjB
|
||||||
|
FrSPFjtVvwsqSwcG
|
||||||
|
hDHdWDngpgZTDgHzzHwNNqlwNvZJlGqcQGsl
|
||||||
|
wDzLTDHgFffLtRft
|
||||||
|
CnCJNVqvCBJBNZmfPcPMcFLVcwmd
|
||||||
|
HgzjHFghSFtrLfwPchPM
|
||||||
|
QDpjgDSQlHHlDQQRzRzsBRRvWnWvJvZnqWBJNF
|
||||||
|
mGHcFPFqzPtcfPwDGVVpgLgSlgBl
|
||||||
|
rCvddTrnsbDLVSDwjSjd
|
||||||
|
QWhWQThswssMQMMMvhTzPqJzmzftHccJfHFhFm
|
||||||
|
cPbNpLVFTPbbFrpTLQBzqqmgnnBhgLMM
|
||||||
|
vvSwWCZCRZCDZtGwzdgWdQmzqgnQddJn
|
||||||
|
vCltGltCGmRRmCvDjjtHFpbcFfbbfssbpNPpHFpH
|
||||||
|
WLLQMWZLSPMPWmrwhnjhZZhpHJHljBDB
|
||||||
|
csbtCfFgCftGljHwHcBnpnJR
|
||||||
|
tsvgszNtfMwPzWqPrS
|
||||||
|
NbDZrbrFQQqqQtQqQDtTcBvCLBLswsZhscCGBZ
|
||||||
|
ljmWRzVRpbndMWmmfdsTsCBsGwTVVVCGCGws
|
||||||
|
ffRpnllHRMfdWzdnmRNQNNSFQQFNbrFHHrNH
|
||||||
|
LccGzWNjcvNLGTmHNsNLMlMwMpMPGlMCwFwDDGCw
|
||||||
|
fZZtfrZgrfQSnnnSnJRCglHpCwwHwpglDClFMw
|
||||||
|
SqJQnffJRnfQQVRhrQtrhnThcLhzNzHdTjhsTWzjdmcm
|
||||||
|
QJQwJMSbtbRgMQMQVZpCZsrrhpZBwrLLvs
|
||||||
|
qCNPGWdqhpphsWrB
|
||||||
|
DcNPNnqjdGDqjmPGGJRFMQmgtlQmQJCSgb
|
||||||
|
blTRbDnHRGGBwnGPCtFPWzVCDvFWtL
|
||||||
|
pdSJprqhhZSdqSdZNhVzZWtzLVgVPvzjLzWv
|
||||||
|
rrsqsmrMpPHlwTsRHn
|
||||||
|
mbNhgbRSLmTwswFm
|
||||||
|
vHjHBWMHBzMqWZVZBzHzcwwwdcFLcpLspdzwpwQd
|
||||||
|
HfMWMfvjWtZHqWDlhSnnnJNnbhslDb
|
||||||
|
lwsvPPnqlwwwsPcHTgqcRcSccmgQ
|
||||||
|
CVWBWCFpFzWfFjWjhNSQJJmcVcHRZJNTSc
|
||||||
|
zdhfzBtfLLtfFClbrDvsPvtPbnmv
|
||||||
|
PntVQbDnQHcDVvhtbtDhcbPcFTrrNfjqmmPTTZqMLZZMjFZm
|
||||||
|
lgJCpCFCSCGCpllWMfZqTNNZrMjrJTTM
|
||||||
|
CSzSwgFlzsGBzQcQhsnnDbVdtc
|
||||||
|
THzqvrVrWzhqhWwqhTbNNDRtFRmmpFDDVsFLLsdddF
|
||||||
|
MbZSSScZSGCJCjZlCjdPmpRmFLDtctdmFRsp
|
||||||
|
GfJQlnZjSMnllbJCQbClnZQrhNwwqhBzTNhrffqhqWhTqz
|
||||||
|
BdBdmDZHFFbrHHStPSRtPCzSRNDS
|
||||||
|
JGGpwqLJGMTLpLlMpqLhJtzCCSGQSPzNNczVVPVzSV
|
||||||
|
WwpllfslqfhffLwhfJpJlqlwdBmZnrdFHBFBBmNHFsFmdZmn
|
||||||
|
jZfQZnZfnbRfjCnfbSSmVpqmNmVpCqlhCqqPpP
|
||||||
|
MdJMwMvvLDssLtFMsMtLDsvvDRmmmPhWzWzphpmqDVzPDWNp
|
||||||
|
TsLdMrvRtLJtGdtGRRtFTBjSBrScnSZjnbcgQgHfnB
|
||||||
|
RZfmlRlWJmWLLRscrslJqvvMdVwmddvPddQPVDdDwz
|
||||||
|
GStFbFCbntbjNnjFhFvdHfhzHfzzQdMHwPdD
|
||||||
|
BSGpFbbjbNjnNNFSbRsLlWqgrZrfRgsBlg
|
||||||
|
ztHczmrmcNNzHsPSTwsPHSQPQT
|
||||||
|
CFCRjlvbClCjBdPDFQdwBsqn
|
||||||
|
llbRgjClJCVVMMCssfmNZWszrNgzGL
|
||||||
|
mmFldllVlmtdWFvPPFBcSSBW
|
||||||
|
DZzZGzZswQZHwQZjZzWWTSSvjSdvPvvWjJTS
|
||||||
|
DpQQggwzZGdmbCldgVgf
|
||||||
|
PJJvhqzVGbTFqzqbbGTlLmrtrZMnnZnntlJnrD
|
||||||
|
fNwRcQBCRNddNgLtgDnttqrMMtlr
|
||||||
|
RfRdNWQHcqHscdfRdGPFbFPpvpVWWzPzVS
|
||||||
|
DRgjZRRDggTfjfRvwWzHGGHPWDswvv
|
||||||
|
dhbmpcCmchgCpsGzWPdVGvWHwP
|
||||||
|
hpMMMpCQMnChFgNRQffTRrSN
|
||||||
|
gfqPCHWtPMMjCtffgjQWGLvGdZcdLLGZcLFGZBWG
|
||||||
|
pJTDsnnnvBjnFwvj
|
||||||
|
zJRpTbNrTSppRVblgbljMgMfCfbC
|
||||||
|
fGrGwqggtbVmtzbf
|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dVSjmdHrfGPddrQgstFgzsQfsMFQ
|
||||||
|
hvJJCCJDcCtwBVFQzzBD
|
||||||
|
RWCnTvWTLRnJJLJllWhTLSprVdNZVGHGNGGnrdGSZH
|
||||||
|
gvMSHFZtBBMBMFZHzjnqLsLGMCzRWWMn
|
||||||
|
QJmDrhbNDbJfPQhDmQPRLszRlnjCzzWqrRnlsL
|
||||||
|
PcJVhJbJJNcNDmfDmjJmbhTfBvpwVSdggtgvgSFZwgvtgpdZ
|
||||||
|
PBClRHHClRlFljllZSBBBllppVGDLpZVVVsGpmGcNDpGLL
|
||||||
|
MvNwnbMwccVsswDG
|
||||||
|
MqnNbzMMrQfnqtttqfQWQQnRdCSHgHPglRFBRWlHjWRlCW
|
||||||
|
lldwdfSBWphHBggZghFs
|
||||||
|
DjDbDVRzDmLRzRLGJjPssrLZPhdshFHrssTZ
|
||||||
|
mvddMzvmmDDvvwQqWftCfqWqfM
|
||||||
|
gpTTwNWGWMSMgJjnvpvvJbJppn
|
||||||
|
lQvmLFdfrQzRFctlrLdRLVPnhPPbVDPDfjnVbfhJjV
|
||||||
|
FLFqccvmmtcQtrmQccRFLlRLSSWBSgTWNwsggqMBsqWGHMNG
|
||||||
|
PjPtVQrPVjrVPLLDQVFLTTWWqbSZwRwzqwSbSbbbwFSq
|
||||||
|
lBnGJBnfflRRNZwbqb
|
||||||
|
HJMGgmfpRMHGGdgncJHLDjjtVDQctLCvQCjTtr
|
||||||
|
VvmvjRGwRwvhmhRvvvVCCTTJjfWqfDMMcJlcCD
|
||||||
|
NpNbPfpSnngZbbLMFJWTMlLFqJJDMD
|
||||||
|
bNSfdSHQZgVQzwhhvRmQ
|
||||||
|
MhmHcDhChhcPVMDPDPQdFhQHnbNpZbZnprnrmNnjNbsllbnp
|
||||||
|
WWqGCWSCzsGbbGNgjN
|
||||||
|
LzwqBLSvwJCLPVMVDLdhMP
|
||||||
|
mNVLLffSLVWdZCcFZCZrSbGr
|
||||||
|
glvcwszTlsRDrHQCZFCvG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r
|
||||||
|
HClCHzFzFBhmnjtQzMMSMnbD
|
||||||
|
sVnMCsdlMRcMFBGz
|
||||||
|
JvwwgrJDfgDmmggQrhNfhQQftjFrGRRtZFGBRZFHzjGcjrcj
|
||||||
|
PBJJvgDPNllPddVCPl
|
||||||
|
fmmRSnfnMnFSmMmmzTDSBFHtlJJqHJJqdHQdTCdtCCdt
|
||||||
|
WggGpNVVgWdwwHQtlGlC
|
||||||
|
hjbWppbLbLZLjVPPjPLSRRMvDlmSzDzBSnBFZf
|
||||||
|
nVttMPnPLjnJLjcnPVCjJJLcssfggBNlffgcNsWTcGcgNsBF
|
||||||
|
HQbwhmDrRrgFsWlQGNls
|
||||||
|
pZdbGzGrGpVttPLttv
|
||||||
|
LLbMrMHLDdWhmgbqqt
|
||||||
|
jGSQZQTpQGVVRSlQMQRljZmgmJBSvggvBWhJmJWvddmt
|
||||||
|
VjlQFGMVrFFrDrPw
|
||||||
|
DZVDwGZlJlVlwZVDzNdqfjMDnjqzNnWf
|
||||||
|
pmtpLRQFhSFpmpRgRtHNFznNdqWBjzWfnBjMWf
|
||||||
|
rHRrhStppHdJcGJrrssCsV
|
||||||
|
pgQqHwgPcPCddCjdWtdp
|
||||||
|
VfZGVFfNVhZhzjjjLz
|
||||||
|
fNNBBnGVNfBfRSRjBRQHJQTwJcJTgHPwTngr
|
||||||
|
MZdlzWzthMgrwmGmqZNqNs
|
||||||
|
VvJQJPVDBJQThwwNsRqsvRsHHm
|
||||||
|
BDQQPTnDDBQQBVfTBQPdFctzzdtztMMtnhcWcd
|
||||||
|
LjWjDShflZRRcZzfHH
|
||||||
|
srNwQPBsrVRhNmRGHzmM
|
||||||
|
rBdgQTrhdPndQTrsQQsrPwnTpLLCWDpSCLtCnvtSWpJjDCvl
|
||||||
|
gSlvDwCvcmcTQTFtRMjWHFVVHwtj
|
||||||
|
rbsphZZzBshGZssMffTVRFfFpWpfTH
|
||||||
|
GZNhZBhPBzTPNLDcDlCDCJNmlg
|
||||||
|
smZjGfvjbWWffQtf
|
||||||
|
dwRrdlVdDdgDbNtgcgQSNStQ
|
||||||
|
FdFVwdblFlzVrlwrTlndZHHZGhmLhhssjHhMjnjq
|
||||||
|
QFvQVFLLgVrFLBVgGhTtllPvmHRRGbTm
|
||||||
|
hDCCNCNCJNzWDZnqJDzSNCTnbRttHGRnccbPRtmmlmHc
|
||||||
|
qJshNMCNdVFVfsLB
|
||||||
|
FcLZZPFjdZcZMPcRjcRTgbpJlwbbTlmdTlGlwD
|
||||||
|
nrrNrHWBNSWvBqvvrhBqzStrgGnnmbwsbbJbwwJnmwmgJTlD
|
||||||
|
BCrrNvqWvSQPcCGZZRQQ
|
||||||
|
vPwcJblJzJbJcJFcwBSvJNdWRLtdsddGWWddWRWsMF
|
||||||
|
mDZmmDZDHVhfmjZgjVDfhTZHtsNptRsMntnWdsMnGtRntG
|
||||||
|
mhQrQDDhgqTTNfhmVQVBrPlBczSJbbCbCCPPvb
|
||||||
|
ZjbjLlbZjGqsgJTfHggrVvlB
|
||||||
|
tFDRFRnMFnnWtDdMdDRhzHfTJhJhffHvHTBHTgcfJV
|
||||||
|
nztDtdWzCCMSptSdFRRswZjsLbjwZmwqwGqpQV
|
||||||
|
vnvmmVnmVbrBJlzgWQWVNFzNHV
|
||||||
|
MwSjZhSwPjMwfDRzgWlNpWvHlgNNNP
|
||||||
|
CfSZjSfftwZDChDRSnccnrvBbbGrtBvctr
|
||||||
|
LCBRQRBQwRrCVLVWSrCSwCptzvhthvGGhdHzwppTTddv
|
||||||
|
mFnJJmnmFFFfPLNNmqqNJDpGnGtbHTtHvhnHbzvHvpGv
|
||||||
|
lMMPLqDmNMVSjjgMCS
|
||||||
|
zzPzbLjHLjfQPQHwwjddFNsNSJjDMsdNMFsC
|
||||||
|
BqqtmgDhcqdSFCdsqddF
|
||||||
|
GtcmrvhgcZlvZtBhtVgrvrvtnWzDnQbfnwlfWWRHWbbwzHRL
|
||||||
|
JfWHWZcMMdDLMPjRnCJjRbFgnblF
|
||||||
|
ShtBTSmBhTtqtfmqSTNvmjVjnFbFnnlrlqgCnrFnVg
|
||||||
|
vfzTTthppmdzPLHLWdGZ
|
||||||
|
tdvrvGgGTSScnHcjcg
|
||||||
|
zLLVfzPPcDZnPjSPpD
|
||||||
|
LfffNFLNlNbJwrctthWqNdNq
|
||||||
|
NdjJtfVNZnnFFdtfGfFNcvpbMDbzdcTbbzpvmcDR
|
||||||
|
PHMSHCHHWrRCvzDzDChT
|
||||||
|
BqPWSHwllSQWrLHQHPqlBBNfttZMjFQfjGtZtNjJJjnN
|
||||||
|
CpZtMCMQQpCVWjMDVjPVQsWWqJJhbTcddPlfhTRqchcJblhh
|
||||||
|
NwDSGNmGRccqNJfT
|
||||||
|
SBSSmgrrgGHnvSzwGVWDCzMCpLZtMsstLM
|
||||||
|
sbjHQsBlBQrrGjQjBqCRSnSCpnfngLnFhJngFfSP
|
||||||
|
zHVctHDcZtdJffnPpcSpFn
|
||||||
|
ZdwNMztdvzVdrqblvWsqHvBR
|
||||||
|
jPdjFPSbVDMMbqZzQWzQ
|
||||||
|
hFRrJlpprGhtlJGQzmCRmZBWQCHRQR
|
||||||
|
vThNplJpNhltNNlvcGDvwVFgnPwvSgPSSfjS
|
||||||
|
DhDTPQpTDmQbDQrrrWtWPJNNrrsJ
|
||||||
|
qqGjgwCgVRjMSRwMMGRGqjwvsNJJBZtrstvNBvHWHJvL
|
||||||
|
VqqgfjzfgfFGVjRggCGznhlbTpQchcshpdFlnDbn
|
||||||
|
DpTQTBbCZQVJQZJjrFllGdlvMPlMLqGBGvLl
|
||||||
|
hmnWHWWNzzmHsmWRlGGpdLgLHGlqvgqg
|
||||||
|
RzcWRhRnRnfmswfwtzzRWrDTrrFCQTCpQpcCrjjQCp
|
||||||
|
HLvpHvGcBTDFznvfqT
|
||||||
|
hCPQbPZPbjSbwwjCPChSClJJfzqTggTFDfsJngDg
|
||||||
|
StqmmZbdqrQmhQrrhZWcRcGBpBHWVcLctMWp
|
||||||
|
dNnRNbRdb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BmzMLHHLmGHNTTS
|
||||||
|
hQhwqVjQwsdggrZZCWVl
|
||||||
|
VjfnQgVQjblChfjVJlbzLtrSLlTGtztHTtsTGH
|
||||||
|
DDqWQDQMWmDwWNwcqdWvpSrtLpLsptMprMStstMz
|
||||||
|
vQcddRdRvWcwWRmmmmddZmmfVnnngJJbZnCBnBhhFbhCgJ
|
||||||
|
gVgDnnmJdQVdJJgtgDjBsBhsBSPRSRRSSwccSbSqwPcCPcSC
|
||||||
|
HrQHlHFpQfTHzzWzwScPPCRfLbPSfCSR
|
||||||
|
TTQlZNTzlZNMWvrZMlpnhnVtnDDnVNtVJnjmhg
|
||||||
|
MCmmssFnZJcNNszfpvvrpvJzvwpp
|
||||||
|
BRRRWQWbSRGGRTTtZHWSqTrvDfgfdfrrwrDgfbvfzfrd
|
||||||
|
jRBhWRWTSRttQBZMNchNCsmFMchP
|
||||||
|
GBDncllqcSlNFZWBFWPjHVbw
|
||||||
|
LQphJlJzLCwPjHbpHZvV
|
||||||
|
hzCMJLMzTsrdrszQCCCTCQCDlqqnNmggqfGmgdmGgcmSNt
|
||||||
|
hFVVbqJsqhcnBRTRGBTh
|
||||||
|
lwdDpmzdNznzZBgGRRjR
|
||||||
|
HdmvNvSCmDmwNDFrMJMqJFCRfsbq
|
||||||
|
ctnbTcFTnbwSSfrrMLRhpJLMRdpwdJJR
|
||||||
|
vdGCVBmGVHPLBRWhpRLJJZ
|
||||||
|
VmQPHqvsPdlQsVHDftnlFTbffnbttfTF
|
||||||
|
LBJZHrhLThHddcMLVtcMcL
|
||||||
|
CPMNFDDMpGqFjjSPDPDqdvmdtQgVQQcQWcQgQQsj
|
||||||
|
DzFDFMRSFPSGTJJTJBwwRhBw
|
||||||
|
dpldqlqlRppFTHpbjbnLRLVnnGfjtG
|
||||||
|
NNJTcmhzvJQNgMJBwcGtjtGbttfhtsGGnhnt
|
||||||
|
rzcwmgvcvrBNvvmMgvcBzwHPCTWWprqPHqTFWdPCWDTF
|
||||||
|
BNllDRTNqDNvNDDLBcDvBCLVJrVdJdtrnrCHggtrdd
|
||||||
|
mppFMFjpMFZQZQGjFCdgrCrCdrvVGtJJCC
|
||||||
|
PZsQmfPphvPjSsjmPjfZllBwcNRDNcDqNNWbTclS
|
||||||
|
fjqZBSDSDwwsQwCDND
|
||||||
|
rrdMdjVWtTTPslsslFLTLCsJ
|
||||||
|
rvPWbvcmHjmdPbHvrvBHgqRRgqHGgfZGfHRS
|
||||||
|
ggTQgsgwFrTrggbMTvSdmjfCmmQDcmqjDjmc
|
||||||
|
nLZnRhNZnnNHZhZVStCcDqjcqmjSjH
|
||||||
|
RWGNnhzBnJJRRWNRBNZNLZhFMTFPvrTrTlsggPwSlFMWTw
|
||||||
|
RNmnPRnLGcQmzBQpHHjTltjtlfgspbsq
|
||||||
|
CZvCJwZMMCCMdFVcwJJsgTTHfsTlbfbgbT
|
||||||
|
SSVFhWCZdSCcWCcWdrvhzmnnnLNGDRDNzzLNGz
|
||||||
|
jPwfPwNfFpFNQpDjdMcjcrdddDHD
|
||||||
|
tzsRsGRLzhLhvqvhHMlqqV
|
||||||
|
LRBnRBGSnBSGsGSGmGtBJCmnNWZpPpTNPMwQMPNJFZTTNwWT
|
||||||
|
PCrStRPSPvZQcZPvqvfjSRWFFNFJFLZTTJTTVZFFGLFF
|
||||||
|
DlpBzBntHDzhlpGJVHLwTMFLVLTL
|
||||||
|
gptBBdgzpsBbpQvvPQPRqrdcCC
|
130
day03/src/main.rs
Normal file
130
day03/src/main.rs
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
use itertools::Itertools;
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
|
fn read_file_to_string_list(file_path: &str) -> Vec<String> {
|
||||||
|
println!("Reading file {}", file_path);
|
||||||
|
let contents = fs::read_to_string(file_path).expect("Should have been able to read the file");
|
||||||
|
let mut splitted: Vec<String> = contents
|
||||||
|
.split("\n")
|
||||||
|
.into_iter()
|
||||||
|
.map(|s| s.to_string())
|
||||||
|
.collect();
|
||||||
|
splitted.pop();
|
||||||
|
return splitted;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
struct Item {
|
||||||
|
name: char,
|
||||||
|
priority: u32,
|
||||||
|
}
|
||||||
|
impl Item {
|
||||||
|
pub fn new(value: &char) -> Self {
|
||||||
|
Self {
|
||||||
|
name: value.to_owned(),
|
||||||
|
priority: Self::get_priority(*value),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn get_priority(value: char) -> u32 {
|
||||||
|
let char_value = value as u32;
|
||||||
|
match char_value {
|
||||||
|
65..=90 => char_value - 38,
|
||||||
|
97..=122 => char_value - 96,
|
||||||
|
_ => char_value,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Rucksack {
|
||||||
|
duplicates: Option<Item>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Rucksack {
|
||||||
|
pub fn find_matches(front: Vec<Item>, back: Vec<Item>) -> Item {
|
||||||
|
let matching: Vec<&Item> = front
|
||||||
|
.iter()
|
||||||
|
.filter(|front_item| {
|
||||||
|
let matchfromback: Vec<&Item> = back
|
||||||
|
.iter()
|
||||||
|
.filter(|back_item| back_item.name == front_item.name)
|
||||||
|
.collect();
|
||||||
|
return matchfromback.len() > 0;
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
let item: &Item = match matching.first() {
|
||||||
|
Some(a) => a.to_owned(),
|
||||||
|
None => panic!("No match found in rucksack"),
|
||||||
|
};
|
||||||
|
item.to_owned()
|
||||||
|
}
|
||||||
|
pub fn new(value: String) -> Self {
|
||||||
|
let front_values: &Vec<char> = &value[..&value.len() / 2].chars().collect::<Vec<char>>();
|
||||||
|
let back_values: &Vec<char> = &value[&value.len() / 2..].chars().collect::<Vec<char>>();
|
||||||
|
let mut front_items: Vec<Item> = vec![];
|
||||||
|
let mut back_items: Vec<Item> = vec![];
|
||||||
|
for b in back_values {
|
||||||
|
back_items.push(Item::new(b))
|
||||||
|
}
|
||||||
|
for a in front_values {
|
||||||
|
front_items.push(Item::new(a))
|
||||||
|
}
|
||||||
|
Self {
|
||||||
|
duplicates: Some(Rucksack::find_matches(front_items, back_items)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("Hello, world!");
|
||||||
|
let stringlist = read_file_to_string_list("exampleInput.txt");
|
||||||
|
let mut rucksack: Vec<Rucksack> = vec![];
|
||||||
|
for string in &stringlist {
|
||||||
|
rucksack.push(Rucksack::new(string.to_owned()));
|
||||||
|
}
|
||||||
|
let priority_list: Vec<Option<Item>> = rucksack.iter().map(|y| y.duplicates).collect();
|
||||||
|
let sum_of_all: u32 = priority_list.iter().map(|x| x.unwrap().priority).sum();
|
||||||
|
println!("Single bags: {}", sum_of_all);
|
||||||
|
let mut group_bags: Vec<String> = vec![];
|
||||||
|
for (a, b, c) in stringlist.iter().tuples() {
|
||||||
|
let group_bag = [String::from(a), String::from(b), String::from(c)].join("");
|
||||||
|
group_bags.push(group_bag)
|
||||||
|
}
|
||||||
|
let mut groupsack: Vec<Rucksack>=vec![];
|
||||||
|
for string in &group_bags{
|
||||||
|
groupsack.push(Rucksack::new(string.to_owned()));
|
||||||
|
}
|
||||||
|
let group_priority_list: Vec<Option<Item>> = rucksack.iter().map(|y| y.duplicates).collect();
|
||||||
|
let group_sum_of_all: u32 = group_priority_list.iter().map(|x| x.unwrap().priority).sum();
|
||||||
|
println!("Group bags: {}", group_sum_of_all);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
#[test]
|
||||||
|
fn item_construction() {
|
||||||
|
let lower_a = Item::new(&'a');
|
||||||
|
assert_eq!(lower_a.name, 'a');
|
||||||
|
assert_eq!(lower_a.priority, 1);
|
||||||
|
|
||||||
|
let capital_a = Item::new(&'A');
|
||||||
|
assert_eq!(capital_a.name, 'A');
|
||||||
|
assert_eq!(capital_a.priority, 27);
|
||||||
|
|
||||||
|
let lower_z = Item::new(&'z');
|
||||||
|
assert_eq!(lower_z.name, 'z');
|
||||||
|
assert_eq!(lower_z.priority, 26);
|
||||||
|
|
||||||
|
let capital_z = Item::new(&'Z');
|
||||||
|
assert_eq!(capital_z.name, 'Z');
|
||||||
|
assert_eq!(capital_z.priority, 52);
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
fn find_matches() {
|
||||||
|
let test_rucksack = Rucksack::new(String::from("aban"));
|
||||||
|
assert_eq!(
|
||||||
|
test_rucksack.duplicates.unwrap().name,
|
||||||
|
Some(Item::new(&'a')).unwrap().name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user