Compare commits
37 Commits
c5f772054e
...
master
Author | SHA1 | Date | |
---|---|---|---|
976cb3651c | |||
5d522dc0f6 | |||
1affc44c28 | |||
40aae04d70 | |||
0d60232b6f | |||
a194cb2d6c | |||
ccc4301d62 | |||
c3437af12b | |||
0b0e9bc0f4 | |||
c7a6c47f0e | |||
e39887f0c2 | |||
43ec9c7d2f | |||
da257be7a7 | |||
729308742a | |||
6a0ed15470 | |||
f2eb9929d7 | |||
efd1fb5ca9 | |||
68b71fe794 | |||
6fe087abb2 | |||
2cbcc69ff3 | |||
176149a167 | |||
017345beb6 | |||
bfdd227743 | |||
82f4503b3e | |||
343d09f460 | |||
6fc5cf34a4 | |||
73c5cb9e62 | |||
b4ec1ca428 | |||
0c6b8a5106 | |||
5ca5930ae8 | |||
33593739d8 | |||
72c1ab9f9e | |||
e802d8dd91 | |||
ab9d8fb2b1 | |||
8ea82daa5c | |||
b61d9951a6 | |||
79ff128e33 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
target/
|
0
day1/Cargo.lock → day01/Cargo.lock
generated
0
day1/Cargo.lock → day01/Cargo.lock
generated
7
day02/Cargo.lock
generated
Normal file
7
day02/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "day2"
|
||||||
|
version = "0.1.0"
|
8
day02/Cargo.toml
Normal file
8
day02/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "day2"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
2500
day02/input.txt
Normal file
2500
day02/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
29
day02/src/main.rs
Normal file
29
day02/src/main.rs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
|
fn score(line: &str) -> i64 {
|
||||||
|
match line.trim() {
|
||||||
|
"A X" => 3 + 0,
|
||||||
|
"A Y" => 1 + 3,
|
||||||
|
"A Z" => 2 + 6,
|
||||||
|
"B X" => 1 + 0,
|
||||||
|
"B Y" => 2 + 3,
|
||||||
|
"B Z" => 3 + 6,
|
||||||
|
"C X" => 2 + 0,
|
||||||
|
"C Y" => 3 + 3,
|
||||||
|
"C Z" => 1 + 6,
|
||||||
|
_other => 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let input = &env::args().collect::<Vec<String>>()[1];
|
||||||
|
|
||||||
|
let mut sum = 0;
|
||||||
|
for line in fs::read_to_string(input).unwrap().lines() {
|
||||||
|
sum += score(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Sum: {}", sum);
|
||||||
|
}
|
||||||
|
|
33
day02/src/main1.rs
Normal file
33
day02/src/main1.rs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::BufReader;
|
||||||
|
use std::io::BufRead;
|
||||||
|
|
||||||
|
fn score(line: String) -> i64 {
|
||||||
|
match line.trim() {
|
||||||
|
"A X" => 1 + 3,
|
||||||
|
"A Y" => 2 + 6,
|
||||||
|
"A Z" => 3 + 0,
|
||||||
|
"B X" => 1 + 0,
|
||||||
|
"B Y" => 2 + 3,
|
||||||
|
"B Z" => 3 + 6,
|
||||||
|
"C X" => 1 + 6,
|
||||||
|
"C Y" => 2 + 0,
|
||||||
|
"C Z" => 3 + 3,
|
||||||
|
_other => 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let args: Vec<String> = env::args().collect();
|
||||||
|
let input = &args[1];
|
||||||
|
let reader = BufReader::new(File::open(input).expect("where file?"));
|
||||||
|
|
||||||
|
let mut sum = 0;
|
||||||
|
for line in reader.lines() {
|
||||||
|
sum += score(line.unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Sum: {}", sum);
|
||||||
|
}
|
||||||
|
|
4
day02/test.txt
Normal file
4
day02/test.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
A Y
|
||||||
|
B X
|
||||||
|
C Z
|
||||||
|
|
7
day03/Cargo.lock
generated
Normal file
7
day03/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "day3"
|
||||||
|
version = "0.1.0"
|
8
day03/Cargo.toml
Normal file
8
day03/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "day3"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
300
day03/input.txt
Normal file
300
day03/input.txt
Normal file
@@ -0,0 +1,300 @@
|
|||||||
|
qFdBBvtHHfvRlfvsqldvqjPpQmnQmjnjjjTRTLGRNG
|
||||||
|
ZCWhhCsJCzSJzSbzgsmPTGNNPPNGjgLTLjgn
|
||||||
|
WJZsbJMwJcszJcScwhVltFwBFBlqddvFdHDfqq
|
||||||
|
crtTsGTtqFThGQGCrsjTwdNJwpRdnJJwffRClpSf
|
||||||
|
PWVBPVHLvHHVgvZWBzmPpnfRSJJRQnSRflRPSNSl
|
||||||
|
gmzBzDgzmZQWLDLLgVmDrqGhsscrqDMGhcqtqcFr
|
||||||
|
HsbcdVrsbVbcLfPqqQsqqtPj
|
||||||
|
mMBFzZRnmFMRBDnDFBGZDGdDqLjtdQtPtgfPfttgtqgq
|
||||||
|
BZvZZdJMBFdJhSvhbhchcHll
|
||||||
|
GNRSqRfcNTpfGCcqjfzBpDQPWBzgDpQsPWzW
|
||||||
|
rrSdnVHlbMdLdBDzgtBtBmQt
|
||||||
|
rbFwwnLFLFwlMLrFwFhMVLrGNSTfZTRhfTqjGJRRZTCNcf
|
||||||
|
QWTnQCnWNNWmTnSPQwmqDbcscbpcjPjVPbrjpq
|
||||||
|
vJhzZNlNNgdzgzJdlGzHHcHDpjsHqrvbVrbvrD
|
||||||
|
RzRdRlhLgtCwCWSLnN
|
||||||
|
SFTJFTTwTVVSJBnSTdvNNfWbZCZWNZCNNhBv
|
||||||
|
srLrcHDcsjtLcLLcrLctjlcvbDNhmWCvNhZWGZZhNvhZmb
|
||||||
|
rclgtMPrrSgVTgJCng
|
||||||
|
DbrhDzcDffbzNbZvZWSSqSTNSVWv
|
||||||
|
gCPltPmCPglFnPFwtGPhGPwTCTdZZWZVRvWqdRqVVdTdvR
|
||||||
|
hLBhlmlstcffBzrpfj
|
||||||
|
wFLLmhMfwZLDwmMNRhZwRLDvJgldbJHPdQvcQHHJQPgH
|
||||||
|
bjrVrTSSJdQHcVll
|
||||||
|
CGCSsCCBpspBrqbSttpbqWmWZRmfFRZhZMNNLFqFLm
|
||||||
|
zWGjjBHGjzzTWMjhtDDWtPPlJZPJpvqQrmZTqQQpmr
|
||||||
|
RFbVLcBVLRcRVcCsCCqvpCZqmplqQJmPrlvQ
|
||||||
|
FLNRRSSRgScSVLLLNdFdwjHjnftBtGMgMjzHgzjWjj
|
||||||
|
znVSqnqbqzSbzTHqDDZmlcFcnhDMnDmn
|
||||||
|
LtjsvdvLJdjfFwRRCCMlChwCpMcclCcZ
|
||||||
|
LgvjjfjFQVgNTgWq
|
||||||
|
SJRJRFFCMSsGRMMwtZJRCVTgqgTVgTBCVpjTjmmWlB
|
||||||
|
ccvnnpnDVqTcBVTV
|
||||||
|
vPHprdHdpnzHSMsSrMRZJGws
|
||||||
|
GddGrcGNHnGvnCHddvCSWqTSWsTwTWShbHlhhb
|
||||||
|
gDPzLRVZgQfpRRFQDDVFDfzhSzsTBqqqnqbhnWTSSlST
|
||||||
|
QVFfFgRQQgLtgffZRfpFPfntjrcrjCmtCdMMmjMdJJJNtm
|
||||||
|
jjmNcpGCNmDqqsBfnZnGGGRLsZ
|
||||||
|
lrmlVWlQQtWllgtbQVrWBnZsJgsRLfZLhZBBBffL
|
||||||
|
rWMVQtrFlbFlSSMHVSdHHNHdcdDcddzppzzm
|
||||||
|
bTpjpjcVTLmphbLppJwqzqwJLqqzzzgRLJ
|
||||||
|
sdHNbrvNHrqPvZZZPRww
|
||||||
|
bNQCrCNtNsSlhffhVhpVWFCW
|
||||||
|
lpNnpMMZZDbNbnBjcrbjvScFmbGj
|
||||||
|
wqhdqVqdscrjdLsv
|
||||||
|
HQftVqWCfhwqtCCjWwfqzzVPZRJQgMlggZMMMZTNMNTnNRTN
|
||||||
|
fvvGbFtVmtTwgtMT
|
||||||
|
WcCcClzPCCcczJJScPWWZzBDmwbhBBHSghgDDMTHMDBD
|
||||||
|
nWPljWzZWnbcbRsNFjFFdFdVjFsj
|
||||||
|
NQrcLNmQGRfGLHHLZgbbnpjZJJJndbgnlv
|
||||||
|
DWtThDWtzzhltWTwjbdpvjbgqjgg
|
||||||
|
VtSPFWtBPBFSFBWCStshWBmlRfHfMRcfQLQLLlmCrCcN
|
||||||
|
pbmwqJnqSJVwwDPCjZZzrZfD
|
||||||
|
QtssBTvNdNvNtQvQGpGhdjPjDjczZDfjhgPPDcgjgr
|
||||||
|
GltptQpMGNNpRWlWFVFHJFHLWH
|
||||||
|
ZLLsDGGVhZcQQLhrLshrVFwHnWqJnWMnJJJnqfWfGn
|
||||||
|
jMlPdTlPlgCgFpngFWFnJfpw
|
||||||
|
TlTNbdSSTSTmTjPMTCdBPjBMrLDczsZcNrDhRNDRQRLLRVVz
|
||||||
|
HDLpBqDVVTvwGDDNRT
|
||||||
|
PlVWjfhsPMMmWtlFNTrhrrvCCCTNNbvw
|
||||||
|
lsglfgVJmsfMjJfSqSzdZnLgqcnLnp
|
||||||
|
pfCDJWBpfDffpJLgQJzzVzNrgNgNgNhNzmVr
|
||||||
|
ZnnGZbGTPZnsnRFdTlbrwdrNzrrmmWwmwVwttH
|
||||||
|
GbPGRvTnZljWnpqSMMCjqJQSCf
|
||||||
|
ZgnFgwggznFrfrwfHhNMMr
|
||||||
|
pctLCLRhPHBLMLWfBL
|
||||||
|
JJcdJcQCCJmQJppmlgndnFslsVnsvghZ
|
||||||
|
WpMgTppWGSWWJmJDpJcJJhqm
|
||||||
|
zZzjZNHvNjPvNsbZLbRLzsPcqhVJSVttdwhwmdRhtdJRVd
|
||||||
|
sLbvvCZCPSSSbbPfNlQQTQGBllCTnMnWQn
|
||||||
|
fwbwswddwSbBfDBggMBPDPhHcPWDmhHhmWnWPC
|
||||||
|
FQFlzLCzQTlrTTzvltFqFrmhPHjnhhnnchcJWcRRmRRq
|
||||||
|
lpLzlFZzCltrTNlTztQLZfSMGBNdSBVwbBNVSMSbVs
|
||||||
|
FMmgbTFdgLSgFQdjrRPrQBPDdj
|
||||||
|
ZqqWRvsfGrrPvvPC
|
||||||
|
wZzwnqccRwRNNpRSMztSMMFbgzLTFS
|
||||||
|
qTwBPfTfqQDMDrssHdvtRHccHMjR
|
||||||
|
gWSZGWzGFhnFFgnhNsRHtRdsVjZcRjHs
|
||||||
|
jgplhpJJFgnDrrwfqprwDP
|
||||||
|
CWhMSRfWhVVnRSZnVVdsLQqQMzGqLBvGMQqczv
|
||||||
|
PHbpNwrjJplttvcclLlQzzDszc
|
||||||
|
NrJbJrFNNJNPrmwrtbjtNmCfSWfWhSZZfSWCsfShfFVR
|
||||||
|
VLhRPLGLRPRSStRRLwfGqfmDwbmqbqqDlD
|
||||||
|
rBSFvppnzTbwDwlDcFWm
|
||||||
|
MJrnJTMvMsrTsPtshRNPZdSLhL
|
||||||
|
BZBrRCrnCQBBnZfGqhGGMMRcthMhMG
|
||||||
|
TLjsCdDCPTvNssjdsPsDgsgqGcPHczchtHczWzPWzzlWhG
|
||||||
|
gsTpsdNbvNNjNSpsNDTsmCnSVQFmSFwZnQBnmnQQ
|
||||||
|
llbsNsWrmbrGbWCNtBjcCFBzQFZBCFjF
|
||||||
|
LdSpwgdqSgzwJdRdLMRHLjQQjHjFHctjHBDTZj
|
||||||
|
gSppgpSJMhpzwrhblfbhhlWlnW
|
||||||
|
DwhTvvsJZWsBnDzPpBLbFp
|
||||||
|
GHtNGRGNdzbMBBtmBt
|
||||||
|
NljlCSVSHdjGSQRGlCQSCswqfWzhZfTcfzcJvshJ
|
||||||
|
lmsGNFsDGqCbFQBbffjjwpzptw
|
||||||
|
hRQdvdrvrvSngWnvnHrTMfzfzRtftzwVTwwpzB
|
||||||
|
HnSSWrvLJvWJGFDsmFLPDFcQ
|
||||||
|
bwwpGphpLghpTvpWphvJlFLJqqltjSjVlSStSR
|
||||||
|
cmszZdDdBZzcNcDCDcNsmNMcqVjMJStFRJltVPVrlVPjVJll
|
||||||
|
HcdmcCzzzQcHNcsCdpnGnhwGgnRggHvbbR
|
||||||
|
CfMBbwBGbMbDCFrDvhFFDT
|
||||||
|
mjzRjjRdSmjPnzFZgnnrTT
|
||||||
|
cmSsVcHjLHTwMfLBpBpBwM
|
||||||
|
whqqfZzgHvhSzzVNVDbpDbmbVbNpJD
|
||||||
|
GcQFntGTCCcCTMCTGBlJsJsDDWpRbWBsJpNS
|
||||||
|
FnPcrGFFdddMnCnTqgqgqPHfLjLqgSzz
|
||||||
|
zMSzzjssFdGnszRtNftqqwFHbbZw
|
||||||
|
RRPLVrgrwHqBqgwt
|
||||||
|
rPWmLCTCQlCQQmmrWLrQShJshhzdhhJjcSjlzRds
|
||||||
|
lvgvCDfPqLHppqpCCDJncbntttbBtBBVHjwtrB
|
||||||
|
TdddszSQsWcngjzVbcVZ
|
||||||
|
hRWsTRTGQhNRGhRTFSWmlpgfqlvLmplPqvvGgv
|
||||||
|
LbWFLQdWWPwWSjSHPHRfppHHDRpggR
|
||||||
|
zmqqNNzlzmnzzNCmVCmtBzpfGsfpBgDgspprcfcfsrRB
|
||||||
|
qNNVNJtNmmmNzznVJzvCTDZWhvZZjZFbWQQhFhbZSw
|
||||||
|
DjdHqJVVhHVZjhDHPWtDtZLFBRBFmSRTFSbwmRRTffTTJf
|
||||||
|
NNznnGlgMQsnQzNclzpfSRSMRmfPMmFRwBwB
|
||||||
|
vzrcGcNcPPvHvHPt
|
||||||
|
wLCcmZwWTNtZNdMSMGSCnJGGMB
|
||||||
|
RFbHsPhVvFPRjlshhrnQnGjQGSdSqJfqnQBM
|
||||||
|
HhzVlFHhPwzScmSTgL
|
||||||
|
TNlBhDNvNBFpJgpPPpDQ
|
||||||
|
jjfCdCZZqsCZsbdqPgFGGMRzSFMqQMRS
|
||||||
|
jnWPtWssCtWcmZbbtstvnrrvhVBhTNNhBHlBlL
|
||||||
|
DZwNWPDzPVWbJngrQjrNnrQcMg
|
||||||
|
GRRfttLBhhvTvmLmFcFcgFFSnjWrnsrG
|
||||||
|
TLthBWtTRLHqhlLLfmhBqVPDJVdPwzJCPPZHwdDdVd
|
||||||
|
GGVhrVSMQwQqfVssVvnWFgvgWn
|
||||||
|
jtlcRBBtQRmpWsjzFCvzWnvF
|
||||||
|
QPcRbpppDmNDtPPblZMfhZdDwdMrqSSGrq
|
||||||
|
ZRrdtBdQvQsWnnfWFZsF
|
||||||
|
bJLcMzNDLbMgwfnGMWFv
|
||||||
|
lpvhmzNDmDmlNbzbmrVVPrHRCPHQBVCP
|
||||||
|
rZllQrsRWrlQswccMVbGbVbTdcQQ
|
||||||
|
NtJCntLSHCjznfLTcGGGqWMdWM
|
||||||
|
jCtzzSFthhSSSjPJrFDlvWrlDZRpwpRZ
|
||||||
|
mQmbLjbrLQjLmTtwwWBTTvWjtt
|
||||||
|
BHSqdHclHHNFlppNqWPwfwDvTfDPPtCw
|
||||||
|
ddSGMGHcdcMhMZnBbmbZmgGJJg
|
||||||
|
lvvBzvDnlzjfPnfjnQPlldRbVbRqbqqCgsqqVpQQgVqc
|
||||||
|
NNFtGNMtTNFmJNGNZtZMwVRTTcsCpVTbbgCbgRhscp
|
||||||
|
FGNGZMtNLWmmJWGFWJGLSNtPrPnBfDzzvjnDBzpnvDBLnv
|
||||||
|
fwvQRFQvQqwpwNJrwN
|
||||||
|
BstDnBjhjBhnshSptpJzWqNppbfr
|
||||||
|
CsDjCdZcBCDcjnfDHfhnfggZMGlgQVmgMTRmgVGMMl
|
||||||
|
MwlBVqVlsgnmzwJsvjhWZhGPvjvRRWzG
|
||||||
|
QNQpQpftHdHHCHGfSpCrQNdSrDRDhchhjvjcPrRRWrPvhZjv
|
||||||
|
LtLSCTSGfHGdGwswnqsggssTqV
|
||||||
|
qDDCHjzjznTvWshZQWfnZZ
|
||||||
|
PFFmmNMMtNMVFtczcFPJNrLhZwQZQsSvvSvWvGQQJQssss
|
||||||
|
tFzrrPPNNFlzVrpRTpblRDqjTpDC
|
||||||
|
DWDrrBdpmdpBrCgDthdtfcHsqJsCqscqwfsjzHcq
|
||||||
|
TNLNFNSTQNQTSnlMcczVJjVzsqLDDfJJ
|
||||||
|
TFPZQRvvlMSPPtRWDtmDRWrBGr
|
||||||
|
LWGVZdrvWdpLGWRsjPMsHmdHdHldlj
|
||||||
|
zJzznChzzzCSfTgMhCPDmlDCbmlsmjDDQj
|
||||||
|
nSTTJhJtnShNtzwhgNrGRRWZZRvMWMtVrqGp
|
||||||
|
PbPmtNmBbPlqBvqlDJBT
|
||||||
|
LpGVDzVpVZqqSTvq
|
||||||
|
pMnWGLRLRppnGpGndrGPtgDCjMPmbPgCQmPPNN
|
||||||
|
sqcZcbZZpcZspcCCRMmznWGWdLWhwDRGTTWggT
|
||||||
|
NjFSJgVHrvfVtrGzWdSznDwLSTLn
|
||||||
|
jFrBNVVjBFNvHrFHBlBFFpMslPgPcpMPmcQPPZCgpP
|
||||||
|
frddqsThtsTfTbPcvhsrbsRLpRBNRpmDpGmRGcRNLpGp
|
||||||
|
QWJHCJwWzlHZQZHQCJJRzRqnLDGRGpnGBRnNDN
|
||||||
|
CVwHCClJjQgWCZVZQgMwSdthjrqvrSPPhdbqtPhs
|
||||||
|
TvdphBBhhhCgdLNNJJJLWz
|
||||||
|
fVcsqRVrPcnJWgDnJN
|
||||||
|
JlqsRJtssZwqwVtPwltRPsHHbFTwTFbpjHhQjTQbvpTF
|
||||||
|
cQSnPDDQJGNzwnNpZb
|
||||||
|
RHDrssVRDHRgsRFHRlrVwzzpNGZlfZdppZdwGNZb
|
||||||
|
sHCHtDgtCjVVLFChqPMhBCMcSTqB
|
||||||
|
hdbQbqcCCQcqFbCbVdcWCQQlRMBtGlRHBtBMpHhpHThZMR
|
||||||
|
LLsSLLfgJPrgPnssnmlZtlZpHGHVGfZVtZpl
|
||||||
|
PvmvgmvvnzmrSsSLJDqDNzqFDQdDwzWWbV
|
||||||
|
HNNjnLbpLGHvWJDhdWWPpWDW
|
||||||
|
lVcSNgcSVclhRlPZPRCDCR
|
||||||
|
cqmSQrwwrrVSrtQFqVNmFwjQnvjHzBbLLGjfjzHTzvnH
|
||||||
|
QmvWVppPHQQvbbvmSHSpPzfzwnWMTZFFzwFMCzLnwT
|
||||||
|
jGBljlNNjgDtGDrNjjtjqqDRnMzRLnFzCFnMfRfMzCnttF
|
||||||
|
jqNrrGdJcdgLjqDqBrDQbbmhdQQmmpPbphmbVv
|
||||||
|
ZHQCggVHHRDWvbfjGptVtLvL
|
||||||
|
nnFwnwrDDMShnhFrFLLLpjvPlPGGtLGb
|
||||||
|
dcNSMhrrTDCBCsWgCTQW
|
||||||
|
HqDDLGtDdCnhfDnwnV
|
||||||
|
PmlJsJTPlbdBTzTnzhnnCCWWzV
|
||||||
|
lSPjMScggsScgjSMMbqHLFGrRLGHRZZtdrcG
|
||||||
|
ZVVtNNppdZSdLtCPqnHhqJJFtb
|
||||||
|
zgwwQBfwmGgSrDfgrrGBggzHCnbJbqbCJFnqhHBhnHHCqJ
|
||||||
|
rvrzfmlRrgDgmrzfggvwzvdjjcccLjMjVcVcsVLjVSZR
|
||||||
|
dppcLRHpphchhNhSddjzHzWQWQLtrMsrWQCWCsMZssCZ
|
||||||
|
JGfBfJJfBqvGVlVbDBwDBDBfZnrQsMQtssMttssDsQMWZncn
|
||||||
|
qPVwlgPBmjpPhcmS
|
||||||
|
zGPnzBgPzPnPlHZlDDHnZBNCvrtcjcjmMcFzNcNFmFdc
|
||||||
|
qQpfsLTTSspqTfJdmdCtMjdtjvJcmr
|
||||||
|
bfQqqSrswLLrfpLTqprfTnDVDVBBbgHPDHnhDPgDbV
|
||||||
|
JssTnsdFztZLdNJnNtTsLNZGqlbGFBqrGMHqHBcFBqMFMH
|
||||||
|
CCgSfgPSvSfhpShSRppCdfrlqGHGGcHmclmqbbqbqlPc
|
||||||
|
wvVSVjQSSQhRVvfQChvZZsdtJstjLNLZDJnLss
|
||||||
|
CmfNNNZNqDrnDjMhZM
|
||||||
|
gdczzGtdFcddtWQgGGMnVhnjJwnrJFDPTwMP
|
||||||
|
dlvcdzdHtzQSLRSfmhLSqv
|
||||||
|
ZpFFLcHFZZRRmJVZgD
|
||||||
|
PzhrtQntzcrjCRJtbtRgBsBRVR
|
||||||
|
zdzWfCzhQzlhWfWhlvpFNlpSqcMSHHMv
|
||||||
|
NrrMgMhNQhNjQrtqtPtwVtZpggPw
|
||||||
|
TfRLndnLFCRFTFbbRDHwpVqqBBwsHwZsfH
|
||||||
|
TJFRdLlRThrlcvZcvQ
|
||||||
|
scrwRVjbQvQBzsBC
|
||||||
|
gMfVqNnVmnCBQDTvdn
|
||||||
|
SMqhWqVlmWSmqMVRSJjjpcFrcLpJrR
|
||||||
|
HtSQHQntHsHMrtHnGfHQVVzLvSBSVvVVSFNJzzVN
|
||||||
|
cmPRmpqlpPmcgTlTpjJNjjVDvDRFNVVBFD
|
||||||
|
hlmCpmqmpgqpZTlcdQHFQfbHHZttwMQwtr
|
||||||
|
VpWgbgfwCjbftwVPPpGQFQhzTBQTBGPzqFTS
|
||||||
|
dbRbDcRrsnsRrLZmLRDZldDZqTNTGqqFFzGGhSTNTFTzNmNT
|
||||||
|
MlLdHlDDHrHclMMrCwgHCCwWwCbCCjjg
|
||||||
|
GGNLhfDMVcVrcGsT
|
||||||
|
jSJQFjHbwPFSvQSHwZFvHSHrqCCrrTsqBwNBrcBNsVTsqq
|
||||||
|
QjZSjZJZPvNRZJQPnSZbJZRWLfnmgDlmhdhWgWLdMdfmhM
|
||||||
|
CgGnzPNggCJtNTgTZTPZzZZvvcDcDDdqDFcJssJDHDqvHq
|
||||||
|
jhhrrLVlmLRRnRflfVbFHHHqdVsDqcvbHVDb
|
||||||
|
jWfWwrlmRRnQmPzZNGZPBNCQTB
|
||||||
|
NzDDhwNmhvtrGmNCvWRVbcRRVTcHHcVFTbwV
|
||||||
|
LgsPlLsQgQdJsLdldtpgFFTMbnFqTcMbHqFcPncq
|
||||||
|
dgsJsLLLggljrhtGNNtSjvGm
|
||||||
|
ptzSrZtzhsmmtPrhLFRFnjnnLMsnfLRL
|
||||||
|
HvwVDHwWWgGDGdHgqVDWDMnRnTjFNTNjfLJvRRRRRR
|
||||||
|
DwDgWgQbDDDHwBBBWdwQGVHhlhlZZSSmztfcppSBhzZcZp
|
||||||
|
CWmWRzlMJqWDWqCJbqDlCBBVLMQHVMGrfMVtQZrsLL
|
||||||
|
SnhPdFFPNZsBBdHtVQ
|
||||||
|
SSPcFFgnwnSpwvcSjwzCqRzTmJbpJCRBmbbD
|
||||||
|
wQbqGWWSqwrbGWWWGjbNMJPfgfnnDmPnPNLfjN
|
||||||
|
tJFztRZCvVRCztZFZRVgmMhmgNLfRfnmDPNPhm
|
||||||
|
BFCVZzpVFlHCdbQqcTcGlJbbSG
|
||||||
|
tttfLPZZQZTlZPHHPWgMVvBnjmvjnjgGBQ
|
||||||
|
FzcNDDDrNzprrrshprhFJtVGVnjtjGvnhvVnnjnjGM
|
||||||
|
RDqJNszDPfdqPtlT
|
||||||
|
QCJdMjCQbdBjSbTHDsbWDDwHTP
|
||||||
|
zlvlmqzqGfgdNzLldrHwwPGpWDrPGZWprr
|
||||||
|
gfVfRczVqcRzmdcSQMjQSQCSjQCQ
|
||||||
|
RhhCGhRBShjjRfpwppFTfFHZHZZD
|
||||||
|
qzdqzlnPPctPdmtPdTZbwQvvwqvHHvZpwZ
|
||||||
|
nVTVTcsWmWSRhhRVrGVB
|
||||||
|
GmshRMnzqRGsPNwMwcrrpcVV
|
||||||
|
CDCbFCLvCgfDSFLslgDpwpLtTwwcPtNNtTTprt
|
||||||
|
JvSFbSbbFllJlgDvlJbgdRhRdqzBGnzshZnRRRnHBZ
|
||||||
|
ShJhtcsvvvQbnnsccVTLVTppWqddpVnLWp
|
||||||
|
NdzPrPZgPMNNrmzpTzpTCjWfzCpzVL
|
||||||
|
dZgHmZRPPZRlZmrPDtDRccvbtQQbJbRS
|
||||||
|
wqjLjwhznhBLqLWGfvSlvcmlrJsqrtJTJJ
|
||||||
|
PwbpFPQDRCDrDJTrTmvs
|
||||||
|
gbZVFbZHgwHbCdpCRMnffNLhWnnzMdzLLW
|
||||||
|
RVVGSNTTRlNqHblBNB
|
||||||
|
JfwJMvLLZwLsMJwWMJfwLHBqzFlvzpBQcqzblFbBqblq
|
||||||
|
wMCZJsgJCCCnsMHrgLLjSPSVTgShtRjTPhRRmt
|
||||||
|
lmQSSWdMHHLWgWqD
|
||||||
|
ZZtVGGGJrJvGVCwfgHNLccmNFFcqtc
|
||||||
|
vrCGPhvrTPdRBnsRTmmp
|
||||||
|
dDMDDjzCQjwCCcDgjSLLLsLNlmpplN
|
||||||
|
FqrHFTFRLCLVFBmS
|
||||||
|
JhHJhHRThrfPZPvhnTZZbWdwdwDDWtDzJDtbMtCW
|
||||||
|
ghwDzJRDwHmPthncSPncLLsPcvnv
|
||||||
|
MWCrNTCHrMVjQQMQcSdnpTLnFFdTcnTc
|
||||||
|
qbWMfWfNrWVQWfbjVBbqMfwDtqzmhmRRzGhtHhHhRwZh
|
||||||
|
fmSmnjTjrlzGlTzJdH
|
||||||
|
BrhRRQMrgQvgFFhQQbwpFvGGdZqZJqpJqHVpJGJLHdLJ
|
||||||
|
ggbDwQMsvsMQrFMFcWSPSCPmSsPfnnmP
|
||||||
|
cmNVbMrrrjcHDRcvfW
|
||||||
|
wQGdFfSThFsLhhHWvDCWDCJRCCjd
|
||||||
|
LtpStGhqrrpnfnpp
|
||||||
|
bvcccTqbgvpGndJtgdsgNd
|
||||||
|
wDQwQhtQhQRmSmjsJndJdBBJBJnlLS
|
||||||
|
hwhmRrzFVjtwzDmrVFrvPCcCMVPPvfqpCCTVVb
|
||||||
|
jRrRNPNRWjPRWPRQNjQjThTCzBBzDCFBGzgDFGGQ
|
||||||
|
dnppLwmwCnvtlqltvtnTGBThGhdFZhgzDzGccD
|
||||||
|
MvnqpLlMqCqCHMjWPPHMSHSs
|
||||||
|
NNpNNvpvBdtTrMFFMhSSwzjzchzwhzwL
|
||||||
|
VVndHqflQZZZgHSLLhjzRSmZRhcR
|
||||||
|
glGgnqbQlngnWCGJpJprtrtFrdPPGs
|
||||||
|
WqwRjzGtRzZZRRGjWBJzjwmfMTHGGssTTDsrLmmmQLMD
|
||||||
|
SNdvSdFlSNNhSPFFcPFclbQQslHmfHTDsTQMLgDTmHQQ
|
||||||
|
CNcCFvpdnWpjWwJf
|
||||||
|
PVPnVHcnRncGZqbVzHVPnnLbSMjwrzWMjSwDtWwWtwWhwDWz
|
||||||
|
pTfsQCshCllpglWWSjBMSQSrMrjM
|
||||||
|
hvpvppggCpJTvTmshgfsmZRRHqbcLPHZmPLRnmPZ
|
||||||
|
LQbhVZZmZhZjBdbGmgHqnHTmvqgnnWHr
|
||||||
|
SzCfDFFNRfsSFFMFfvprvpWzqzgqTwHTvp
|
||||||
|
CDNDFJgMDSQhjVdPJLQG
|
||||||
|
plpdLdpjjrrHJJjLrrHLFdbzzCcvzgFgcwggzPMFvvcMhM
|
||||||
|
GRtSBQNsQlMPRzRlzw
|
||||||
|
ZSTtsmBlmjLLpnpH
|
||||||
|
hglGNVSdNSghzSgCBhDFLBMBtFMMFtHtbtLL
|
||||||
|
frQZccRcqGFmFHrJ
|
||||||
|
nvfGZwvTwGTfQwvfTwfgnCSlpdnzgzslppCsCV
|
||||||
|
snTSPbQnTTnQgbmsTJsLfZwjffhpLnGRjpGfjL
|
||||||
|
dcNWcNHHlNtWHHlCtltWNFNMLZwjpGfpmrZfrFprrRGpwZfp
|
||||||
|
HmdNWCmDMVvQPDgqJs
|
||||||
|
GGFtSngQLfnSnQffgPnRgFRGRwmRJvwbBbJDwjvTbjrwhJvJ
|
||||||
|
WHClslcNNWcqNWlCZdcHsVrThBwBjbhDTDBhrvDZJTwm
|
||||||
|
NWVqqcHHNpsNcNVdVlhCMlHQQMQQzLfzQPttFGPMLSLgtF
|
31
day03/src/main.rs
Normal file
31
day03/src/main.rs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs;
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let input = fs::read_to_string(&env::args().nth(1).unwrap()).unwrap();
|
||||||
|
let mut lines = input.lines();
|
||||||
|
let mut next_line;
|
||||||
|
|
||||||
|
let mut sum: u64 = 0;
|
||||||
|
while (next_line = lines.next()) == () && !next_line.is_none() {
|
||||||
|
let line1: HashSet<char> = next_line.unwrap().chars().collect();
|
||||||
|
let line2: HashSet<char> = lines.next().unwrap().chars().collect();
|
||||||
|
'chars: for c in lines.next().unwrap().chars() {
|
||||||
|
if line1.contains(&c) && line2.contains(&c) {
|
||||||
|
sum += value_of(c);
|
||||||
|
break 'chars;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("{:?}", sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn value_of(c: char) -> u64 {
|
||||||
|
if c >= 'a' && c <= 'z' {
|
||||||
|
(c as u64) - ('a' as u64) + 1
|
||||||
|
} else {
|
||||||
|
(c as u64) - ('A' as u64) + 27
|
||||||
|
}
|
||||||
|
}
|
28
day03/src/main1.rs
Normal file
28
day03/src/main1.rs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs;
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let input = fs::read_to_string(&env::args().nth(1).unwrap()).unwrap();
|
||||||
|
|
||||||
|
let mut sum: u64 = 0;
|
||||||
|
for line in input.lines() {
|
||||||
|
let mut left_chars: HashSet<char> = HashSet::new();
|
||||||
|
|
||||||
|
for (i, c) in line.char_indices() {
|
||||||
|
if i < line.len()/2 {
|
||||||
|
left_chars.insert(c);
|
||||||
|
} else if left_chars.contains(&c) {
|
||||||
|
if c >= 'a' && c <= 'z' {
|
||||||
|
sum += (c as u64) - ('a' as u64) + 1;
|
||||||
|
} else {
|
||||||
|
sum += (c as u64) - ('A' as u64) + 27;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("{:?}", sum);
|
||||||
|
}
|
||||||
|
|
6
day03/test.txt
Normal file
6
day03/test.txt
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
vJrwpWtwJgWrhcsFMMfFFhFp
|
||||||
|
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
|
||||||
|
PmmdzqPrVvPwwTWBwg
|
||||||
|
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
|
||||||
|
ttgJtRGJQctTZtZT
|
||||||
|
CrZsJsPPZsGzwwsLwLmpwMDw
|
7
day04/Cargo.lock
generated
Normal file
7
day04/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "day4"
|
||||||
|
version = "0.1.0"
|
8
day04/Cargo.toml
Normal file
8
day04/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "day4"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
1000
day04/input.txt
Normal file
1000
day04/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
25
day04/src/main.rs
Normal file
25
day04/src/main.rs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let input = fs::read_to_string(&env::args().nth(1).unwrap()).unwrap();
|
||||||
|
let mut sum = 0;
|
||||||
|
|
||||||
|
for line in input.lines() {
|
||||||
|
let (s1, e1, s2, e2) = readline(line);
|
||||||
|
if s1 <= e2 && s2 <= e1 {
|
||||||
|
sum += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Total: {}", sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn readline(line: &str) -> (i64, i64, i64, i64) {
|
||||||
|
let nums: Vec<i64> = line
|
||||||
|
.split(['-', ','])
|
||||||
|
.map(|line| line.parse::<i64>().unwrap())
|
||||||
|
.collect();
|
||||||
|
(nums[0], nums[1], nums[2], nums[3])
|
||||||
|
}
|
||||||
|
|
25
day04/src/main1.rs
Normal file
25
day04/src/main1.rs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let input = fs::read_to_string(&env::args().nth(1).unwrap()).unwrap();
|
||||||
|
let mut sum = 0;
|
||||||
|
|
||||||
|
for line in input.lines() {
|
||||||
|
let (s1, e1, s2, e2) = readline(line);
|
||||||
|
if (s1 <= s2 && e1 >= e2) || (s1 >= s2 && e1 <= e2) {
|
||||||
|
sum += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Total: {}", sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn readline(line: &str) -> (i64, i64, i64, i64) {
|
||||||
|
let nums: Vec<i64> = line
|
||||||
|
.split(['-', ','])
|
||||||
|
.map(|line| line.parse::<i64>().unwrap())
|
||||||
|
.collect();
|
||||||
|
(nums[0], nums[1], nums[2], nums[3])
|
||||||
|
}
|
||||||
|
|
6
day04/test.txt
Normal file
6
day04/test.txt
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
2-4,6-8
|
||||||
|
2-3,4-5
|
||||||
|
5-7,7-9
|
||||||
|
2-8,3-7
|
||||||
|
6-6,4-6
|
||||||
|
2-6,4-8
|
7
day05/Cargo.lock
generated
Normal file
7
day05/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "day5"
|
||||||
|
version = "0.1.0"
|
8
day05/Cargo.toml
Normal file
8
day05/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "day5"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
511
day05/input.txt
Normal file
511
day05/input.txt
Normal file
@@ -0,0 +1,511 @@
|
|||||||
|
[L] [M] [M]
|
||||||
|
[D] [R] [Z] [C] [L]
|
||||||
|
[C] [S] [T] [G] [V] [M]
|
||||||
|
[R] [L] [Q] [B] [B] [D] [F]
|
||||||
|
[H] [B] [G] [D] [Q] [Z] [T] [J]
|
||||||
|
[M] [J] [H] [M] [P] [S] [V] [L] [N]
|
||||||
|
[P] [C] [N] [T] [S] [F] [R] [G] [Q]
|
||||||
|
[Z] [P] [S] [F] [F] [T] [N] [P] [W]
|
||||||
|
1 2 3 4 5 6 7 8 9
|
||||||
|
|
||||||
|
move 7 from 3 to 9
|
||||||
|
move 5 from 8 to 9
|
||||||
|
move 3 from 9 to 5
|
||||||
|
move 6 from 9 to 2
|
||||||
|
move 9 from 9 to 3
|
||||||
|
move 3 from 7 to 3
|
||||||
|
move 8 from 2 to 3
|
||||||
|
move 9 from 3 to 1
|
||||||
|
move 11 from 3 to 8
|
||||||
|
move 5 from 6 to 9
|
||||||
|
move 1 from 6 to 3
|
||||||
|
move 1 from 2 to 7
|
||||||
|
move 1 from 4 to 8
|
||||||
|
move 1 from 3 to 9
|
||||||
|
move 4 from 4 to 3
|
||||||
|
move 6 from 8 to 3
|
||||||
|
move 2 from 8 to 2
|
||||||
|
move 4 from 9 to 3
|
||||||
|
move 3 from 2 to 5
|
||||||
|
move 2 from 5 to 4
|
||||||
|
move 5 from 3 to 4
|
||||||
|
move 11 from 1 to 4
|
||||||
|
move 1 from 7 to 6
|
||||||
|
move 1 from 3 to 5
|
||||||
|
move 2 from 1 to 9
|
||||||
|
move 1 from 1 to 4
|
||||||
|
move 7 from 5 to 8
|
||||||
|
move 21 from 4 to 6
|
||||||
|
move 6 from 6 to 2
|
||||||
|
move 6 from 8 to 9
|
||||||
|
move 5 from 8 to 5
|
||||||
|
move 2 from 2 to 7
|
||||||
|
move 4 from 3 to 7
|
||||||
|
move 1 from 2 to 6
|
||||||
|
move 1 from 2 to 5
|
||||||
|
move 2 from 2 to 7
|
||||||
|
move 4 from 3 to 7
|
||||||
|
move 1 from 4 to 6
|
||||||
|
move 9 from 5 to 3
|
||||||
|
move 7 from 3 to 4
|
||||||
|
move 7 from 7 to 3
|
||||||
|
move 7 from 4 to 1
|
||||||
|
move 8 from 3 to 5
|
||||||
|
move 1 from 3 to 5
|
||||||
|
move 3 from 8 to 2
|
||||||
|
move 2 from 2 to 9
|
||||||
|
move 13 from 9 to 4
|
||||||
|
move 5 from 5 to 3
|
||||||
|
move 4 from 7 to 6
|
||||||
|
move 1 from 7 to 4
|
||||||
|
move 2 from 4 to 2
|
||||||
|
move 3 from 3 to 4
|
||||||
|
move 2 from 5 to 2
|
||||||
|
move 6 from 1 to 7
|
||||||
|
move 1 from 2 to 8
|
||||||
|
move 1 from 3 to 8
|
||||||
|
move 1 from 1 to 6
|
||||||
|
move 1 from 3 to 4
|
||||||
|
move 1 from 2 to 6
|
||||||
|
move 24 from 6 to 1
|
||||||
|
move 3 from 2 to 3
|
||||||
|
move 3 from 3 to 5
|
||||||
|
move 2 from 8 to 6
|
||||||
|
move 2 from 5 to 4
|
||||||
|
move 3 from 5 to 1
|
||||||
|
move 7 from 4 to 8
|
||||||
|
move 3 from 8 to 9
|
||||||
|
move 2 from 9 to 5
|
||||||
|
move 2 from 6 to 3
|
||||||
|
move 1 from 9 to 8
|
||||||
|
move 5 from 7 to 5
|
||||||
|
move 2 from 3 to 1
|
||||||
|
move 1 from 7 to 1
|
||||||
|
move 7 from 4 to 7
|
||||||
|
move 2 from 4 to 8
|
||||||
|
move 6 from 8 to 6
|
||||||
|
move 3 from 6 to 9
|
||||||
|
move 10 from 5 to 1
|
||||||
|
move 7 from 7 to 1
|
||||||
|
move 1 from 4 to 9
|
||||||
|
move 1 from 6 to 3
|
||||||
|
move 2 from 9 to 7
|
||||||
|
move 1 from 4 to 2
|
||||||
|
move 1 from 9 to 5
|
||||||
|
move 1 from 8 to 5
|
||||||
|
move 39 from 1 to 8
|
||||||
|
move 1 from 2 to 5
|
||||||
|
move 2 from 6 to 9
|
||||||
|
move 3 from 9 to 5
|
||||||
|
move 3 from 1 to 6
|
||||||
|
move 1 from 7 to 2
|
||||||
|
move 1 from 3 to 2
|
||||||
|
move 2 from 6 to 2
|
||||||
|
move 3 from 2 to 3
|
||||||
|
move 1 from 6 to 2
|
||||||
|
move 1 from 1 to 8
|
||||||
|
move 3 from 1 to 2
|
||||||
|
move 3 from 2 to 4
|
||||||
|
move 2 from 4 to 5
|
||||||
|
move 2 from 3 to 8
|
||||||
|
move 8 from 5 to 2
|
||||||
|
move 8 from 8 to 2
|
||||||
|
move 15 from 2 to 7
|
||||||
|
move 1 from 1 to 5
|
||||||
|
move 25 from 8 to 7
|
||||||
|
move 2 from 2 to 4
|
||||||
|
move 2 from 4 to 3
|
||||||
|
move 1 from 8 to 4
|
||||||
|
move 2 from 4 to 6
|
||||||
|
move 1 from 2 to 1
|
||||||
|
move 26 from 7 to 2
|
||||||
|
move 15 from 2 to 1
|
||||||
|
move 7 from 8 to 9
|
||||||
|
move 10 from 1 to 6
|
||||||
|
move 10 from 7 to 2
|
||||||
|
move 1 from 8 to 1
|
||||||
|
move 5 from 9 to 8
|
||||||
|
move 1 from 8 to 9
|
||||||
|
move 2 from 6 to 9
|
||||||
|
move 3 from 7 to 1
|
||||||
|
move 1 from 7 to 1
|
||||||
|
move 5 from 9 to 2
|
||||||
|
move 1 from 3 to 1
|
||||||
|
move 9 from 6 to 3
|
||||||
|
move 1 from 6 to 1
|
||||||
|
move 4 from 2 to 4
|
||||||
|
move 3 from 4 to 8
|
||||||
|
move 1 from 4 to 1
|
||||||
|
move 9 from 3 to 1
|
||||||
|
move 1 from 7 to 6
|
||||||
|
move 9 from 2 to 5
|
||||||
|
move 14 from 1 to 6
|
||||||
|
move 1 from 3 to 8
|
||||||
|
move 5 from 2 to 6
|
||||||
|
move 8 from 1 to 8
|
||||||
|
move 6 from 6 to 8
|
||||||
|
move 14 from 6 to 7
|
||||||
|
move 1 from 1 to 7
|
||||||
|
move 10 from 5 to 4
|
||||||
|
move 11 from 8 to 5
|
||||||
|
move 15 from 7 to 1
|
||||||
|
move 4 from 5 to 6
|
||||||
|
move 4 from 8 to 9
|
||||||
|
move 6 from 5 to 3
|
||||||
|
move 1 from 6 to 9
|
||||||
|
move 1 from 1 to 6
|
||||||
|
move 1 from 5 to 8
|
||||||
|
move 2 from 6 to 2
|
||||||
|
move 6 from 1 to 5
|
||||||
|
move 1 from 5 to 8
|
||||||
|
move 2 from 5 to 4
|
||||||
|
move 9 from 2 to 9
|
||||||
|
move 13 from 9 to 8
|
||||||
|
move 1 from 2 to 1
|
||||||
|
move 1 from 4 to 8
|
||||||
|
move 3 from 3 to 1
|
||||||
|
move 2 from 4 to 5
|
||||||
|
move 2 from 1 to 5
|
||||||
|
move 1 from 9 to 3
|
||||||
|
move 17 from 8 to 1
|
||||||
|
move 3 from 3 to 2
|
||||||
|
move 4 from 5 to 1
|
||||||
|
move 2 from 2 to 4
|
||||||
|
move 1 from 6 to 1
|
||||||
|
move 1 from 2 to 8
|
||||||
|
move 4 from 4 to 6
|
||||||
|
move 1 from 5 to 9
|
||||||
|
move 5 from 6 to 8
|
||||||
|
move 1 from 5 to 4
|
||||||
|
move 1 from 5 to 6
|
||||||
|
move 3 from 8 to 6
|
||||||
|
move 8 from 4 to 5
|
||||||
|
move 32 from 1 to 7
|
||||||
|
move 11 from 7 to 6
|
||||||
|
move 8 from 5 to 3
|
||||||
|
move 3 from 8 to 7
|
||||||
|
move 6 from 3 to 9
|
||||||
|
move 4 from 3 to 8
|
||||||
|
move 5 from 8 to 2
|
||||||
|
move 1 from 8 to 5
|
||||||
|
move 11 from 6 to 3
|
||||||
|
move 1 from 5 to 2
|
||||||
|
move 2 from 8 to 6
|
||||||
|
move 12 from 7 to 8
|
||||||
|
move 2 from 6 to 2
|
||||||
|
move 2 from 6 to 4
|
||||||
|
move 5 from 2 to 5
|
||||||
|
move 8 from 7 to 2
|
||||||
|
move 2 from 7 to 1
|
||||||
|
move 2 from 7 to 6
|
||||||
|
move 5 from 5 to 4
|
||||||
|
move 5 from 4 to 7
|
||||||
|
move 5 from 8 to 2
|
||||||
|
move 2 from 9 to 7
|
||||||
|
move 5 from 8 to 4
|
||||||
|
move 2 from 7 to 3
|
||||||
|
move 2 from 9 to 3
|
||||||
|
move 3 from 7 to 9
|
||||||
|
move 1 from 1 to 8
|
||||||
|
move 2 from 6 to 1
|
||||||
|
move 2 from 9 to 8
|
||||||
|
move 1 from 7 to 8
|
||||||
|
move 1 from 2 to 5
|
||||||
|
move 1 from 7 to 9
|
||||||
|
move 7 from 4 to 3
|
||||||
|
move 3 from 3 to 6
|
||||||
|
move 5 from 8 to 6
|
||||||
|
move 3 from 9 to 5
|
||||||
|
move 16 from 3 to 1
|
||||||
|
move 2 from 9 to 1
|
||||||
|
move 7 from 1 to 8
|
||||||
|
move 1 from 1 to 2
|
||||||
|
move 5 from 8 to 2
|
||||||
|
move 12 from 1 to 4
|
||||||
|
move 1 from 3 to 5
|
||||||
|
move 1 from 2 to 9
|
||||||
|
move 1 from 9 to 4
|
||||||
|
move 4 from 6 to 5
|
||||||
|
move 5 from 6 to 1
|
||||||
|
move 1 from 6 to 5
|
||||||
|
move 1 from 1 to 4
|
||||||
|
move 1 from 4 to 7
|
||||||
|
move 1 from 3 to 7
|
||||||
|
move 9 from 4 to 6
|
||||||
|
move 2 from 7 to 8
|
||||||
|
move 1 from 3 to 4
|
||||||
|
move 2 from 8 to 9
|
||||||
|
move 4 from 8 to 4
|
||||||
|
move 4 from 2 to 8
|
||||||
|
move 2 from 9 to 7
|
||||||
|
move 2 from 7 to 8
|
||||||
|
move 10 from 2 to 4
|
||||||
|
move 1 from 2 to 1
|
||||||
|
move 5 from 4 to 7
|
||||||
|
move 1 from 1 to 3
|
||||||
|
move 3 from 8 to 7
|
||||||
|
move 6 from 7 to 2
|
||||||
|
move 3 from 2 to 7
|
||||||
|
move 1 from 6 to 7
|
||||||
|
move 5 from 5 to 8
|
||||||
|
move 4 from 1 to 3
|
||||||
|
move 4 from 3 to 1
|
||||||
|
move 8 from 4 to 2
|
||||||
|
move 1 from 3 to 2
|
||||||
|
move 2 from 7 to 2
|
||||||
|
move 2 from 6 to 3
|
||||||
|
move 4 from 7 to 2
|
||||||
|
move 4 from 5 to 7
|
||||||
|
move 14 from 2 to 7
|
||||||
|
move 3 from 2 to 1
|
||||||
|
move 3 from 8 to 2
|
||||||
|
move 1 from 5 to 7
|
||||||
|
move 6 from 2 to 4
|
||||||
|
move 2 from 2 to 7
|
||||||
|
move 2 from 3 to 6
|
||||||
|
move 6 from 8 to 2
|
||||||
|
move 4 from 6 to 4
|
||||||
|
move 2 from 6 to 9
|
||||||
|
move 4 from 4 to 2
|
||||||
|
move 2 from 4 to 8
|
||||||
|
move 10 from 7 to 2
|
||||||
|
move 18 from 2 to 6
|
||||||
|
move 2 from 2 to 6
|
||||||
|
move 2 from 9 to 2
|
||||||
|
move 2 from 8 to 5
|
||||||
|
move 1 from 2 to 9
|
||||||
|
move 1 from 2 to 9
|
||||||
|
move 1 from 5 to 7
|
||||||
|
move 1 from 2 to 6
|
||||||
|
move 2 from 9 to 2
|
||||||
|
move 6 from 7 to 3
|
||||||
|
move 7 from 6 to 8
|
||||||
|
move 5 from 7 to 2
|
||||||
|
move 1 from 7 to 4
|
||||||
|
move 1 from 5 to 7
|
||||||
|
move 4 from 8 to 7
|
||||||
|
move 5 from 2 to 3
|
||||||
|
move 1 from 7 to 5
|
||||||
|
move 2 from 2 to 8
|
||||||
|
move 9 from 4 to 3
|
||||||
|
move 13 from 6 to 8
|
||||||
|
move 10 from 3 to 1
|
||||||
|
move 1 from 5 to 2
|
||||||
|
move 3 from 6 to 8
|
||||||
|
move 5 from 1 to 2
|
||||||
|
move 1 from 1 to 8
|
||||||
|
move 2 from 4 to 3
|
||||||
|
move 17 from 8 to 6
|
||||||
|
move 5 from 6 to 3
|
||||||
|
move 3 from 1 to 2
|
||||||
|
move 9 from 6 to 5
|
||||||
|
move 2 from 6 to 8
|
||||||
|
move 5 from 5 to 9
|
||||||
|
move 3 from 9 to 8
|
||||||
|
move 3 from 1 to 3
|
||||||
|
move 3 from 7 to 5
|
||||||
|
move 6 from 5 to 8
|
||||||
|
move 7 from 2 to 4
|
||||||
|
move 1 from 6 to 3
|
||||||
|
move 1 from 1 to 5
|
||||||
|
move 4 from 4 to 5
|
||||||
|
move 2 from 2 to 9
|
||||||
|
move 3 from 1 to 3
|
||||||
|
move 4 from 5 to 8
|
||||||
|
move 1 from 4 to 5
|
||||||
|
move 6 from 8 to 7
|
||||||
|
move 1 from 5 to 2
|
||||||
|
move 4 from 9 to 2
|
||||||
|
move 2 from 5 to 9
|
||||||
|
move 2 from 1 to 8
|
||||||
|
move 2 from 4 to 9
|
||||||
|
move 6 from 7 to 5
|
||||||
|
move 3 from 5 to 2
|
||||||
|
move 3 from 2 to 5
|
||||||
|
move 10 from 8 to 3
|
||||||
|
move 2 from 8 to 5
|
||||||
|
move 3 from 2 to 5
|
||||||
|
move 6 from 5 to 1
|
||||||
|
move 4 from 5 to 6
|
||||||
|
move 1 from 7 to 5
|
||||||
|
move 23 from 3 to 7
|
||||||
|
move 2 from 5 to 9
|
||||||
|
move 2 from 1 to 5
|
||||||
|
move 2 from 6 to 3
|
||||||
|
move 6 from 3 to 1
|
||||||
|
move 1 from 1 to 7
|
||||||
|
move 4 from 3 to 1
|
||||||
|
move 1 from 8 to 5
|
||||||
|
move 2 from 9 to 2
|
||||||
|
move 3 from 3 to 8
|
||||||
|
move 2 from 6 to 8
|
||||||
|
move 12 from 1 to 3
|
||||||
|
move 1 from 9 to 7
|
||||||
|
move 3 from 5 to 9
|
||||||
|
move 9 from 3 to 8
|
||||||
|
move 1 from 1 to 7
|
||||||
|
move 1 from 9 to 4
|
||||||
|
move 3 from 3 to 6
|
||||||
|
move 3 from 2 to 1
|
||||||
|
move 3 from 8 to 6
|
||||||
|
move 1 from 4 to 2
|
||||||
|
move 1 from 2 to 9
|
||||||
|
move 1 from 2 to 7
|
||||||
|
move 20 from 7 to 5
|
||||||
|
move 3 from 7 to 3
|
||||||
|
move 3 from 1 to 3
|
||||||
|
move 5 from 8 to 1
|
||||||
|
move 5 from 1 to 5
|
||||||
|
move 4 from 5 to 2
|
||||||
|
move 3 from 2 to 6
|
||||||
|
move 3 from 8 to 7
|
||||||
|
move 1 from 2 to 6
|
||||||
|
move 2 from 8 to 6
|
||||||
|
move 2 from 7 to 5
|
||||||
|
move 2 from 3 to 6
|
||||||
|
move 12 from 5 to 1
|
||||||
|
move 6 from 5 to 7
|
||||||
|
move 12 from 6 to 8
|
||||||
|
move 4 from 9 to 3
|
||||||
|
move 4 from 5 to 8
|
||||||
|
move 3 from 1 to 5
|
||||||
|
move 4 from 7 to 4
|
||||||
|
move 3 from 5 to 9
|
||||||
|
move 7 from 1 to 6
|
||||||
|
move 1 from 1 to 3
|
||||||
|
move 6 from 7 to 6
|
||||||
|
move 1 from 1 to 3
|
||||||
|
move 10 from 3 to 6
|
||||||
|
move 10 from 6 to 2
|
||||||
|
move 2 from 9 to 5
|
||||||
|
move 4 from 6 to 5
|
||||||
|
move 9 from 6 to 1
|
||||||
|
move 16 from 8 to 7
|
||||||
|
move 3 from 8 to 7
|
||||||
|
move 1 from 8 to 1
|
||||||
|
move 7 from 2 to 1
|
||||||
|
move 1 from 5 to 9
|
||||||
|
move 1 from 6 to 1
|
||||||
|
move 2 from 2 to 1
|
||||||
|
move 3 from 1 to 4
|
||||||
|
move 1 from 6 to 8
|
||||||
|
move 7 from 4 to 1
|
||||||
|
move 1 from 8 to 2
|
||||||
|
move 22 from 1 to 8
|
||||||
|
move 18 from 7 to 9
|
||||||
|
move 6 from 5 to 2
|
||||||
|
move 2 from 2 to 7
|
||||||
|
move 2 from 1 to 5
|
||||||
|
move 4 from 7 to 6
|
||||||
|
move 1 from 5 to 6
|
||||||
|
move 2 from 8 to 2
|
||||||
|
move 3 from 2 to 6
|
||||||
|
move 1 from 5 to 6
|
||||||
|
move 15 from 9 to 6
|
||||||
|
move 6 from 9 to 5
|
||||||
|
move 1 from 9 to 8
|
||||||
|
move 1 from 2 to 9
|
||||||
|
move 5 from 5 to 9
|
||||||
|
move 9 from 8 to 6
|
||||||
|
move 3 from 2 to 7
|
||||||
|
move 12 from 8 to 9
|
||||||
|
move 1 from 7 to 5
|
||||||
|
move 1 from 5 to 7
|
||||||
|
move 3 from 7 to 1
|
||||||
|
move 17 from 6 to 3
|
||||||
|
move 1 from 2 to 6
|
||||||
|
move 2 from 1 to 4
|
||||||
|
move 16 from 6 to 4
|
||||||
|
move 7 from 4 to 6
|
||||||
|
move 1 from 5 to 7
|
||||||
|
move 8 from 4 to 5
|
||||||
|
move 9 from 9 to 8
|
||||||
|
move 16 from 3 to 7
|
||||||
|
move 1 from 1 to 5
|
||||||
|
move 3 from 5 to 1
|
||||||
|
move 5 from 6 to 2
|
||||||
|
move 3 from 1 to 7
|
||||||
|
move 3 from 6 to 7
|
||||||
|
move 3 from 9 to 3
|
||||||
|
move 5 from 8 to 5
|
||||||
|
move 11 from 5 to 7
|
||||||
|
move 2 from 3 to 7
|
||||||
|
move 1 from 2 to 1
|
||||||
|
move 1 from 3 to 6
|
||||||
|
move 17 from 7 to 9
|
||||||
|
move 1 from 3 to 2
|
||||||
|
move 3 from 4 to 6
|
||||||
|
move 1 from 1 to 2
|
||||||
|
move 1 from 6 to 4
|
||||||
|
move 14 from 7 to 6
|
||||||
|
move 15 from 9 to 6
|
||||||
|
move 4 from 8 to 7
|
||||||
|
move 1 from 4 to 7
|
||||||
|
move 7 from 9 to 5
|
||||||
|
move 5 from 2 to 9
|
||||||
|
move 7 from 5 to 1
|
||||||
|
move 3 from 1 to 7
|
||||||
|
move 29 from 6 to 4
|
||||||
|
move 1 from 2 to 4
|
||||||
|
move 18 from 4 to 2
|
||||||
|
move 3 from 1 to 4
|
||||||
|
move 1 from 1 to 7
|
||||||
|
move 18 from 2 to 4
|
||||||
|
move 3 from 6 to 5
|
||||||
|
move 15 from 4 to 1
|
||||||
|
move 1 from 5 to 1
|
||||||
|
move 1 from 5 to 4
|
||||||
|
move 9 from 4 to 1
|
||||||
|
move 5 from 1 to 3
|
||||||
|
move 9 from 1 to 5
|
||||||
|
move 2 from 4 to 3
|
||||||
|
move 5 from 5 to 6
|
||||||
|
move 3 from 7 to 9
|
||||||
|
move 7 from 7 to 5
|
||||||
|
move 6 from 4 to 6
|
||||||
|
move 2 from 3 to 7
|
||||||
|
move 6 from 5 to 8
|
||||||
|
move 2 from 8 to 4
|
||||||
|
move 1 from 8 to 9
|
||||||
|
move 9 from 6 to 2
|
||||||
|
move 3 from 9 to 3
|
||||||
|
move 1 from 2 to 1
|
||||||
|
move 6 from 7 to 4
|
||||||
|
move 2 from 2 to 8
|
||||||
|
move 3 from 9 to 5
|
||||||
|
move 5 from 4 to 8
|
||||||
|
move 1 from 6 to 9
|
||||||
|
move 1 from 3 to 1
|
||||||
|
move 1 from 3 to 4
|
||||||
|
move 1 from 6 to 5
|
||||||
|
move 1 from 9 to 3
|
||||||
|
move 10 from 8 to 7
|
||||||
|
move 3 from 9 to 2
|
||||||
|
move 7 from 2 to 4
|
||||||
|
move 6 from 5 to 7
|
||||||
|
move 4 from 5 to 8
|
||||||
|
move 7 from 3 to 2
|
||||||
|
move 3 from 7 to 1
|
||||||
|
move 9 from 1 to 5
|
||||||
|
move 5 from 7 to 9
|
||||||
|
move 7 from 1 to 4
|
||||||
|
move 11 from 4 to 2
|
||||||
|
move 4 from 8 to 3
|
||||||
|
move 5 from 4 to 7
|
||||||
|
move 4 from 4 to 1
|
||||||
|
move 1 from 3 to 6
|
||||||
|
move 12 from 7 to 4
|
||||||
|
move 2 from 1 to 8
|
||||||
|
move 5 from 9 to 7
|
||||||
|
move 7 from 5 to 6
|
||||||
|
move 1 from 1 to 4
|
||||||
|
move 1 from 9 to 8
|
||||||
|
move 1 from 4 to 7
|
||||||
|
move 1 from 8 to 9
|
||||||
|
move 5 from 7 to 9
|
||||||
|
move 2 from 7 to 5
|
||||||
|
move 2 from 6 to 3
|
||||||
|
move 5 from 2 to 7
|
||||||
|
move 1 from 7 to 8
|
||||||
|
move 1 from 1 to 6
|
||||||
|
move 3 from 5 to 1
|
62
day05/src/main.rs
Normal file
62
day05/src/main.rs
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs;
|
||||||
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let (mut stacks, moves) = read_input(&env::args().nth(1).unwrap());
|
||||||
|
println!("stack = {:?}", stacks);
|
||||||
|
println!("moves = {:?}", moves);
|
||||||
|
|
||||||
|
for (n, from, to) in moves {
|
||||||
|
let mut crane: Vec<char> = Vec::new();
|
||||||
|
for _i in 1..=n {
|
||||||
|
crane.push(stacks[from].pop_front().unwrap());
|
||||||
|
}
|
||||||
|
for _i in 1..=n {
|
||||||
|
stacks[to].push_front(crane.pop().unwrap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let res: String = stacks.iter()
|
||||||
|
.map(|stack| stack.front().unwrap())
|
||||||
|
.collect();
|
||||||
|
println!("res = {:?}", res);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_input(file: &str) -> (Vec<VecDeque<char>>, Vec<(usize, usize, usize)>) {
|
||||||
|
let input = fs::read_to_string(file).unwrap();
|
||||||
|
|
||||||
|
let n_stacks = (input.lines().next().unwrap().len() + 1) / 4;
|
||||||
|
let mut stacks: Vec<VecDeque<char>> = vec![VecDeque::new(); n_stacks];
|
||||||
|
let mut moves: Vec<(usize, usize, usize)> = Vec::new();
|
||||||
|
let mut reading_crates = true;
|
||||||
|
|
||||||
|
for line in input.lines() {
|
||||||
|
if line.is_empty() || (reading_crates && has_digit(line)) {
|
||||||
|
reading_crates = false;
|
||||||
|
continue;
|
||||||
|
|
||||||
|
} else if reading_crates {
|
||||||
|
for (i, c) in line.char_indices() {
|
||||||
|
if i % 4 == 1 && c != ' '{
|
||||||
|
stacks[i/4].push_back(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
let nums: Vec<usize> = line
|
||||||
|
.split(|c: char| !c.is_numeric())
|
||||||
|
.filter(|s| !s.is_empty())
|
||||||
|
.map(|num| num.parse::<usize>().unwrap())
|
||||||
|
.collect();
|
||||||
|
moves.push((nums[0], nums[1] - 1, nums[2] - 1));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(stacks, moves)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn has_digit(line: &str) -> bool {
|
||||||
|
!line.chars().filter(|c| c.is_digit(10)).collect::<Vec<char>>().is_empty()
|
||||||
|
}
|
||||||
|
|
59
day05/src/main1.rs
Normal file
59
day05/src/main1.rs
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs;
|
||||||
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let (mut stacks, moves) = read_input(&env::args().nth(1).unwrap());
|
||||||
|
println!("stack = {:?}", stacks);
|
||||||
|
println!("moves = {:?}", moves);
|
||||||
|
|
||||||
|
for (n, from, to) in moves {
|
||||||
|
for _i in 1..=n {
|
||||||
|
let item = stacks[from].pop_front().unwrap();
|
||||||
|
stacks[to].push_front(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let res: String = stacks.iter()
|
||||||
|
.map(|stack| stack.front().unwrap())
|
||||||
|
.collect();
|
||||||
|
println!("res = {:?}", res);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_input(file: &str) -> (Vec<VecDeque<char>>, Vec<(usize, usize, usize)>) {
|
||||||
|
let input = fs::read_to_string(file).unwrap();
|
||||||
|
|
||||||
|
let n_stacks = (input.lines().next().unwrap().len() + 1) / 4;
|
||||||
|
let mut stacks: Vec<VecDeque<char>> = vec![VecDeque::new(); n_stacks];
|
||||||
|
let mut moves: Vec<(usize, usize, usize)> = Vec::new();
|
||||||
|
let mut reading_crates = true;
|
||||||
|
|
||||||
|
for line in input.lines() {
|
||||||
|
if line.is_empty() || (reading_crates && has_digit(line)) {
|
||||||
|
reading_crates = false;
|
||||||
|
continue;
|
||||||
|
|
||||||
|
} else if reading_crates {
|
||||||
|
for (i, c) in line.char_indices() {
|
||||||
|
if i % 4 == 1 && c != ' '{
|
||||||
|
stacks[i/4].push_back(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
let nums: Vec<usize> = line
|
||||||
|
.split(|c: char| !c.is_numeric())
|
||||||
|
.filter(|s| !s.is_empty())
|
||||||
|
.map(|num| num.parse::<usize>().unwrap())
|
||||||
|
.collect();
|
||||||
|
moves.push((nums[0], nums[1] - 1, nums[2] - 1));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(stacks, moves)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn has_digit(line: &str) -> bool {
|
||||||
|
!line.chars().filter(|c| c.is_digit(10)).collect::<Vec<char>>().is_empty()
|
||||||
|
}
|
||||||
|
|
9
day05/test.txt
Normal file
9
day05/test.txt
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[D]
|
||||||
|
[N] [C]
|
||||||
|
[Z] [M] [P]
|
||||||
|
1 2 3
|
||||||
|
|
||||||
|
move 1 from 2 to 1
|
||||||
|
move 3 from 1 to 3
|
||||||
|
move 2 from 2 to 1
|
||||||
|
move 1 from 1 to 2
|
7
day06/Cargo.lock
generated
Normal file
7
day06/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "day6"
|
||||||
|
version = "0.1.0"
|
8
day06/Cargo.toml
Normal file
8
day06/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "day6"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
1
day06/input.txt
Normal file
1
day06/input.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
zcncrcnrrlccmhchssgqsqrsstfffnqfnfsswgwjjcmcnnvjvwjvwvfvnvwwhvvwmwhmwwwhbhhldhdmhhdfdbdfbdblllnfllgslllqhlhfhlhqllncnfnsffwmwzzlglzlwlhwwmvmddpvvbrvrdvrdvdhhzdhdpdzzbgbsssrpsrshrshhbqbgbmmtwwcbcrbbvnvhnncscwcwlcwlwnwswbbnwntthzzdlzdzffvqvdqvvtptdptphpddzzvhzvzwwqgqjjjvsspvspsbsffvpvcvjcvjvrvjjgmjjhrrdhhdvhvttjttzptpssnlnjjlnnhmnndjnjwwtjjtbbfflwfwgwvvpjpwpcwcgglmgmdmnmbbqtqctcwcmwwvmvlmvmdvdvhvlhlzhzttghttnvnjntnqqtmtwwhvhrhfhchqchhdrdllnwnfwfjjmsmmnhhshnhpptstjjpnpzzhmmpssgrsrzsrrffzjjhvjhjcjcpcvpccfnfjnfjfllssrdsdnnmffldldppcctcmtctffprpsrrrfhfmflldccnpppvsswppdgpgjpgpqgpqpjppclcjczcnzzzqvzzwlzzqfzffsqqphqhvqqbcccstsdttwcwcvvmjjhqqmllpglgtgwgnnbnrbnnjdndhhbrbvrvwwwblwwwppmdmttztqzqrqjjpggpmgpmpqqmssvnsvnndnvddtztddrrsnsbbshhqmhqmmdnnrsrllqvvfjfpfqpqfqflqlmqmrrqgrqrrhvvfddfhhfnhnlncnzzwwjwswpsscpchcssrzssjqsqrsswbbzggnqnwqqsrqqzbqbddtffcjjdggwlwnwtnnpddcqddsppcwpcwpphvphhhrprqrqttwgwqwppvdpvvrgggmpmddzvvwwthwtttbqtbbftfrffbdfbbspshphpwhppnhnmhhbbshbsbmbdmmtrmrbrprbprphhnmhmvhmhhqqbvqvqcvcwcbwcchbbgwwqffrcffsvvcczrztrzzdhdmhdmmzbbvlvqqtptpvvfsfppdzppmddfvdfdwdfdmdwwlvvqdvqdqmdqqmnmdndsswsfwfvwfwzzhrzhhwfhhpvhppmssnhsnsnwswvwlwdwzwnwswwmqmjmbbdjdbbtllcpllltqlttnvvppznpnttlrrwlwvllphpbblccgjcggbtbwtwdwrrbnndpddbqqnpnrnnqqshspsggtptztpzzclcggtqtgqttcmmbgbfbdfdfsddlrlvrlvvmqqgbqgbqbcbbnpplqqblqbqmbbbdqbbhjjcgcdgdwdjwjqqlsqqnnwffglfglgnlggjgjtgjtgjtgjjclcwcqqvpvwwvgvhgvhvjjzpzbznnvrrrpbpdbdhhmshsnnnwppcbcvvlldccdggqnqgnqqzbzzcfflnnmppcgcmgmrgmrgmgngwwptpzzpfzpfzpzdppgcgtcgtgccvtctzzdmzmlmzlzwllbplblltgtctrrghgvhgvvfvssngsschshrhvrvddghgwwwwzgwgvgccjdjzjwwvdvvqsqshsvvddmddbllvppmlpmlmwlwppjmppwrrdzrrpmrmrdmrmbmzzwttvwwsfswwlflnlrlvvdllzbztbtpbtppnjpnpdnnjrjsshtssvvsjvjfjwffsszvsvjssqzsslpslppjpspqptbncvzrlwtjvsrwtnzzhwdfsmlthvgqgjrpshpbsrrvnsdbqslbcplnpcjqwmwqsnwdcjsdmccbdglwbrcdcqsfhjqhstvhqqdwltqwhhqcrnpvnzjhhbjvqbqhclwggjqfvnfsvcnjjhbmrvbpjqrbljbtltvnsgdfhddlmsdhcrfwvlvbsdrjwjvtnqzhrlqgjmzsmjlpdjsrjmdhmvgwjmfwtqffnzfrtswrlgvvhhqgpzcjwscfqgjmdhtvbgzdlvzfhgqlqbfwsjrmmhrlcwhrcnwwvngcmsrfgczsfqvvmdtmtprfvjrwrwcqwvgmzcjncrzvcswlzsdszvdtwmptnrhgzqwrhjjtbchhpwsdjnqmnsgzwqzvlzlsznpqgvtqnldjqpvndtsjlzhpzsgthbwvwnlbwjlmndqpcdvjdgdzhctpghlfwrtqtvfwdpgrjbmwzqgthjpmlrsqmzsznddhrbjnggqrdntpbngvldnnltfnmdwfhftjvpqbrzqvdzbzzctshzldtcdgfnczglrrjtwswzdvjrfgwztwznbpplmbgwpcmstcsjtqhmzmzsjwsfbjlbnbdtdsmlpdmrrbhdhpzrjdpzhcwsrgfrhmqzqtjfhpvltnthwjrrrpnsbmmwrhsfqbmnvwhpntltsgwgnqhcvlndfrtrfrnlmbhltmtgzhlzqgtsbbnggdjvbslfbczhpghqqcqlrbtpnbqbflfjrmpmwwvjqgvcqtmfggmptqlqstcmdtqlslnnzwbgnstftfsvsjdrmgbzfnzltwbjmqhsvshnmwhftjdndltdpngzwbrjpgpwmqgfsflnhmtzcmdjmzwrsrrrmpvwgggwrhrwtfwdbgbpmwpcdspdtbqvdwwsnwdtrtdtgnfzzsmlbcqdzbsqnrgtvvnlfcdlcgcnfpqbddqcjfqtmpndmnwvfqgjzrltqvlprmbbhmtwbzjjgfhhhfjswpffmjnsdmrcjrwlwpmfrmhljpphlwwwwmgsjcsrcvmfrdjdhshddshpplzsnsphcmdhvllgmdgrvbvjmtpltdthffsvwwhvgqrhmfjfpdswcqldrhpmznffjsntwrnmnpmsshljszbchctptsdlnbcvpfvtlfnzcrljpdwrsjnlpqcpnwvnqhzhqmjbvlbtgslzthlbbjzsgdglbrltzjdshpfbndjtssvsjqlstnrjdzzjvlpqhmwvrsvndcqrqjjcsqvmvrbhngtcfdprlbnqmhqllddgjpdzbjlphntrtgjrdgtbslrtzczbnnlddzzsvqvqvvzjpjqfhztgtsfggdppfdhzsbjzqjmpnmgqzlsdhjjbfpbsbnzpmhwrzjqhczrgcsflfwtrgwbnbrshjpwltntsnsdhmhqlmzdprcrcpcpjnphsmjwhzdqtncdbwgspmnfzsgmpbdhmslqchhhbbwfrghhnfjplsvrtbvplgrwdnbnfsgpwrqczvzlnfsngnsnbwvpmfdcmjztdnrllslnwcfwwnwsvztqmgqtfvmdqrrrmwfmphbcvwwttpmwjjbvqrmlwtwfsjdpcbmdlnlzcqntfzzmslshwprjfhwwpbbdfcdjwllfwcznwpjpwrlsfnnbgzjllrgtzcdcvhdhbtlrcvfdvsdjlzsmwwqvpzfhzjlqpfbqstvfrpcchmtwgbrhqqbglrvzmctdlpnvmglgdtzpbdngtfdnmsmwbgjstzbqwqcdlhfrtqqnhqvpfhdrjqvsvstftdgwwnwpfbfbdcfqnqlwpdnfhhfctwrgdqpbpbmgnfsnbpjfctvdtjnsfqlrtctrnjgltndngcmrdphhsqpjhprbngjzqqhnhhrdwlwwpmhzwshvrtzfgzlrhwghvpvfprbbvflltplpptvrmwcrdqndfqbfqtlqqwvphsmcvnbzghvsptrphhfcgdsslhfbcwhtjcmnpbvqrfgpsjgqpnnwwhjjwqrhhqgznwdzjqbtmmjljjwctqtfgwqbdrjwqwbbcftvjwfdfrgvsrlcrccpvfzdrcjvqfbhddpvrrhjrmhdgchrghbzsqpmgnmslfctblwlvphdfpvtdtwpdfsjwssmgnsvsqpdbqngccsplhmjbwjwtzwsbjhwpwcslqjdchmbvzrbgnwvjrrrdtvhtlzlrbwthzlhhqzzpvpwbzrrbrbtpwnhldhqqltqrqdddfwdmjzgctnlrjrjwvddfmjpnptdmrvnqjvsjfrmlvlqsthhsbvnjlsdzrjngfnqdjfssmvgrchbwmwbbvfqfhvrtwghmrpddnwbrbvbmqvfzbjdsnbzgrtmsfhmsmjtrqsgmpnwwbfwtp
|
25
day06/src/main.rs
Normal file
25
day06/src/main.rs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{BufReader, Read};
|
||||||
|
use std::collections::{VecDeque, HashSet};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let file = File::open(&env::args().nth(1).unwrap()).unwrap();
|
||||||
|
let reader = BufReader::new(file);
|
||||||
|
|
||||||
|
let mut prevs: VecDeque<u8> = VecDeque::new();
|
||||||
|
let mut i = 0;
|
||||||
|
for byte in reader.bytes() {
|
||||||
|
i += 1;
|
||||||
|
prevs.push_back(byte.unwrap());
|
||||||
|
if prevs.len() > 14 {
|
||||||
|
prevs.pop_front();
|
||||||
|
}
|
||||||
|
let set: HashSet<u8> = HashSet::from_iter(prevs.iter().cloned());
|
||||||
|
if set.len() == 14 {
|
||||||
|
println!("{}", i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
26
day06/src/main1.rs
Normal file
26
day06/src/main1.rs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{BufReader, Read};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let file = File::open(&env::args().nth(1).unwrap()).unwrap();
|
||||||
|
let reader = BufReader::new(file);
|
||||||
|
|
||||||
|
let (mut x1, mut x2, mut x3) = (0, 0, 0);
|
||||||
|
let mut i = 0;
|
||||||
|
for byte in reader.bytes() {
|
||||||
|
i += 1;
|
||||||
|
let c = byte.unwrap();
|
||||||
|
if c != x1 && c != x2 && c != x3
|
||||||
|
&& x1 != x2 && x1 != x3 && x2 != x3
|
||||||
|
&& x1 != 0 {
|
||||||
|
println!("{}", i);
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
x1 = x2;
|
||||||
|
x2 = x3;
|
||||||
|
x3 = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
1
day06/test.txt
Normal file
1
day06/test.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
mjqjpqmgbljsphdztnvjfqwrcgsmlb
|
7
day07/Cargo.lock
generated
Normal file
7
day07/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "day7"
|
||||||
|
version = "0.1.0"
|
8
day07/Cargo.toml
Normal file
8
day07/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "day7"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
1101
day07/input.txt
Normal file
1101
day07/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
94
day07/src/main.rs
Normal file
94
day07/src/main.rs
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{self, BufRead};
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
const MAX_SIZE: usize = 70_000_000 - 30_000_000;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let file = File::open(&env::args().nth(1).unwrap()).unwrap();
|
||||||
|
let mut lines = io::BufReader::new(file).lines();
|
||||||
|
let mut tree = DirTree::new();
|
||||||
|
let mut cwd = 0;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let tokens: Vec<_> = if let Some(Ok(l)) = lines.next() {
|
||||||
|
l.split_whitespace().map(String::from).collect()
|
||||||
|
} else { break; };
|
||||||
|
|
||||||
|
if tokens[0] == "$" {
|
||||||
|
if tokens[1] == "cd" {
|
||||||
|
if tokens[2] == ".." {
|
||||||
|
cwd = tree.inodes[cwd].parent.unwrap();
|
||||||
|
} else if tokens[2] == "/" {
|
||||||
|
cwd = 0;
|
||||||
|
} else {
|
||||||
|
let subdir = tree.inodes[cwd].subdirs[&tokens[2]];
|
||||||
|
cwd = subdir;
|
||||||
|
}
|
||||||
|
} else if tokens[1] == "ls" {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else if tokens[0] == "dir" {
|
||||||
|
tree.add_subdir_to(cwd, tokens[1].clone());
|
||||||
|
} else {
|
||||||
|
tree.add_file_to(
|
||||||
|
cwd,
|
||||||
|
tokens[1].clone(),
|
||||||
|
tokens[0].parse::<usize>().unwrap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let total_size = tree.size_of(0);
|
||||||
|
let answer: usize = (0..tree.inodes.len())
|
||||||
|
.map(|inode| tree.size_of(inode))
|
||||||
|
.filter(|size| total_size - *size <= MAX_SIZE)
|
||||||
|
.min().unwrap();
|
||||||
|
println!("{:?}", answer);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Dir {
|
||||||
|
pub files: HashMap<String, usize>, // file name and size
|
||||||
|
pub subdirs: HashMap<String, usize>, // dir name and index into arena
|
||||||
|
pub parent: Option<usize>, // index into arena
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct DirTree {
|
||||||
|
inodes: Vec<Dir>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DirTree {
|
||||||
|
fn new() -> Self {
|
||||||
|
let newdir = Dir {
|
||||||
|
files: HashMap::new(),
|
||||||
|
subdirs: HashMap::new(),
|
||||||
|
parent: None,
|
||||||
|
};
|
||||||
|
DirTree { inodes: vec![newdir] }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_subdir_to(&mut self, idx: usize, name: String) {
|
||||||
|
let newidx = self.inodes.len();
|
||||||
|
let newdir = Dir {
|
||||||
|
files: HashMap::new(),
|
||||||
|
subdirs: HashMap::new(),
|
||||||
|
parent: Some(idx),
|
||||||
|
};
|
||||||
|
self.inodes.push(newdir);
|
||||||
|
self.inodes[idx].subdirs.insert(name, newidx);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_file_to(&mut self, idx: usize, name: String, size: usize) {
|
||||||
|
self.inodes[idx].files.insert(name, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn size_of(&self, inode: usize) -> usize {
|
||||||
|
let size_files: usize = self.inodes[inode].files.values().sum();
|
||||||
|
let size_dirs: usize = self.inodes[inode].subdirs.values()
|
||||||
|
.fold(0, |acc, subdir_inode| acc + self.size_of(*subdir_inode));
|
||||||
|
size_files + size_dirs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
91
day07/src/main1.rs
Normal file
91
day07/src/main1.rs
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{self, BufRead};
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let file = File::open(&env::args().nth(1).unwrap()).unwrap();
|
||||||
|
let mut lines = io::BufReader::new(file).lines();
|
||||||
|
let mut tree = DirTree::new();
|
||||||
|
let mut cwd = 0;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let tokens: Vec<_> = if let Some(Ok(l)) = lines.next() {
|
||||||
|
l.split_whitespace().map(String::from).collect()
|
||||||
|
} else { break; };
|
||||||
|
|
||||||
|
if tokens[0] == "$" {
|
||||||
|
if tokens[1] == "cd" {
|
||||||
|
if tokens[2] == ".." {
|
||||||
|
cwd = tree.inodes[cwd].parent.unwrap();
|
||||||
|
} else if tokens[2] == "/" {
|
||||||
|
cwd = 0;
|
||||||
|
} else {
|
||||||
|
let subdir = tree.inodes[cwd].subdirs[&tokens[2]];
|
||||||
|
cwd = subdir;
|
||||||
|
}
|
||||||
|
} else if tokens[1] == "ls" {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else if tokens[0] == "dir" {
|
||||||
|
tree.add_subdir_to(cwd, tokens[1].clone());
|
||||||
|
} else {
|
||||||
|
tree.add_file_to(
|
||||||
|
cwd,
|
||||||
|
tokens[1].clone(),
|
||||||
|
tokens[0].parse::<usize>().unwrap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sum: usize = (0..tree.inodes.len())
|
||||||
|
.map(|inode| tree.size_of(inode))
|
||||||
|
.filter(|size| *size <= 100000)
|
||||||
|
.sum();
|
||||||
|
println!("{:?}", sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Dir {
|
||||||
|
pub files: HashMap<String, usize>, // file name and size
|
||||||
|
pub subdirs: HashMap<String, usize>, // dir name and index into arena
|
||||||
|
pub parent: Option<usize>, // index into arena
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct DirTree {
|
||||||
|
inodes: Vec<Dir>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DirTree {
|
||||||
|
fn new() -> Self {
|
||||||
|
let newdir = Dir {
|
||||||
|
files: HashMap::new(),
|
||||||
|
subdirs: HashMap::new(),
|
||||||
|
parent: None,
|
||||||
|
};
|
||||||
|
DirTree { inodes: vec![newdir] }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_subdir_to(&mut self, idx: usize, name: String) {
|
||||||
|
let newidx = self.inodes.len();
|
||||||
|
let newdir = Dir {
|
||||||
|
files: HashMap::new(),
|
||||||
|
subdirs: HashMap::new(),
|
||||||
|
parent: Some(idx),
|
||||||
|
};
|
||||||
|
self.inodes.push(newdir);
|
||||||
|
self.inodes[idx].subdirs.insert(name, newidx);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_file_to(&mut self, idx: usize, name: String, size: usize) {
|
||||||
|
self.inodes[idx].files.insert(name, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn size_of(&self, inode: usize) -> usize {
|
||||||
|
let size_files: usize = self.inodes[inode].files.values().sum();
|
||||||
|
let size_dirs: usize = self.inodes[inode].subdirs.values()
|
||||||
|
.fold(0, |acc, subdir_inode| acc + self.size_of(*subdir_inode));
|
||||||
|
size_files + size_dirs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
23
day07/test.txt
Normal file
23
day07/test.txt
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
$ cd /
|
||||||
|
$ ls
|
||||||
|
dir a
|
||||||
|
14848514 b.txt
|
||||||
|
8504156 c.dat
|
||||||
|
dir d
|
||||||
|
$ cd a
|
||||||
|
$ ls
|
||||||
|
dir e
|
||||||
|
29116 f
|
||||||
|
2557 g
|
||||||
|
62596 h.lst
|
||||||
|
$ cd e
|
||||||
|
$ ls
|
||||||
|
584 i
|
||||||
|
$ cd ..
|
||||||
|
$ cd ..
|
||||||
|
$ cd d
|
||||||
|
$ ls
|
||||||
|
4060174 j
|
||||||
|
8033020 d.log
|
||||||
|
5626152 d.ext
|
||||||
|
7214296 k
|
7
day08/Cargo.lock
generated
Normal file
7
day08/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "day8"
|
||||||
|
version = "0.1.0"
|
8
day08/Cargo.toml
Normal file
8
day08/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "day8"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
99
day08/input.txt
Normal file
99
day08/input.txt
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
323312120104041101003001553044055322145351354433645660555433454202452204412052502421011342410230100
|
||||||
|
331223314040220223001130433220004441042006330461143461335633613314213000015223153233240331142300012
|
||||||
|
023102231103100342321215533524330225130560305625124623310126454152020030305335002210044012323422232
|
||||||
|
033211114433402023241334421151326235424122515414424161565116453111213321055111200550233444040333323
|
||||||
|
031320412113341012010242000135046256344463444305066152423440545620430235453525520134521220144043130
|
||||||
|
010124340443212543345333321333301441655163125534010352005641320662142112543221425142532404413320002
|
||||||
|
032312034332435412243231103121245340611134410006433546515216241603224333504015201503140034044432021
|
||||||
|
320200344413202332231554246602660034061050643672316237416266543042042653101335352044243134331323303
|
||||||
|
021300102204043340554035441662023251216477627653211774256145300615432406261511620233045011441203023
|
||||||
|
214221412130421304035463335360514215534123522725272245137776312134526215216203521523534253001441422
|
||||||
|
420043232030231215456256414206036653347362132153333156552344113453564204615313111314105214221003223
|
||||||
|
241014245200324505163302204145552154121123441333614641654374366443635062610615660400505253511330311
|
||||||
|
231411122124035056146223662646715423323763562152711313214722174623631122416546336265504022423420321
|
||||||
|
042134415425335411142551632217112111473327114471514114442336163742155647750445640460531524541203340
|
||||||
|
343034551205503142350464162224754743123535251535665351452621461253234473323031250306005520215303040
|
||||||
|
410130220425226615062361272722422212213362652886842457443563446376627357725562240530656421332425231
|
||||||
|
330405053401450540006525751276462213552438775622853762648444675762737115273314256401440500101434302
|
||||||
|
304122334204441123350414175256673644342865574663385723585576354377456151273122601662220161301504112
|
||||||
|
422435205014554545365735723436373233832475876524575872268832223848512552555643351604546205341424215
|
||||||
|
443115513525431203264315523331217625862645482563537776356753567584283413472356644126410362312334123
|
||||||
|
052022430460332345152212254167524466648262435238422282347263726486242532216231573303203326333131543
|
||||||
|
404311335435645624675123354136583324744857778885726358668585255832473858653735421124234313332210004
|
||||||
|
520111321123045340623442334624735877337545859497694367639273762375345722536177411211020042150153021
|
||||||
|
411235141221544066661746224736774624232459373766373495575944484527562783724767432624400142054055522
|
||||||
|
024120413051264413175435475422366266524638499844474853789334849464538454233333357361304324422613501
|
||||||
|
352214454643240574661363763475756533743797783848433976887696359992333666675226733442545524354500443
|
||||||
|
251345503313114376116272866687526585434388584575674356595674465655476743763543124147356110122024044
|
||||||
|
133110654322616733231668722725373876835778466784566584387395434396884778345524117356166460636143351
|
||||||
|
112230445513242554663324764556586867753674864468343933678664667973977485428425757277634522562064320
|
||||||
|
412306136011573262177765432437358738546736839846997485567376574548587838746648241232635661362635551
|
||||||
|
311241644325164361477854453554348537943884446578656447795556786443464445568375622146223253430106005
|
||||||
|
414462311300441254474772486749467753538794788465984797676648668849664495546568855562445764261642010
|
||||||
|
445133603633532623526886852476968663955448979964894644847777557664794864337536578317645124263315442
|
||||||
|
021241645421162453132262365348765439348656776856595854754476769757566455663276324366766456305305120
|
||||||
|
510244461256441623866724589378887569656684895495456487696769566643875787347426424523647565754401653
|
||||||
|
151145124011265333234662229795656686884674575478956878676685556556946338775266677877143733665060552
|
||||||
|
131002165277346618257378696764537399445797598957895796889759879556485735764887363865111323236124503
|
||||||
|
220611453676274277858565456484455695655979579759955677959885995645474566676772536632553114354340041
|
||||||
|
323335253242622148532422868466345564965967686989886957689558546964794339796466254345247754360223316
|
||||||
|
112064463545413576425378697983496684567756967695578787779885776765545968768637752578574116433630421
|
||||||
|
262635257577314368832689586734395956986977797785985896558768958559955796869794344738811241365425065
|
||||||
|
036254031317172762245555787683749657559987756669998856989597798769664563473786885472827134423313506
|
||||||
|
112502266652465672888368949558445769459577569797855698786769989985987785676547473444272672141252544
|
||||||
|
045215646223371643352336896643689688876655959565996855669678688486694743366369623465327522575042356
|
||||||
|
205562422736764236882339845435688999868789977579698799868877976745688897678798344673376264654052604
|
||||||
|
640616321667131656568746868646446794765955968978766798777975879944949447436547952777356562624565361
|
||||||
|
503133645662433253222235564587874595496598558678699667976697595767948945736786373476844144136233155
|
||||||
|
152313252157252347426379766989467986779887556669696688689579876876596876558577966523563177643114061
|
||||||
|
015365066657673648536298976339575598578756896788969879767577686654749477584746873347542574227516230
|
||||||
|
302516211647152355274343639744655874775669596897686966699876695998787469759645835454545677723745465
|
||||||
|
266163561235542776842433383799598975897978899879789767676699785678664666798579564534878747126146153
|
||||||
|
634140631567256667662664934564476759588897588797699869877796899585469988739654868456635123523755234
|
||||||
|
526164653667775855733559449364494974596968858678799696797985695999575786597999333727844531513343544
|
||||||
|
115403464653622458323374663594975966866888697766687979997898875955786785736875844627521437353606304
|
||||||
|
640206337252276334632475883969765797699957959997976897898769896775474877959677374487863614742211222
|
||||||
|
106034313777637748437776995547694868569869859888896977797665956948986945796495667868436477373160314
|
||||||
|
006143515575426735835789383997647997666658866898869877859765667898455643998988843284334411112325061
|
||||||
|
060213154573543438565356383379984957565858775655687688855799695465677553374667278462773177353503021
|
||||||
|
534112106512613276556555984466559658455977888698665968969989598677796459965554455385335454425613431
|
||||||
|
423425206422713575644746337955366575454795967856856876586957554899648773967935667584344176377532425
|
||||||
|
315510242114177262757639877363694484999758689789879599886867745964475568777854454352517415741562052
|
||||||
|
254415451471443426858387939443978767549948877565555768796577696468685835375388876547331566530141542
|
||||||
|
303202343156475546746672434475949695576445897955568899665665785796494455593633835634447131551412543
|
||||||
|
530640543251355257253244866999758855497944665987986659888747567449665534577874222676576617430555625
|
||||||
|
035226003425623774544664764845838347558577759648579987787884744479479884357976856228167235705641542
|
||||||
|
012530303425724762454645575734538738897469478966696978758788679866348589899832555641531652553533310
|
||||||
|
431520564223363131574588328444453968694548987546469759466967869587993958848677622834372746605252324
|
||||||
|
131024531432663176288887647869436593765656667475894545486664448575468585944778464554223653360402652
|
||||||
|
551654340156114412778738226397776454595784788647965555996665676344574743382638772356734133042615443
|
||||||
|
024355434261535345548273336774384984477576879774784456784868644637765744738364526332565760044560540
|
||||||
|
155113230232747546753685543766476666768567676894864479768956459393759573342483687447324136430444500
|
||||||
|
440336611600246742643243587242836576774688377798976584555359856436455842274266466561462502505050311
|
||||||
|
015501455202457152271777448623885744575738975738543495886575536689489232583347854551274740450542500
|
||||||
|
112355455505514326761438726267648488556885859557845836789874856463364248667756746144136240330222401
|
||||||
|
430051415453434173737573386277526293849897978657467838347963744587834677342423717341756610043455255
|
||||||
|
444113312134554163124414283335326283887438687965973966654788943867635532444353372724432652622302125
|
||||||
|
033012131053460465125111273742768667769675675775436398594585954535426388764627242656605623003420535
|
||||||
|
532011006562506121567537614332848223752545648784336666978759658235586323586276363263554554402535155
|
||||||
|
225043145666651226342224774572478338454285536637433467599546254373462838314454715765242604264433432
|
||||||
|
143342003654424145134151113142525853753886774346442435733753462268623254516141462445566062114320251
|
||||||
|
444420540521256141013447675222256426635324487526632736745527642885674235536747737261652463202500555
|
||||||
|
222431405032506222504344543644653776575736336844778763733528588764848657567376356150063166013552501
|
||||||
|
034510422056636225624747266514456777633233775555386632488454864657717533631241666065420200205052500
|
||||||
|
103105455224503224304034177327635111647827276665752827282575886784253656562365122244424151025515301
|
||||||
|
101102203425121661104345642122736177478284778325375873527465777421741567742166564045604510141154121
|
||||||
|
332242401534421133554041122533563354755216642533436868343877635122146146667706230365422105012153402
|
||||||
|
432103353112023141120633555353651647171735573773567775173731563436215115735654456154234331555345240
|
||||||
|
311201403135204156305310465662641267265251523134647455137635637621766373241145212506405302221022004
|
||||||
|
221411412415305356354132634130374733663416232631657355257255546777623360525504041204002524135430312
|
||||||
|
112411441314100543355310054325527735473745551311261276366344472654631261140112663455454513102400244
|
||||||
|
013012011123153452314613460031161542746223115713547637621711265172533165260520404042554414322034013
|
||||||
|
201330012335124150152314410164151235026663366233372131265564532262110563062500635222224450514021440
|
||||||
|
342111222034352424040354160440340405301651622677574134133735403132430514114033551354315433040230114
|
||||||
|
112010023301100445223113160555302602635620463156162543530556141321431263425255250524151354433130344
|
||||||
|
332330330010343221124140132242255256316545654313060323031636355342510224333220335454325432312040232
|
||||||
|
231131200414441021404115411126030522302652306460121060224031660650605423613101532204404042041104211
|
||||||
|
110213044340333244505210244013344303254465010502545450101621054023246053340412123410522324133332123
|
||||||
|
001010311033004234122205300341243461144265623424563511436115050502162552302441545001031211431213203
|
||||||
|
110302001002203213045154432555553533654213115630566633251401333456110344545402251530041323224011221
|
56
day08/src/main.rs
Normal file
56
day08/src/main.rs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let input = fs::read_to_string(&env::args().nth(1).unwrap()).unwrap();
|
||||||
|
let forest: Vec<Vec<i8>> = input.lines()
|
||||||
|
.map(|line| line.chars()
|
||||||
|
.map(|c| c.to_digit(10).unwrap() as i8).collect())
|
||||||
|
.collect();
|
||||||
|
let nrows = forest.len();
|
||||||
|
let ncols = forest[0].len();
|
||||||
|
|
||||||
|
let mut scores = vec![vec![1; ncols]; nrows];
|
||||||
|
for r in 1..nrows-1 {
|
||||||
|
for c in 1..ncols-1 {
|
||||||
|
let h = forest[r][c];
|
||||||
|
|
||||||
|
let mut j = c - 1;
|
||||||
|
let mut count = 0;
|
||||||
|
while j > 0 && forest[r][j] < h {
|
||||||
|
count += 1;
|
||||||
|
j -= 1;
|
||||||
|
}
|
||||||
|
scores[r][c] *= count + 1;
|
||||||
|
|
||||||
|
let mut j = c + 1;
|
||||||
|
let mut count = 0;
|
||||||
|
while j < ncols-1 && forest[r][j] < h {
|
||||||
|
count += 1;
|
||||||
|
j += 1;
|
||||||
|
}
|
||||||
|
scores[r][c] *= count + 1;
|
||||||
|
|
||||||
|
let mut i = r - 1;
|
||||||
|
let mut count = 0;
|
||||||
|
while i > 0 && forest[i][c] < h {
|
||||||
|
count += 1;
|
||||||
|
i -= 1;
|
||||||
|
}
|
||||||
|
scores[r][c] *= count + 1;
|
||||||
|
|
||||||
|
let mut i = r + 1;
|
||||||
|
let mut count = 0;
|
||||||
|
while i < nrows-1 && forest[i][c] < h {
|
||||||
|
count += 1;
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
scores[r][c] *= count + 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let answer = scores.iter().map(|row| row.iter().max()).max();
|
||||||
|
println!("{:?}", answer);
|
||||||
|
}
|
||||||
|
|
59
day08/src/main1.rs
Normal file
59
day08/src/main1.rs
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let input = fs::read_to_string(&env::args().nth(1).unwrap()).unwrap();
|
||||||
|
let forest: Vec<Vec<i8>> = input.lines()
|
||||||
|
.map(|line| line.chars()
|
||||||
|
.map(|c| c.to_digit(10).unwrap() as i8).collect())
|
||||||
|
.collect();
|
||||||
|
let nrows = forest.len();
|
||||||
|
let ncols = forest[0].len();
|
||||||
|
|
||||||
|
let min_from_left: Vec<Vec<i8>> = forest.iter()
|
||||||
|
.map(|row| row.iter()
|
||||||
|
.scan(-1, |h, &tree| {
|
||||||
|
let old = *h; *h = i8::max(*h as i8, tree); Some(old)
|
||||||
|
})
|
||||||
|
.collect())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let min_from_right: Vec<Vec<i8>> = forest.iter()
|
||||||
|
.map(|row: &Vec<i8>| row.iter()
|
||||||
|
.rev()
|
||||||
|
.scan(-1, |h, &tree| {
|
||||||
|
let old = *h; *h = i8::max(*h as i8, tree); Some(old)
|
||||||
|
})
|
||||||
|
.collect::<Vec<i8>>().iter()
|
||||||
|
.rev().map(|x| *x)
|
||||||
|
.collect())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let mut min_from_top: Vec<Vec<i8>> = vec![vec![-1; ncols]; nrows];
|
||||||
|
for c in 0..ncols {
|
||||||
|
for r in 1..nrows {
|
||||||
|
min_from_top[r][c] = i8::max(min_from_top[r-1][c], forest[r-1][c]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut min_from_bot: Vec<Vec<i8>> = vec![vec![-1; ncols]; nrows];
|
||||||
|
for c in 0..ncols {
|
||||||
|
for r in (0..nrows-1).rev() {
|
||||||
|
min_from_bot[r][c] = i8::max(min_from_bot[r+1][c], forest[r+1][c]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut sum = 0;
|
||||||
|
for r in 0..nrows {
|
||||||
|
for c in 0..ncols {
|
||||||
|
if forest[r][c] > min_from_left[r][c]
|
||||||
|
|| forest[r][c] > min_from_right[r][c]
|
||||||
|
|| forest[r][c] > min_from_top[r][c]
|
||||||
|
|| forest[r][c] > min_from_bot[r][c] {
|
||||||
|
sum += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!("{:?}", sum);
|
||||||
|
}
|
||||||
|
|
5
day08/test.txt
Normal file
5
day08/test.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
30373
|
||||||
|
25512
|
||||||
|
65332
|
||||||
|
33549
|
||||||
|
35390
|
7
day09/Cargo.lock
generated
Normal file
7
day09/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "day9"
|
||||||
|
version = "0.1.0"
|
8
day09/Cargo.toml
Normal file
8
day09/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "day9"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
2000
day09/input.txt
Normal file
2000
day09/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
49
day09/src/main.rs
Normal file
49
day09/src/main.rs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{self, BufRead};
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let file = File::open(&env::args().nth(1).unwrap()).unwrap();
|
||||||
|
let reader = io::BufReader::new(file);
|
||||||
|
let mut rope: [(i64, i64); 10] = [(0, 0); 10];
|
||||||
|
let mut visited: HashSet<(i64, i64)> = vec![(0, 0)].into_iter().collect();
|
||||||
|
|
||||||
|
for line in reader.lines().flatten() {
|
||||||
|
let ((movx, movy), count) = parse_line(line).unwrap();
|
||||||
|
for _ in 0..count {
|
||||||
|
rope[0] = (rope[0].0 + movx, rope[0].1 + movy);
|
||||||
|
for link in 1..=9 {
|
||||||
|
rope[link] = move_tail(rope[link - 1], rope[link]);
|
||||||
|
}
|
||||||
|
visited.insert(rope[9]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!("{:?}", visited.len());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_line(line: String) -> Option<((i64, i64), i64)> {
|
||||||
|
let mov = match line.chars().nth(0) {
|
||||||
|
Some('L') => Some((-1, 0)),
|
||||||
|
Some('R') => Some((1, 0)),
|
||||||
|
Some('U') => Some((0, -1)),
|
||||||
|
Some('D') => Some((0, 1)),
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
let count = line[2..].parse::<i64>();
|
||||||
|
match (mov, count) {
|
||||||
|
(Some(mov), Ok(count)) => Some((mov, count)),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn move_tail((hx, hy): (i64, i64), (tx, ty): (i64, i64)) -> (i64, i64) {
|
||||||
|
let dx = if hx > tx { 1 } else { -1 };
|
||||||
|
let dy = if hy > ty { 1 } else { -1 };
|
||||||
|
match (hx - tx, hy - ty) {
|
||||||
|
(-1..=1, -1..=1) => (tx, ty),
|
||||||
|
(-1..=1, _) => (hx, ty + dy),
|
||||||
|
(_, -1..=1) => (tx + dx, hy),
|
||||||
|
(_, _) => (tx + dx, ty + dy),
|
||||||
|
}
|
||||||
|
}
|
39
day09/src/main1.rs
Normal file
39
day09/src/main1.rs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{self, BufRead};
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let file = File::open(&env::args().nth(1).unwrap()).unwrap();
|
||||||
|
let reader = io::BufReader::new(file);
|
||||||
|
let (mut hx, mut hy, mut tx, mut ty) = (0, 0, 0, 0);
|
||||||
|
let mut visited: HashSet<(i64, i64)> = vec![(0, 0)].into_iter().collect();
|
||||||
|
|
||||||
|
for line in reader.lines().flatten() {
|
||||||
|
let (movx, movy) = match line.chars().nth(0) {
|
||||||
|
Some('L') => (-1, 0),
|
||||||
|
Some('R') => (1, 0),
|
||||||
|
Some('U') => (0, -1),
|
||||||
|
Some('D') => (0, 1),
|
||||||
|
_ => (999, 999),
|
||||||
|
};
|
||||||
|
let count = line[2..].parse::<i64>().unwrap();
|
||||||
|
for _ in 0..count {
|
||||||
|
(hx, hy) = (hx + movx, hy + movy);
|
||||||
|
(tx, ty) = move_tail(hx, hy, tx, ty).unwrap();
|
||||||
|
visited.insert((tx, ty));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!("{:?}", visited.len());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn move_tail(hx: i64, hy: i64, tx: i64, ty: i64) -> Option<(i64, i64)> {
|
||||||
|
match (hx - tx, hy - ty) {
|
||||||
|
(-1..=1, -1..=1) => Some((tx, ty)),
|
||||||
|
(-1..=1, 2) => Some((hx, ty + 1)),
|
||||||
|
(-1..=1, -2) => Some((hx, ty - 1)),
|
||||||
|
(2, -1..=1) => Some((tx + 1, hy)),
|
||||||
|
(-2, -1..=1) => Some((tx - 1, hy)),
|
||||||
|
_ => None
|
||||||
|
}
|
||||||
|
}
|
8
day09/test.txt
Normal file
8
day09/test.txt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
R 4
|
||||||
|
U 4
|
||||||
|
L 3
|
||||||
|
D 1
|
||||||
|
R 4
|
||||||
|
D 1
|
||||||
|
L 5
|
||||||
|
R 2
|
8
day09/test2.txt
Normal file
8
day09/test2.txt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
R 5
|
||||||
|
U 8
|
||||||
|
L 8
|
||||||
|
D 3
|
||||||
|
R 17
|
||||||
|
D 10
|
||||||
|
L 25
|
||||||
|
U 20
|
7
day10/Cargo.lock
generated
Normal file
7
day10/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "day10"
|
||||||
|
version = "0.1.0"
|
8
day10/Cargo.toml
Normal file
8
day10/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "day10"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
143
day10/input.txt
Normal file
143
day10/input.txt
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 5
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 6
|
||||||
|
addx 4
|
||||||
|
addx -4
|
||||||
|
addx 4
|
||||||
|
addx -6
|
||||||
|
addx 11
|
||||||
|
addx -1
|
||||||
|
addx 2
|
||||||
|
addx 4
|
||||||
|
addx 3
|
||||||
|
noop
|
||||||
|
addx 2
|
||||||
|
addx -30
|
||||||
|
addx 2
|
||||||
|
addx 33
|
||||||
|
noop
|
||||||
|
addx -37
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 3
|
||||||
|
addx 2
|
||||||
|
addx 5
|
||||||
|
addx 20
|
||||||
|
addx 7
|
||||||
|
addx -24
|
||||||
|
addx 2
|
||||||
|
noop
|
||||||
|
addx 7
|
||||||
|
addx -2
|
||||||
|
addx -6
|
||||||
|
addx 13
|
||||||
|
addx 3
|
||||||
|
addx -2
|
||||||
|
addx 2
|
||||||
|
noop
|
||||||
|
addx -5
|
||||||
|
addx 10
|
||||||
|
addx 5
|
||||||
|
addx -39
|
||||||
|
addx 1
|
||||||
|
addx 5
|
||||||
|
noop
|
||||||
|
addx 3
|
||||||
|
noop
|
||||||
|
addx -5
|
||||||
|
addx 10
|
||||||
|
addx -2
|
||||||
|
addx 2
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 7
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 3
|
||||||
|
noop
|
||||||
|
addx 3
|
||||||
|
addx 2
|
||||||
|
addx 8
|
||||||
|
addx -1
|
||||||
|
addx -20
|
||||||
|
addx 21
|
||||||
|
addx -38
|
||||||
|
addx 5
|
||||||
|
addx 2
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 8
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx -2
|
||||||
|
addx 2
|
||||||
|
addx -7
|
||||||
|
addx 14
|
||||||
|
addx 5
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx -16
|
||||||
|
addx 17
|
||||||
|
addx 2
|
||||||
|
addx -12
|
||||||
|
addx 19
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx -37
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 3
|
||||||
|
addx 2
|
||||||
|
addx 2
|
||||||
|
addx 5
|
||||||
|
addx 20
|
||||||
|
addx -19
|
||||||
|
addx 2
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 5
|
||||||
|
addx 19
|
||||||
|
addx -12
|
||||||
|
addx 3
|
||||||
|
addx -2
|
||||||
|
addx 2
|
||||||
|
addx -18
|
||||||
|
addx 25
|
||||||
|
addx -14
|
||||||
|
addx -22
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 3
|
||||||
|
addx 5
|
||||||
|
addx -4
|
||||||
|
addx 7
|
||||||
|
addx 4
|
||||||
|
noop
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 2
|
||||||
|
addx -6
|
||||||
|
addx 15
|
||||||
|
addx -1
|
||||||
|
addx 4
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 1
|
||||||
|
addx 4
|
||||||
|
addx -33
|
||||||
|
noop
|
||||||
|
addx 21
|
||||||
|
noop
|
50
day10/src/main.rs
Normal file
50
day10/src/main.rs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
use std::num;
|
||||||
|
use std::env;
|
||||||
|
use std::process;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{self, BufRead};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
enum Inst{
|
||||||
|
AddX(i64),
|
||||||
|
Noop,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct ParseError(String);
|
||||||
|
impl From<num::ParseIntError> for ParseError {
|
||||||
|
fn from(e: num::ParseIntError) -> Self {
|
||||||
|
ParseError(e.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_line(line: String) -> Result<Inst, ParseError> {
|
||||||
|
match &line[..4] {
|
||||||
|
"noop" => Ok(Inst::Noop),
|
||||||
|
"addx" => Ok(Inst::AddX(line[5..].parse::<i64>()?)),
|
||||||
|
_ => Err(ParseError(String::from("bad instruction"))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let file = File::open(&env::args().nth(1).unwrap()).unwrap();
|
||||||
|
let reader = io::BufReader::new(file);
|
||||||
|
let mut xs: Vec<i64> = vec![1];
|
||||||
|
|
||||||
|
for line in reader.lines().flatten() {
|
||||||
|
let last_x = *xs.last().unwrap();
|
||||||
|
match parse_line(line) {
|
||||||
|
Ok(Inst::Noop) => { xs.push(last_x) },
|
||||||
|
Ok(Inst::AddX(x)) => { xs.push(last_x); xs.push(last_x + x) },
|
||||||
|
Err(e) => { eprintln!("error: {:?}", e); process::exit(1) },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let screen: Vec<_> = xs.iter().enumerate()
|
||||||
|
.map(|(i, &x)| if ((i as i64) % 40 - x).abs() <= 1 { '#' } else { '.' })
|
||||||
|
.collect();
|
||||||
|
for i in 0..6 {
|
||||||
|
println!("{}", screen[(i*40)..((i+1)*40)].iter().collect::<String>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
45
day10/src/main1.rs
Normal file
45
day10/src/main1.rs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::process;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{self, BufRead};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
enum Inst{
|
||||||
|
AddX(i64),
|
||||||
|
Noop,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct ParseError(String);
|
||||||
|
|
||||||
|
fn parse_line(line: String) -> Result<Inst, ParseError> {
|
||||||
|
match &line[..4] {
|
||||||
|
"noop" => Ok(Inst::Noop),
|
||||||
|
"addx" => match line[5..].parse::<i64>() {
|
||||||
|
Ok(operand) => Ok(Inst::AddX(operand)),
|
||||||
|
Err(e) => Err(ParseError(e.to_string())),
|
||||||
|
},
|
||||||
|
_ => Err(ParseError(String::from("bad instruction"))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let file = File::open(&env::args().nth(1).unwrap()).unwrap();
|
||||||
|
let reader = io::BufReader::new(file);
|
||||||
|
let mut xs: Vec<i64> = vec![0, 1];
|
||||||
|
|
||||||
|
for line in reader.lines().flatten() {
|
||||||
|
let last_x = *xs.last().unwrap();
|
||||||
|
match parse_line(line) {
|
||||||
|
Ok(Inst::Noop) => { xs.push(last_x) },
|
||||||
|
Ok(Inst::AddX(x)) => { xs.push(last_x); xs.push(last_x + x) },
|
||||||
|
Err(e) => { eprintln!("error: {:?}", e); process::exit(1) },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let res: i64 = xs.iter().enumerate()
|
||||||
|
.skip(20).step_by(40)
|
||||||
|
.map(|(i, &x)| (i as i64)*x)
|
||||||
|
.sum();
|
||||||
|
println!("{:?}", res);
|
||||||
|
}
|
||||||
|
|
146
day10/test.txt
Normal file
146
day10/test.txt
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
addx 15
|
||||||
|
addx -11
|
||||||
|
addx 6
|
||||||
|
addx -3
|
||||||
|
addx 5
|
||||||
|
addx -1
|
||||||
|
addx -8
|
||||||
|
addx 13
|
||||||
|
addx 4
|
||||||
|
noop
|
||||||
|
addx -1
|
||||||
|
addx 5
|
||||||
|
addx -1
|
||||||
|
addx 5
|
||||||
|
addx -1
|
||||||
|
addx 5
|
||||||
|
addx -1
|
||||||
|
addx 5
|
||||||
|
addx -1
|
||||||
|
addx -35
|
||||||
|
addx 1
|
||||||
|
addx 24
|
||||||
|
addx -19
|
||||||
|
addx 1
|
||||||
|
addx 16
|
||||||
|
addx -11
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 21
|
||||||
|
addx -15
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx -3
|
||||||
|
addx 9
|
||||||
|
addx 1
|
||||||
|
addx -3
|
||||||
|
addx 8
|
||||||
|
addx 1
|
||||||
|
addx 5
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx -36
|
||||||
|
noop
|
||||||
|
addx 1
|
||||||
|
addx 7
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 2
|
||||||
|
addx 6
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 7
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
addx -13
|
||||||
|
addx 13
|
||||||
|
addx 7
|
||||||
|
noop
|
||||||
|
addx 1
|
||||||
|
addx -33
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 2
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 8
|
||||||
|
noop
|
||||||
|
addx -1
|
||||||
|
addx 2
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
addx 17
|
||||||
|
addx -9
|
||||||
|
addx 1
|
||||||
|
addx 1
|
||||||
|
addx -3
|
||||||
|
addx 11
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx -13
|
||||||
|
addx -19
|
||||||
|
addx 1
|
||||||
|
addx 3
|
||||||
|
addx 26
|
||||||
|
addx -30
|
||||||
|
addx 12
|
||||||
|
addx -1
|
||||||
|
addx 3
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx -9
|
||||||
|
addx 18
|
||||||
|
addx 1
|
||||||
|
addx 2
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 9
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx -1
|
||||||
|
addx 2
|
||||||
|
addx -37
|
||||||
|
addx 1
|
||||||
|
addx 3
|
||||||
|
noop
|
||||||
|
addx 15
|
||||||
|
addx -21
|
||||||
|
addx 22
|
||||||
|
addx -6
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
addx 2
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
addx -10
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 20
|
||||||
|
addx 1
|
||||||
|
addx 2
|
||||||
|
addx 2
|
||||||
|
addx -6
|
||||||
|
addx -11
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
7
day11/Cargo.lock
generated
Normal file
7
day11/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "day11"
|
||||||
|
version = "0.1.0"
|
8
day11/Cargo.toml
Normal file
8
day11/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "day11"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
55
day11/input.txt
Normal file
55
day11/input.txt
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
Monkey 0:
|
||||||
|
Starting items: 66, 79
|
||||||
|
Operation: new = old * 11
|
||||||
|
Test: divisible by 7
|
||||||
|
If true: throw to monkey 6
|
||||||
|
If false: throw to monkey 7
|
||||||
|
|
||||||
|
Monkey 1:
|
||||||
|
Starting items: 84, 94, 94, 81, 98, 75
|
||||||
|
Operation: new = old * 17
|
||||||
|
Test: divisible by 13
|
||||||
|
If true: throw to monkey 5
|
||||||
|
If false: throw to monkey 2
|
||||||
|
|
||||||
|
Monkey 2:
|
||||||
|
Starting items: 85, 79, 59, 64, 79, 95, 67
|
||||||
|
Operation: new = old + 8
|
||||||
|
Test: divisible by 5
|
||||||
|
If true: throw to monkey 4
|
||||||
|
If false: throw to monkey 5
|
||||||
|
|
||||||
|
Monkey 3:
|
||||||
|
Starting items: 70
|
||||||
|
Operation: new = old + 3
|
||||||
|
Test: divisible by 19
|
||||||
|
If true: throw to monkey 6
|
||||||
|
If false: throw to monkey 0
|
||||||
|
|
||||||
|
Monkey 4:
|
||||||
|
Starting items: 57, 69, 78, 78
|
||||||
|
Operation: new = old + 4
|
||||||
|
Test: divisible by 2
|
||||||
|
If true: throw to monkey 0
|
||||||
|
If false: throw to monkey 3
|
||||||
|
|
||||||
|
Monkey 5:
|
||||||
|
Starting items: 65, 92, 60, 74, 72
|
||||||
|
Operation: new = old + 7
|
||||||
|
Test: divisible by 11
|
||||||
|
If true: throw to monkey 3
|
||||||
|
If false: throw to monkey 4
|
||||||
|
|
||||||
|
Monkey 6:
|
||||||
|
Starting items: 77, 91, 91
|
||||||
|
Operation: new = old * old
|
||||||
|
Test: divisible by 17
|
||||||
|
If true: throw to monkey 1
|
||||||
|
If false: throw to monkey 7
|
||||||
|
|
||||||
|
Monkey 7:
|
||||||
|
Starting items: 76, 58, 57, 55, 67, 77, 54, 99
|
||||||
|
Operation: new = old + 6
|
||||||
|
Test: divisible by 3
|
||||||
|
If true: throw to monkey 2
|
||||||
|
If false: throw to monkey 1
|
162
day11/src/main.rs
Normal file
162
day11/src/main.rs
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
use std::num::ParseIntError;
|
||||||
|
use std::env;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{self, BufRead, Lines};
|
||||||
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
enum Operator { Add, Mul }
|
||||||
|
#[derive(Debug)]
|
||||||
|
enum Operand { Old, Imm(u64) }
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Operation { left: Operand, op: Operator, right: Operand }
|
||||||
|
impl Operation {
|
||||||
|
fn perform(&self, old: u64) -> u64 {
|
||||||
|
let left = match self.left {
|
||||||
|
Operand::Old => old,
|
||||||
|
Operand::Imm(x) => x,
|
||||||
|
};
|
||||||
|
let right = match self.right {
|
||||||
|
Operand::Old => old,
|
||||||
|
Operand::Imm(x) => x,
|
||||||
|
};
|
||||||
|
match self.op {
|
||||||
|
Operator::Add => left + right,
|
||||||
|
Operator::Mul => left * right,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Monkey {
|
||||||
|
id: u64,
|
||||||
|
items: VecDeque<u64>,
|
||||||
|
operation: Operation,
|
||||||
|
div_by_test: u64,
|
||||||
|
true_throw: u64,
|
||||||
|
false_throw: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
enum MonkeyError {
|
||||||
|
ParseError(),
|
||||||
|
ParseIntError(ParseIntError),
|
||||||
|
IoError(io::Error),
|
||||||
|
}
|
||||||
|
impl From<ParseIntError> for MonkeyError {
|
||||||
|
fn from(e: ParseIntError) -> Self { MonkeyError::ParseIntError(e) }
|
||||||
|
}
|
||||||
|
impl From<io::Error> for MonkeyError {
|
||||||
|
fn from(e: io::Error) -> Self { MonkeyError::IoError(e) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_monkey<B: BufRead>(
|
||||||
|
lines: &mut Lines<B>
|
||||||
|
) -> Result<Option<Monkey>, MonkeyError> {
|
||||||
|
let id = match lines.next() {
|
||||||
|
Some(line) => line?
|
||||||
|
.strip_prefix("Monkey ").ok_or(MonkeyError::ParseError())?
|
||||||
|
.strip_suffix(":").ok_or(MonkeyError::ParseError())?
|
||||||
|
.parse::<u64>()?,
|
||||||
|
None => return Ok(None),
|
||||||
|
};
|
||||||
|
|
||||||
|
let starting_items = lines.next().ok_or(MonkeyError::ParseError())??
|
||||||
|
.strip_prefix(" Starting items: ").ok_or(MonkeyError::ParseError())?
|
||||||
|
.split(", ")
|
||||||
|
.map(|item| item.parse::<u64>())
|
||||||
|
.collect::<Result<VecDeque<_>, _>>()?;
|
||||||
|
|
||||||
|
let op_line = lines.next().ok_or(MonkeyError::ParseError())??;
|
||||||
|
let op_vec = op_line
|
||||||
|
.strip_prefix(" Operation: new = ").ok_or(MonkeyError::ParseError())?
|
||||||
|
.split(' ').collect::<Vec<_>>();
|
||||||
|
let (left, operator, right) = (op_vec[0], op_vec[1], op_vec[2]);
|
||||||
|
let operation = Operation {
|
||||||
|
left: match left {
|
||||||
|
"old" => Operand::Old,
|
||||||
|
_ => Operand::Imm(left.parse()?)
|
||||||
|
},
|
||||||
|
op: match operator {
|
||||||
|
"+" => Ok(Operator::Add),
|
||||||
|
"*" => Ok(Operator::Mul),
|
||||||
|
_ => Err(MonkeyError::ParseError())
|
||||||
|
}?,
|
||||||
|
right: match right {
|
||||||
|
"old" => Operand::Old,
|
||||||
|
_ => Operand::Imm(right.parse()?)
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
let test_val = lines.next().ok_or(MonkeyError::ParseError())??
|
||||||
|
.strip_prefix(" Test: divisible by ").ok_or(MonkeyError::ParseError())?
|
||||||
|
.parse::<u64>()?;
|
||||||
|
|
||||||
|
let true_throw = lines.next().ok_or(MonkeyError::ParseError())??
|
||||||
|
.strip_prefix(" If true: throw to monkey ")
|
||||||
|
.ok_or(MonkeyError::ParseError())?
|
||||||
|
.parse::<u64>()?;
|
||||||
|
let false_throw = lines.next().ok_or(MonkeyError::ParseError())??
|
||||||
|
.strip_prefix(" If false: throw to monkey ")
|
||||||
|
.ok_or(MonkeyError::ParseError())?
|
||||||
|
.parse::<u64>()?;
|
||||||
|
|
||||||
|
// Remove empty line if exists
|
||||||
|
match lines.next() {
|
||||||
|
None => Ok(()),
|
||||||
|
Some(Err(e)) => Err(e),
|
||||||
|
Some(Ok(s)) => Ok(match s.as_str() {
|
||||||
|
"" => Ok(()),
|
||||||
|
_ => Err(MonkeyError::ParseError()),
|
||||||
|
}?),
|
||||||
|
}?;
|
||||||
|
|
||||||
|
Ok(Some(Monkey {
|
||||||
|
id: id,
|
||||||
|
items: starting_items,
|
||||||
|
operation: operation,
|
||||||
|
div_by_test: test_val,
|
||||||
|
true_throw: true_throw,
|
||||||
|
false_throw: false_throw,
|
||||||
|
})
|
||||||
|
)}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let file = File::open(&env::args().nth(1).unwrap()).unwrap();
|
||||||
|
let mut lines = io::BufReader::new(file).lines();
|
||||||
|
let mut monkeys: Vec<Monkey> = Vec::new();
|
||||||
|
|
||||||
|
loop {
|
||||||
|
match parse_monkey(&mut lines) {
|
||||||
|
Ok(None) => break,
|
||||||
|
Ok(Some(m)) => {
|
||||||
|
assert!(m.id == monkeys.len() as u64);
|
||||||
|
monkeys.push(m)
|
||||||
|
},
|
||||||
|
Err(e) => eprintln!("{:?}", e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let mut monkey_item_counts = vec![0; monkeys.len()];
|
||||||
|
let lcd = monkeys.iter().fold(1, |acc, m| acc * m.div_by_test);
|
||||||
|
|
||||||
|
for _round in 1..=10000 {
|
||||||
|
for i in 0..monkeys.len() {
|
||||||
|
monkey_item_counts[i] += monkeys[i].items.len();
|
||||||
|
|
||||||
|
for _item in 0..monkeys[i].items.len() {
|
||||||
|
let old_item = monkeys[i].items.pop_front().unwrap();
|
||||||
|
let new_item = monkeys[i].operation.perform(old_item) % lcd;
|
||||||
|
let new_i = if new_item % monkeys[i].div_by_test == 0 {
|
||||||
|
monkeys[i].true_throw
|
||||||
|
} else {
|
||||||
|
monkeys[i].false_throw
|
||||||
|
} as usize;
|
||||||
|
monkeys[new_i].items.push_back(new_item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
monkey_item_counts.sort_by(|x, y| y.cmp(x));
|
||||||
|
println!("{:?}", monkey_item_counts[0]*monkey_item_counts[1]);
|
||||||
|
}
|
||||||
|
|
158
day11/src/main1.rs
Normal file
158
day11/src/main1.rs
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
use std::num::ParseIntError;
|
||||||
|
use std::env;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{self, BufRead, Lines};
|
||||||
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
enum Operator { Add, Mul }
|
||||||
|
#[derive(Debug)]
|
||||||
|
enum Operand { Old, Imm(u64) }
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Operation { left: Operand, op: Operator, right: Operand }
|
||||||
|
impl Operation {
|
||||||
|
fn perform(&self, old: u64) -> u64 {
|
||||||
|
let left = match self.left {
|
||||||
|
Operand::Old => old,
|
||||||
|
Operand::Imm(x) => x,
|
||||||
|
};
|
||||||
|
let right = match self.right {
|
||||||
|
Operand::Old => old,
|
||||||
|
Operand::Imm(x) => x,
|
||||||
|
};
|
||||||
|
match self.op {
|
||||||
|
Operator::Add => left + right,
|
||||||
|
Operator::Mul => left * right,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Monkey {
|
||||||
|
id: u64,
|
||||||
|
items: VecDeque<u64>,
|
||||||
|
operation: Operation,
|
||||||
|
div_by_test: u64,
|
||||||
|
true_throw: u64,
|
||||||
|
false_throw: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
enum MonkeyError {
|
||||||
|
ParseError(),
|
||||||
|
ParseIntError(ParseIntError),
|
||||||
|
IoError(io::Error),
|
||||||
|
}
|
||||||
|
impl From<ParseIntError> for MonkeyError {
|
||||||
|
fn from(e: ParseIntError) -> Self { MonkeyError::ParseIntError(e) }
|
||||||
|
}
|
||||||
|
impl From<io::Error> for MonkeyError {
|
||||||
|
fn from(e: io::Error) -> Self { MonkeyError::IoError(e) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_monkey<B: BufRead>(
|
||||||
|
lines: &mut Lines<B>
|
||||||
|
) -> Result<Option<Monkey>, MonkeyError> {
|
||||||
|
let id = match lines.next() {
|
||||||
|
Some(line) => line?
|
||||||
|
.strip_prefix("Monkey ").ok_or(MonkeyError::ParseError())?
|
||||||
|
.strip_suffix(":").ok_or(MonkeyError::ParseError())?
|
||||||
|
.parse::<u64>()?,
|
||||||
|
None => return Ok(None),
|
||||||
|
};
|
||||||
|
|
||||||
|
let starting_items = lines.next().ok_or(MonkeyError::ParseError())??
|
||||||
|
.strip_prefix(" Starting items: ").ok_or(MonkeyError::ParseError())?
|
||||||
|
.split(", ")
|
||||||
|
.map(|item| item.parse::<u64>())
|
||||||
|
.collect::<Result<VecDeque<_>, _>>()?;
|
||||||
|
|
||||||
|
let op_line = lines.next().ok_or(MonkeyError::ParseError())??;
|
||||||
|
let op_vec = op_line
|
||||||
|
.strip_prefix(" Operation: new = ").ok_or(MonkeyError::ParseError())?
|
||||||
|
.split(' ').collect::<Vec<_>>();
|
||||||
|
let (left, operator, right) = (op_vec[0], op_vec[1], op_vec[2]);
|
||||||
|
let operation = Operation {
|
||||||
|
left: match left {
|
||||||
|
"old" => Operand::Old,
|
||||||
|
_ => Operand::Imm(left.parse()?)
|
||||||
|
},
|
||||||
|
op: match operator {
|
||||||
|
"+" => Ok(Operator::Add),
|
||||||
|
"*" => Ok(Operator::Mul),
|
||||||
|
_ => Err(MonkeyError::ParseError())
|
||||||
|
}?,
|
||||||
|
right: match right {
|
||||||
|
"old" => Operand::Old,
|
||||||
|
_ => Operand::Imm(right.parse()?)
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
let test_val = lines.next().ok_or(MonkeyError::ParseError())??
|
||||||
|
.strip_prefix(" Test: divisible by ").ok_or(MonkeyError::ParseError())?
|
||||||
|
.parse::<u64>()?;
|
||||||
|
|
||||||
|
let true_throw = lines.next().ok_or(MonkeyError::ParseError())??
|
||||||
|
.strip_prefix(" If true: throw to monkey ")
|
||||||
|
.ok_or(MonkeyError::ParseError())?
|
||||||
|
.parse::<u64>()?;
|
||||||
|
let false_throw = lines.next().ok_or(MonkeyError::ParseError())??
|
||||||
|
.strip_prefix(" If false: throw to monkey ")
|
||||||
|
.ok_or(MonkeyError::ParseError())?
|
||||||
|
.parse::<u64>()?;
|
||||||
|
|
||||||
|
// Remove empty line if exists
|
||||||
|
match lines.next() {
|
||||||
|
None => Ok(()),
|
||||||
|
Some(Err(e)) => Err(e),
|
||||||
|
Some(Ok(s)) => Ok(match s.as_str() {
|
||||||
|
"" => Ok(()),
|
||||||
|
_ => Err(MonkeyError::ParseError()),
|
||||||
|
}?),
|
||||||
|
}?;
|
||||||
|
|
||||||
|
Ok(Some(Monkey {
|
||||||
|
id: id,
|
||||||
|
items: starting_items,
|
||||||
|
operation: operation,
|
||||||
|
div_by_test: test_val,
|
||||||
|
true_throw: true_throw,
|
||||||
|
false_throw: false_throw,
|
||||||
|
})
|
||||||
|
)}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let file = File::open(&env::args().nth(1).unwrap()).unwrap();
|
||||||
|
let mut lines = io::BufReader::new(file).lines();
|
||||||
|
let mut monkeys: Vec<Monkey> = Vec::new();
|
||||||
|
|
||||||
|
loop {
|
||||||
|
match parse_monkey(&mut lines) {
|
||||||
|
Ok(None) => break,
|
||||||
|
Ok(Some(m)) => { assert!(m.id == monkeys.len() as u64); monkeys.push(m) },
|
||||||
|
Err(e) => eprintln!("{:?}", e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let mut monkey_item_counts = vec![0; monkeys.len()];
|
||||||
|
|
||||||
|
for _round in 1..=20 {
|
||||||
|
for i in 0..monkeys.len() {
|
||||||
|
monkey_item_counts[i] += monkeys[i].items.len();
|
||||||
|
|
||||||
|
for _item in 0..monkeys[i].items.len() {
|
||||||
|
let old_item = monkeys[i].items.pop_front().unwrap();
|
||||||
|
let new_item = monkeys[i].operation.perform(old_item) / 3;
|
||||||
|
let new_i = if new_item % monkeys[i].div_by_test == 0 {
|
||||||
|
monkeys[i].true_throw
|
||||||
|
} else {
|
||||||
|
monkeys[i].false_throw
|
||||||
|
} as usize;
|
||||||
|
monkeys[new_i].items.push_back(new_item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
monkey_item_counts.sort_by(|x, y| y.cmp(x));
|
||||||
|
println!("{:?}", monkey_item_counts[0]*monkey_item_counts[1]);
|
||||||
|
}
|
||||||
|
|
27
day11/test.txt
Normal file
27
day11/test.txt
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
Monkey 0:
|
||||||
|
Starting items: 79, 98
|
||||||
|
Operation: new = old * 19
|
||||||
|
Test: divisible by 23
|
||||||
|
If true: throw to monkey 2
|
||||||
|
If false: throw to monkey 3
|
||||||
|
|
||||||
|
Monkey 1:
|
||||||
|
Starting items: 54, 65, 75, 74
|
||||||
|
Operation: new = old + 6
|
||||||
|
Test: divisible by 19
|
||||||
|
If true: throw to monkey 2
|
||||||
|
If false: throw to monkey 0
|
||||||
|
|
||||||
|
Monkey 2:
|
||||||
|
Starting items: 79, 60, 97
|
||||||
|
Operation: new = old * old
|
||||||
|
Test: divisible by 13
|
||||||
|
If true: throw to monkey 1
|
||||||
|
If false: throw to monkey 3
|
||||||
|
|
||||||
|
Monkey 3:
|
||||||
|
Starting items: 74
|
||||||
|
Operation: new = old + 3
|
||||||
|
Test: divisible by 17
|
||||||
|
If true: throw to monkey 0
|
||||||
|
If false: throw to monkey 1
|
7
day12/Cargo.lock
generated
Normal file
7
day12/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "day12"
|
||||||
|
version = "0.1.0"
|
8
day12/Cargo.toml
Normal file
8
day12/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "day12"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
41
day12/input.txt
Normal file
41
day12/input.txt
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
abcccccccccccaaaaacccccccaaaaaaccccccccccccccccccccccccccccccccaaaaaaaaaaaaaacccccccccccccccccccaaaaaacccccccacccccccccaaccaaccccccccccccccccccccccccccccccaaaaaa
|
||||||
|
abcccccccccccaaaaaaacccccaaaaaaccccccccaaccccccccccaaaaccccccccaaaaaaaaaaaaaccccccccccccccccccccaaaaaaccccaaaacccccccccaaaaaaccccccccccccccccccccccccccccccccaaaa
|
||||||
|
abccccccccccaaaaaaaacccccaaaaaccccccccaaaacccccccccaaaacccccccccccaaaaaaacccccccccccccccccccccccaaaaacccccaaaaaaccccccccaaaaacccccccccccaaaccccccccccccccccccaaaa
|
||||||
|
abccccccccccaaaaaaaaccccccaaaaacccccccaaaacccccccccaaaacccccaaaccccaaaaaaccccccccccccccccccccccccaaaaacccccaaaaacccccccaaaaaacccccccccccaaaacccccccccccccccccaaaa
|
||||||
|
abccccccccccaaaaaaccccccccaaaaacccccccaaaaccccccccccaaacccccaaaaccaaaaaaaacccccccccccccccccccccccaaaaaccccaaaaacccccccaaaaaaaaccccccccccaaaaccaaccccccccccccaaaaa
|
||||||
|
abcccccccccccccaaaccccccccccccccccccccccccccccccccccccccccccaaaaccaaaaaaaaccccccccccccccccccccccccccccccccaccaaccccaaaaaaaaaaacccccccccccaaaaaaccccccccccccccaccc
|
||||||
|
abcacccccccccccccaaaccccccccccccccaaacccccccccccccccccccccccaaaccaaaacccaaacccccccccccccccccccccccaacccccccccccccccaaacccaaccccccccccccccaaaalllllccccccccccccccc
|
||||||
|
abaacccccccccccccaaaaaacccccccccccaaaccccccccccccccccccccccccccccaaaccccaaaccccccccccccccccccccccaaccccccccccccccccaaaaaaaaccccccccccccccckklllllllccccaaaccccccc
|
||||||
|
abaaaaacccccccccaaaaaaacccccccccaaaaaaaacccccaacccccccccccccccccccccccccaaaccccccccaacccccccccaaaaacaacaacaacccccaaaaaaaaccccccccccccaaakkkkllllllllcccaaaccccccc
|
||||||
|
abaaaaaccccccccaaaaaaaacccccccccaaaaaaaacccccaaaaaacccccccccccccccccccccaaaccccccaaaacacccccccaaaaaaaacaaaaaccccaaaaaaaaaccccccccckkkkkkkkkklsssslllcccaaaaaacccc
|
||||||
|
abaaaccccccccccaaaaaaacccccccccccaaaaacccccccaaaaaaccccccccccccccccccaaaaaaaaccccaaaaaacccccccccaaaaacaaaaacccccaaaaaaaacccaaaccjjkkkkkkkkkssssssslllcccaaaaacccc
|
||||||
|
abaaaccccccccccccaaaaaacccccaacccaaaaaaccccaaaaaaaccaaaccccccccccccccaaaaaaaacccccaaaacccccccccaaaaaccaaaaaacccccccaaaaaaccaaaajjjjkkkkkkssssssssslllcddaaaaccccc
|
||||||
|
abcaaacccccccccccaaaaaacaaacaacccaaaaaaccccaaaaaaaaaaaaaaccccccccccccccaaaaaccccccaaaaccccaaaaaaacaaacccaaaaaaacccaaaaaaaccaaajjjjrrrrrrssssuuuussqmmddddaaaccccc
|
||||||
|
abccaacccccccccccaaccccccaaaaacccaaaccaccccaaaaaaaaaaaaaacccccccccccccaaaaaacccccaacaaccccaaaaacccaaccccacccaaaaaaaaaccaaccaaajjjrrrrrrrrssuuuuuvqqmmmdddaaaccccc
|
||||||
|
abccccccccaaccccccccccccccaaaaaacccccccccccccaaaaaaaaaaaccccccccccccccaaaaaacccccccccccccaaaaaaccccccccccccaaaaaaaaaacccccccccjjjrrruuuuuuuuuuuvvqqmmmmddddaccccc
|
||||||
|
abaacccccaaaaccccccccccccaaaaaaacccccccccccccaacccccaaaaacccccccccccccaccaaacccccccccccccaaaaaacccccccccccaaaaaaaaccccccccccccjjjrrruuuuuuuuxyyvvqqqmmmddddcccccc
|
||||||
|
abaacccccaaaacccccccccccaaaaaaccccccccaaccccccccacccaaaaacccccccccccccccccccccccccccccccccaaaaacccccccccccaaaaaaacccccccccccccjjjrrttuxxxxuxxyyvvqqqqmmmmddddcccc
|
||||||
|
abaacccccaaaacccccccccccaacaaacccccaaaaacccaaaaaaaccccccccccccccccccccccccccccccccccccccccaaacccccccccccccccaaaaaaccccccccccccjjjrrtttxxxxxxyyyvvqqqqqmmmmdddcccc
|
||||||
|
abacccccccccccccccccccccccccaaccccccaaaaaccaaaaaaaccccccccaaccccccccccccccccccccccccccccccccccccccccccccccccaaaaaaccccccccccccjjjqrrttxxxxxxyyyvvvvqqqqmmmdddcccc
|
||||||
|
abccccccccccccccccccccccccccccccccccaaaaaccaaaaaaacccccccaaaccccccccccaaaccccccccccccccccccaaaccccccccccccccaaccccccccccaaccccjjjqqqtttxxxxxyyyyyvvvqqqqmmmeeeccc
|
||||||
|
SbaaccccccaccaaacccccccccccccccccccaaaaacccaaaaaaaaccccaaaaaaaacccccccaaacaaccccccccccccccaaaaaaccccccccccccccccccccccaaaaaaccciiiqqqttxxxxEzyyyyyvvvqqqnnneeeccc
|
||||||
|
abaaccccccaaaaaaccccccccccccccccccccccaaccaaaaaaaaaacccaaaaaaaacccccaaaaaaaaccccccccccccccaaaaaaccccccccccccccccccccccaaaaaaccciiiqqtttxxxyyyyyyyvvvvqqqnnneeeccc
|
||||||
|
abaaaaacccaaaaaaccccccccccccccccccccccccccaaaaaaaaaaccccaaaaaaccccccaaaaaaaaccccccccccccccaaaaaacccccccccccccccccccccccaaaaacciiiqqqttxxyyyyyyywvvvvrrrqnnneeeccc
|
||||||
|
abaaaaacccaaaaaaaccccccccaaaccccccccccccccaacaaaccccccccaaaaaaccccccaaaaaaaccccccccccccccccaaaaaccccccccccccccccccccccaaaaaccciiiqqtttxxxyyyyywwwvrrrrrnnneeecccc
|
||||||
|
abaaaccccaaaaaaaaccccccccaaaacccccccccccccccccaaccccccccaaaaaaccccccccaaaaaccccccccccccccccaacaaccccccccccccccccccccccaaaaaccciiqqqttxxxwwwwyyywwrrrrnnnnneeecccc
|
||||||
|
abaaaccccaaaaaaaaccccccccaaaacccccaaaaacccccccaaccccccccaaccaacccccccaaacaaacccccccccccccccccccccccccccccccccccccccccccccccccciiqqqtttwwwwwwywwwrrrrnnnnneeeccccc
|
||||||
|
abcaaaccccccaaaccccccccccaaaccccccaaaaacccccccccccccaaaaccccccccccccccaacccccccccccccccccccccccccccccccaaaacccccccccccccccccciiiqqqtttssssswwwwwrrrnnnneeeecccccc
|
||||||
|
abccaaccccccaaaccccccccccccccccccaaaaaacccccccccccccaaaaccccccccccccccccccccccccccccccccccccccccccccccaaaaacccccccccccccccccciiiqqqqtssssssswwwwrronnnfeeeacccccc
|
||||||
|
abcccccccccccccccccccccccccccccccaaaaaacccccccccccccaaaaccccccccccccccccccccccccccccccccccccccccccccccaaaaaaccccccccccccccccciiiiqqppssssssswwwwrroonfffeaacccccc
|
||||||
|
abcccccccccccccccccccccccccccccccaaaaaacaaaccccccccccaacccccccccccccccccccccccccccccccccaaacccccccccccaaaaaaccccccccccccccccccihhpppppppppsssssrrroonfffaaaaacccc
|
||||||
|
abcccccccccccccccccccccccccccccccccaacccaaaaacccccccccccccccccccccccccccccccccccccccccccaaaaaaccccccccaaaaaccccccccccccccccccchhhhppppppppppssssrooofffaaaaaacccc
|
||||||
|
abccccccccaaaccccccccccccccccccccccccccaaaaacccccccccccccccccccccccccccccccccccccaccccaaaaaaaaccccccccccaaacccccccccccccccccccchhhhhhhhhpppposssoooofffaaaaaccccc
|
||||||
|
abccccccccaaaacccccaaccccccccccccccccccaaaaaccccccccccccccccccccccccaaccccccccccaaccccaaaaaaaacccccccccccccccccccccccccccccccccchhhhhhhhhgppooooooofffaaaaacccccc
|
||||||
|
abaaccccccaaaacccccaacaaccccccccccccccccaaaaacccccccccccccccaacaaccaaaaaaccccaaaaacaacaaaaaaacccccccccccccccccccccccccccccccccccccchhhhhhgggooooooffffaaaaaaccccc
|
||||||
|
abaaacccccaaaacccccaaaaaccccccccccccccccaaccccccccccccccccccaaaaaccaaaaaaccccaaaaaaaacccaaaaaccccccccccccccccccccccccaaacaacccccccccccccgggggooooffffccccaacccccc
|
||||||
|
abaaaccccccccccccaaaaaaccccaaccccccccccccccccccaaacccccccccccaaaaaaaaaaaacaacccaaaaaccccaacaaacccccccccccccccccccccccaaaaaaccccccccccccccaggggggggfffcccccccccccc
|
||||||
|
abaaaccccccccccccaaaaaaaacaaaaccccccccaaaccccccaaaacccccccccaaaaaaaaaaaaaaaaccaaaaacccccaaaaaccccccccccccccaaccccccccaaaaaaccccccccccccccaagggggggfccccccccccccca
|
||||||
|
abaacccccccccccccaccaaaaacaaaaccccccccaaaccccccaaaacccccccccaaaaccaaaaaaaaaaccaacaaaccccccaaaccccccccccccaaaaaacccccaaaaaaacccccccccccccaaaaccggggcccccccccccccaa
|
||||||
|
abaacccccccccccccccaaacaccaaaacccccaaaaaaaaccccaaaccccccccccccaaccaaaaaaaacccccccaacccccaacaaaaacccccccccaaaaaacccccaaaaaaaaccccccccccccaaaccccccccccccccccaaacaa
|
||||||
|
abcccccccccccccccccaaccccccccccccccaaaaaaaaccccccccccccccccccccaaaaaaaaaaaccccccccccccccaaaaaaaacccccccccaaaaaacccccaaaaaaaaccccccccccccacaccccccccccccccccaaaaaa
|
||||||
|
abccccccccccccccccccccccccccccccccccaaaaaacccccccccccccccccccccaaaaaaaaaaaaccccccccccccccaaaaaaccccccccccaaaaaccccccccaaacccccccccccccccccccccccccccccccccccaaaaa
|
86
day12/src/main.rs
Normal file
86
day12/src/main.rs
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{self, BufRead};
|
||||||
|
use std::collections::BinaryHeap;
|
||||||
|
use std::cmp::max;
|
||||||
|
|
||||||
|
fn get(map: &Vec<Vec<i64>>, coord: (usize, usize)) -> i64 {
|
||||||
|
map[coord.0 as usize][coord.1 as usize]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let file = File::open(&env::args().nth(1).unwrap()).unwrap();
|
||||||
|
let mut map: Vec<Vec<i64>> = Vec::new();
|
||||||
|
let mut queue = BinaryHeap::new();
|
||||||
|
let mut end = (0, 0);
|
||||||
|
let mut starts: Vec<(usize, usize)> = Vec::new();
|
||||||
|
|
||||||
|
// parse input
|
||||||
|
for (i, line) in io::BufReader::new(file).lines().flatten().enumerate() {
|
||||||
|
let mut row: Vec<i64> = Vec::new();
|
||||||
|
for (j, c) in line.chars().enumerate() {
|
||||||
|
match c {
|
||||||
|
'S' | 'a' => { starts.push((i, j)); row.push('a' as i64); },
|
||||||
|
'E' => { end = (i, j); row.push('z' as i64); },
|
||||||
|
c => row.push(c as i64),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
map.push(row);
|
||||||
|
}
|
||||||
|
let (height, width) = (map.len(), map[0].len());
|
||||||
|
let mut costs = vec![vec![i64::MAX; width]; height];
|
||||||
|
let heur: Vec<Vec<i64>> = (0..height)
|
||||||
|
.map(|i| (0..width)
|
||||||
|
.map(|j|
|
||||||
|
max((i.abs_diff(end.0) + j.abs_diff(end.1)) as i64,
|
||||||
|
get(&map, end) - get(&map, (i, j))))
|
||||||
|
.collect())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
for start in starts.iter() {
|
||||||
|
queue.push((-heur[start.0][start.1], *start));
|
||||||
|
costs[start.0][start.1] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A*
|
||||||
|
let answer = loop {
|
||||||
|
// no route
|
||||||
|
if queue.is_empty() {
|
||||||
|
break None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let (_, (i, j)) = queue.pop().unwrap();
|
||||||
|
let cost = get(&costs, (i, j));
|
||||||
|
|
||||||
|
// found destination
|
||||||
|
if (i, j) == end {
|
||||||
|
break Some(cost);
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle neighbors
|
||||||
|
let neighbors = [
|
||||||
|
(i as i64, (j as i64) - 1),
|
||||||
|
(i as i64, (j as i64) + 1),
|
||||||
|
((i as i64) - 1, j as i64),
|
||||||
|
((i as i64) + 1, j as i64)];
|
||||||
|
for (nexti, nextj) in neighbors {
|
||||||
|
if nexti < 0 || nextj < 0
|
||||||
|
|| nexti >= height as i64 || nextj >= width as i64
|
||||||
|
|| map[nexti as usize][nextj as usize] > map[i][j] + 1
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let nexti: usize = nexti as usize;
|
||||||
|
let nextj: usize = nextj as usize;
|
||||||
|
let new_cost = cost + 1;
|
||||||
|
if new_cost < costs[nexti][nextj] {
|
||||||
|
costs[nexti][nextj] = new_cost;
|
||||||
|
queue.retain(|(_, (ri, rj))| *ri != nexti || *rj != nextj);
|
||||||
|
queue.push((-new_cost - heur[nexti][nextj], (nexti, nextj)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
println!("= {:?}", answer);
|
||||||
|
}
|
||||||
|
|
83
day12/src/main1.rs
Normal file
83
day12/src/main1.rs
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{self, BufRead};
|
||||||
|
use std::collections::BinaryHeap;
|
||||||
|
use std::cmp::max;
|
||||||
|
|
||||||
|
fn get(map: &Vec<Vec<i64>>, coord: (usize, usize)) -> i64 {
|
||||||
|
map[coord.0 as usize][coord.1 as usize]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let file = File::open(&env::args().nth(1).unwrap()).unwrap();
|
||||||
|
let mut map: Vec<Vec<i64>> = Vec::new();
|
||||||
|
let mut queue = BinaryHeap::new();
|
||||||
|
let (mut start, mut end) = ((0, 0), (0, 0));
|
||||||
|
|
||||||
|
// parse input
|
||||||
|
for (i, line) in io::BufReader::new(file).lines().flatten().enumerate() {
|
||||||
|
let mut row: Vec<i64> = Vec::new();
|
||||||
|
for (j, c) in line.chars().enumerate() {
|
||||||
|
match c {
|
||||||
|
'S' => { start = (i, j); row.push('a' as i64); },
|
||||||
|
'E' => { end = (i, j); row.push('z' as i64); },
|
||||||
|
c => row.push(c as i64),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
map.push(row);
|
||||||
|
}
|
||||||
|
let (height, width) = (map.len(), map[0].len());
|
||||||
|
let mut costs = vec![vec![i64::MAX; width]; height];
|
||||||
|
let heur: Vec<Vec<i64>> = (0..height)
|
||||||
|
.map(|i| (0..width)
|
||||||
|
.map(|j|
|
||||||
|
max((i.abs_diff(end.0) + j.abs_diff(end.1)) as i64,
|
||||||
|
get(&map, end) - get(&map, (i, j))))
|
||||||
|
.collect())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
queue.push((-heur[start.0][start.1], start));
|
||||||
|
costs[start.0][start.1] = 0;
|
||||||
|
|
||||||
|
// A*
|
||||||
|
let answer = loop {
|
||||||
|
// no route
|
||||||
|
if queue.is_empty() {
|
||||||
|
break None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let (_, (i, j)) = queue.pop().unwrap();
|
||||||
|
let cost = get(&costs, (i, j));
|
||||||
|
|
||||||
|
// found destination
|
||||||
|
if (i, j) == end {
|
||||||
|
break Some(cost);
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle neighbors
|
||||||
|
let neighbors = [
|
||||||
|
(i as i64, (j as i64) - 1),
|
||||||
|
(i as i64, (j as i64) + 1),
|
||||||
|
((i as i64) - 1, j as i64),
|
||||||
|
((i as i64) + 1, j as i64)];
|
||||||
|
for (nexti, nextj) in neighbors {
|
||||||
|
if nexti < 0 || nextj < 0
|
||||||
|
|| nexti >= height as i64 || nextj >= width as i64
|
||||||
|
|| map[nexti as usize][nextj as usize] > map[i][j] + 1
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let nexti: usize = nexti as usize;
|
||||||
|
let nextj: usize = nextj as usize;
|
||||||
|
let new_cost = cost + 1;
|
||||||
|
if new_cost < costs[nexti][nextj] {
|
||||||
|
costs[nexti][nextj] = new_cost;
|
||||||
|
queue.retain(|(_, (ri, rj))| *ri != nexti || *rj != nextj);
|
||||||
|
queue.push((-new_cost - heur[nexti][nextj], (nexti, nextj)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
println!("= {:?}", answer);
|
||||||
|
}
|
||||||
|
|
5
day12/test.txt
Normal file
5
day12/test.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
Sabqponm
|
||||||
|
abcryxxl
|
||||||
|
accszExk
|
||||||
|
acctuvwj
|
||||||
|
abdefghi
|
7
day13/Cargo.lock
generated
Normal file
7
day13/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "day13"
|
||||||
|
version = "0.1.0"
|
8
day13/Cargo.toml
Normal file
8
day13/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "day13"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
449
day13/input.txt
Normal file
449
day13/input.txt
Normal file
@@ -0,0 +1,449 @@
|
|||||||
|
[[],[[0,[10,1],3,[4]],9,[2,10,4,10]],[5,[0,0,[1,2,7,5]]]]
|
||||||
|
[[[],[[8,5,2,8,0],[4,7,0,5],[2,7,7]],4],[4],[2,8,[[9,4,8]],6,10],[[[3,0,2,5],[],4,[7,9],[1,5,10,9,6]],4],[]]
|
||||||
|
|
||||||
|
[[[8],0,[[3],10]],[]]
|
||||||
|
[[5,1,[[0,10,5],3,10],9],[[5,[0,9,3],[2,1,5],10]],[1,[[10,1,9,10],[10],2,1],[[9,0,8,6,7],1],[3]]]
|
||||||
|
|
||||||
|
[3,8,3,3]
|
||||||
|
[3,8,3,3,4]
|
||||||
|
|
||||||
|
[[6,[7,10,9,[1,4]]],[4,2]]
|
||||||
|
[[[[3,2,8,6,9],[6,2],6,[3,5,9,5]],[],4,[],6],[8,[6,8],9,[],10],[],[[8,[],3,10],[10,[5,0],7,[]],[[6,8]],[]]]
|
||||||
|
|
||||||
|
[[0,6,[3,1,[2],[8,6,3,8,1],6]],[6,[[3],[7,6,4,9],8,[6,4,8,8,1],7]],[]]
|
||||||
|
[[[[10,0],4]],[],[7,[[8],1],[[3,3,10,9,4],[0,8,2,0,5],[],[2,3,3,4,4]],10,6],[[],[[5,7,1],10],[[1,3,3],[10,9],[6,3,10],5]]]
|
||||||
|
|
||||||
|
[[[4],[7,1,[1,2],0,7],[[]]],[[7],5]]
|
||||||
|
[[[[1,2]]],[[[7,8,6,6],[],[],[]]],[[[10,10],7],[8,2,[6,2,7,9],[5],[1,7,9,2,10]],[2,1],[5]],[[],0,8,1,1],[3,[[6,2,5,8,8],[10,9,5]],[[7,5,6,3,8],[8,5],10,5]]]
|
||||||
|
|
||||||
|
[[4]]
|
||||||
|
[[],[3,5,1],[3,[7,0,[4,8]],[4,[4,7,2,4]]]]
|
||||||
|
|
||||||
|
[[[0],[[4,2],3],4,6,2],[],[0,[8,[0,7,8]],[7,0,[5],7,9],1,[]],[5,6,[]]]
|
||||||
|
[[4,[[4,10,1,1]]],[10,[[4,6,5,10,0],[3]]]]
|
||||||
|
|
||||||
|
[[7,[3,[],4],[[5],[9,8,6,5],8,4,10],[[],0,[10,0],[]]],[[6,6,[3,2,4]],4,9,[8,0]]]
|
||||||
|
[[],[6,[6,[6,8,10],1,7],[[8,0,5],[],3,3]],[6,0,[[2,2,8],3,0,[2,10,5,3,4],[3,6,2]],2]]
|
||||||
|
|
||||||
|
[[[[10,1,3,8,5],8,[],5,9],[1,3],5,10,[[5,4],[8,2],[1],1]],[[4],[6,6]],[[5],2,[[4,6,1,10],[]],[[9,2,8,10,4],[]],1]]
|
||||||
|
[[[[10,7],2,[3,5]],2,[[5,7,7,1,2],10,0,2]],[2],[[]],[8,[10,1],[[0,4],[6,6,9,5,5],[10,1,3,9,5],[6,0,9,0,0]],10],[[10,[1,0],6,[10]],[1,[5]]]]
|
||||||
|
|
||||||
|
[[4],[7,[[],[3,0,1]],6,4,10],[]]
|
||||||
|
[[[[4,3],1,0,[6]]],[[7],[[8,6,9,5],1,[2]]]]
|
||||||
|
|
||||||
|
[[10,5,[[7,9],[3,10,3,10,4],6,[6,7],4],2],[0,[10,6,[1]]],[7],[1,[3,[4,0,7]],7],[9,1,[[3,3,10,3],1]]]
|
||||||
|
[[[]]]
|
||||||
|
|
||||||
|
[[[2,4,[],[9,10,3,2]],1,[[5,7,6,0]],8],[],[0,9,9,9],[]]
|
||||||
|
[[[[0,6],[1,9,4,9,10]],9,[[7,7,2,4,9],[10,1,9,9]],9],[5,6,[10,[0]]]]
|
||||||
|
|
||||||
|
[[7,[[3,6,9,10,3],7,[1],[3,9],[]],3],[7,2],[],[]]
|
||||||
|
[[],[],[8,[[0,5],[3,5,7,8,10],2,1]],[]]
|
||||||
|
|
||||||
|
[[[5,[10,8,8],10,[5,5,10,5],1],[6,[6,3,0,2,6],8,3,[7,8,3]],[],[3]],[3,[[9,2,10,2,10],[6]],[9,7,0],4,[[3,3],5]],[[],0,[[1]],[],8],[[[0]],2],[[[10,3,0,2,9],[9,9,6,4],[7,1,2,6,5],[0,8],[2,2,5,0,7]],9]]
|
||||||
|
[[[4,[1,8,0,5,0],1,0,7],2],[]]
|
||||||
|
|
||||||
|
[[[[10],4,[],8,[]],[[10,8,6],[0],[2],[0],3]],[10,1,6,0,[]]]
|
||||||
|
[[[],3,[],[9,6,2],0],[9,2,3,[2,[1,8,5,8,3],0],5],[4,[0,3,[5,2,8,5,7],[6,6,5,7],[5,6,0,3,10]],0,[[9],[3,8,3,3,3],7]]]
|
||||||
|
|
||||||
|
[[[7],9,1]]
|
||||||
|
[[[5,[1,1,1,10],[9]]],[],[[],10]]
|
||||||
|
|
||||||
|
[[[4],[[2],[8],[],1],[]]]
|
||||||
|
[[],[],[[[5,2],3,2,[],[5,10,5,5]],1,[[6,7,2],[4,7,3,8,10]]],[[7,1],9,2],[9,5,[10],10,[7,10,7,[2,1,5,1,2],[]]]]
|
||||||
|
|
||||||
|
[[0],[8]]
|
||||||
|
[[],[[0,8,5,6,[6,5,8,8,3]],[4,[8,0,6],[3,8,0],5],6,0],[[8,7,[9],10],1,4,9],[4,[[4]],0,[10,[],[3,4],3]],[[[8,7,8,5,5],[6]]]]
|
||||||
|
|
||||||
|
[[[8]],[[[7,3,5,7,1],[9,8],[5],10,2]]]
|
||||||
|
[[[[8],[10,3,5,0,7],7,[2,1]],[]],[6,[[],4,7,10,0],[]],[]]
|
||||||
|
|
||||||
|
[[[[9,9,9,10,1],1,4,4],4,[[],1,[0,1,2,8,8],[0,7,6,3]]],[5],[[[0,1],6,[2,8,2],6],[]]]
|
||||||
|
[[6,1,[8,[10],6]],[2,[[5],[],[8,4,7],6,[]],[4,[3,5,7]],[[4]],[[1,1],9]],[[2,5,[0,1,9,4],5,[0]],7,[1,3,5,[],10],7,1],[]]
|
||||||
|
|
||||||
|
[[[[3,10,6,2,0],[5,0,5,5,7],7,[2,4],4]],[[0,6,10,4]],[4,[[],0,7]],[[2,[3,2,2,6],2],[[9,5,0],9,0,[1,6,8,9]],10]]
|
||||||
|
[[6,8,9],[[[]],[[0,0,7,7],1,9,[5,2,3],8],6],[[1],[6,2,[]],10,1],[[[8,3,2]],[5,5,5,[5,4,6]]]]
|
||||||
|
|
||||||
|
[[10,[]]]
|
||||||
|
[[[[10,1,0],[0,2,4]],[[9],1,[],3,10],10,[2,8,[6,8],2]]]
|
||||||
|
|
||||||
|
[[10,2,[],5,2],[[],9],[[[9],8,8,2],3],[[7,5,10],8,9,[],[2,2]]]
|
||||||
|
[[],[9]]
|
||||||
|
|
||||||
|
[[4,6]]
|
||||||
|
[[2],[[7,0,[3,0,10,8],8,[5]]],[[10,10,1]],[[8],8,[0],[[7,5,2,8,9],[],3,[],[5,10,10,9,0]],0]]
|
||||||
|
|
||||||
|
[[],[[]]]
|
||||||
|
[[],[[4,[10,6,0,5,4],[7,8,8],5],[4,[10],[8,4],2,[0]],[],9]]
|
||||||
|
|
||||||
|
[[7,[[0,4,8,7],[],[3,5,6,10,4],10,[5]]],[],[8,10],[8],[3,[[7,3,10]]]]
|
||||||
|
[[6,[4,3],9,[[5,10,5],0,10],9],[[8],5,[6,[]],[[6,4,8,8,7]]],[],[[]]]
|
||||||
|
|
||||||
|
[[[[6,6]]],[],[[7],[[7],5],[]],[3,[[6,1,9],6,8]],[[3]]]
|
||||||
|
[[2,[[],6,7,7,8],4,[8]],[[5,[],2,[5,2,8,7,4],2]]]
|
||||||
|
|
||||||
|
[[0,9]]
|
||||||
|
[[2,6],[[]],[[],0,6]]
|
||||||
|
|
||||||
|
[[[5],2,2]]
|
||||||
|
[[[8,9,[5,1,7,6,1],3,[]],[[1,4,1,5],[10,8],[9,4,7],2]],[4,3,[[6],[5],[3,10],[9,10,2,5,2],4]]]
|
||||||
|
|
||||||
|
[[8,1]]
|
||||||
|
[[[8,[1,10],8],[[3,2,7,3,10],9,10,[7,5],8],[7],2,2],[[1],6,[[10,5,5],[9,8,7,1],10,[7,0,9,10,10],[4]]],[2,[[2],[4,1,6,7]],[10,[8,1]],1,6],[1,[[7],0,[4,7,4,8,9],[10,9,3,5]],[[10,8,8],[]],8,2]]
|
||||||
|
|
||||||
|
[[[]],[[5,6,4,9],1,[[0,9,7,1,7],[9],[8]],3,10]]
|
||||||
|
[[0,[[5,7],[0,6,5],[1],6],8],[5,1],[[[9,4],10,4,[10,8]],[[7,7,10,2]]]]
|
||||||
|
|
||||||
|
[[[],0,[]],[],[],[[4,2,[7],10],[[8,8,7,8,5],[9,0],[5,7,4,2],3],7,[[0,3,8,3,8],4,1,4]],[[4],9]]
|
||||||
|
[[[3],[[10,0,6,7,7]],[[1,7,3,2],[10,6,3,2,7],8,[4],9]],[9,4,0,[10,[1,9,0,8,0],0],10],[4],[1],[9,2,[],0]]
|
||||||
|
|
||||||
|
[[5,[[1,0,6,7],[7],[8,0,6,7],6,[8,2]]],[1]]
|
||||||
|
[[3,[9,[6]],[]]]
|
||||||
|
|
||||||
|
[[[[8,9,5,9,10],[4,10,6,3],[0,9],5],[[],0,[5,6,6],[0],8],6],[[2,3,3,[0],[3,10]]],[],[[[3,9]],5,[],[1,7,[6,10],0,[0,4,10,5]]],[[5,1,[10,3,8,2],[]],[],[8,[],0],[[9,7,1],[8,6]],[]]]
|
||||||
|
[[[],[10,[5,2,9],[5,2,8]]],[[3,3]],[[1,8],6,6,8,7]]
|
||||||
|
|
||||||
|
[[5],[1,10,[],10]]
|
||||||
|
[[1,6,9,1],[8,7,9],[3,3,5,1],[[9,8,[4]],[[4,3],10,[10]]]]
|
||||||
|
|
||||||
|
[[[[5,6,9],2,0,[7,1,2]],[[1,10],5,[8,3,6,4],[],[5,10]]],[9,9,6],[9],[[1,4,4],3],[[[7],10,[6],[7],[9,3,3,7]],6,4,6,10]]
|
||||||
|
[[[[1,3],[6,8,6,3,2]]],[[[],[2,6]],1,4,[[],[4,6,10,10,10],[],[9,2,10]],0],[2,[[0],[1,1],1],[[6,0,3,3,3],[7,10,1],[10,10]],[4,[3,8,5,2,9],[5,2],[4,5]]],[9,[]]]
|
||||||
|
|
||||||
|
[[9]]
|
||||||
|
[[],[[[8,2,9],10,0]],[0,[2,7,[2,9,8]],5,[]],[]]
|
||||||
|
|
||||||
|
[[7,8,[[9,7,10,10],8]],[[0],[[1,10,7,4],0,[]],[[]],[1,0,[4,7,3,3,5],[4]]],[]]
|
||||||
|
[[10,2,6,[],[[7,0,3,3],10,[9,2,7],7,4]],[[[3,1,1,1,9],1],[2,9,[]],8],[8],[1,8,8,[6,[4,5,5,10,0],9,9]],[]]
|
||||||
|
|
||||||
|
[[],[8,[],[[],[9,2,2],7],[[9,7,6],10]],[[0,[8,6,6,9,5],10],10,[3]],[[1,[10,4,1,5],2,[8,8,8,4,7]],8,4,1,[1,[3,2,6,7,5],3]],[6]]
|
||||||
|
[[],[[[3,5],[6,3,5],[2,9]],[[6,10,4,2],4],9],[[[3,6,6],4],[[4],[5,0,5],2,2],[9,[8,7,5,3]]]]
|
||||||
|
|
||||||
|
[[7,[[8,2,3,10]],5,[7]],[[[6,6,5,2]],[2,1,[],1]]]
|
||||||
|
[[0,4,6],[10,4,8],[9,[[0,9,10,5],8,9,[7,7]]]]
|
||||||
|
|
||||||
|
[[[0,[8,8],5,[4,10,8,9]],4],[4,[1,[6,0],0,3]],[5,5,[8,[10,2,4,8,2],[5],6],[8,[8],5],[4,[],4,[0,2,8,4]]],[[[7,0,2,2,4],10,[],9],[],[[1,8,10,4,6],1,0,[]]],[0,6,[5,2],3]]
|
||||||
|
[[[[7,2,9,1,1],1,[1,5,4]],[],7,9,9],[3,9,1],[7,9,[6,8,5,[2]]],[3,[]]]
|
||||||
|
|
||||||
|
[[[5,[],1],9,[[2],8,[1,7,5,0],[6,5,9,1]],[2,[8,4]]]]
|
||||||
|
[[[2,9,7,[10,5,0]],3,7,8],[[[3]],[]],[[10,0,1,6,[]],[[4,9,3],2],8,[6]],[[6,7,6,[1],[2,7]],[4],[5],[[10],[],[0,6],1]]]
|
||||||
|
|
||||||
|
[[],[[],[1,6,[9,9,8,1],5],6],[],[5,5,[],5],[]]
|
||||||
|
[[[[5,0,7]],9,[[7,6,9],[],10,[2,1]],8],[[[7],5,[3,1,6,9],2,[10]],6],[5]]
|
||||||
|
|
||||||
|
[[],[],[1,[[0,0,3,2,10],[0,5,0,10],7,1,5]],[[]]]
|
||||||
|
[[3],[[]],[6,3,5],[[[7,7,4,7,4],[8,7],[10,5]],[[1,4]],5]]
|
||||||
|
|
||||||
|
[[9],[[1,[4,0,2,5],[1,8,3,10,9]]],[9,[[4,9,10,10,8],5],[],10],[7,2,[[6,8],[9,9],6],5]]
|
||||||
|
[[3,9,[[7,5,7],[4,8,1,10],0,0],[9,[6,0,0],5,9,[7,10]],5],[],[10]]
|
||||||
|
|
||||||
|
[[8,6,[[],[8]],6,7],[[[],[3]],[10,1,[6],[4],[4]],1],[2,[[6,2,8,10],[],9]],[2,10,10,[8,[9,3,0],[2,3,6]],5],[9]]
|
||||||
|
[[5,3],[9]]
|
||||||
|
|
||||||
|
[[[[2,0,0,7],[],[10],[],[4,2]],[[1],8,[2],[8,3]]],[[0,[6,0,1,6],[7,0],[0,9,3]]],[],[[0,[4,7]]],[6,[8,[10,1,9,9],1,[2,0,7,2]],1,[[5,7]]]]
|
||||||
|
[[0,[],1]]
|
||||||
|
|
||||||
|
[[[8],[7,0,[]],1]]
|
||||||
|
[[0],[]]
|
||||||
|
|
||||||
|
[[8,[[0,8,5,7],4,0,[2,7,0]],7,[],4],[]]
|
||||||
|
[[[[4,0,6,9,6],[7,2,9,9],[1,3,7,7],3],6],[],[4,9,4,3],[[],[],[[]]],[7,[]]]
|
||||||
|
|
||||||
|
[[[[],8,[],3,10],0,6],[1,0,3,[[]]],[]]
|
||||||
|
[[[3],7],[9,[3,7,[10,6,9,7]],[5],[9,[]]]]
|
||||||
|
|
||||||
|
[[],[[7,6,[2,3,8,9],0,[3,2,4,9]],[4]]]
|
||||||
|
[[4,[[0,0],[3,7],2],[[7,0],5,9,[1,6,6,8,3],8]]]
|
||||||
|
|
||||||
|
[[[5,2,[5,1,6,8]],[8],2,[[3,6],[1,0],[5]],[3,1,[6,10],10,4]],[],[[8,[10,9,4,9,6],7,1],5],[5,[10,[2,2,5]]]]
|
||||||
|
[[7,[],7],[1,[[10],10,[5,0,0]],5]]
|
||||||
|
|
||||||
|
[[0,[0,[4,0,3],[]],7,0],[3,[]],[[[3],[]],[2],[0,[9,9,8],[9,9],[1,6,9]]]]
|
||||||
|
[[6,[[2,6,8],[5,0],6],8,8,[]],[],[[10,3,[6],[2,5],6],[],[7]],[[8,8,10]]]
|
||||||
|
|
||||||
|
[[[9,10,7],4,[[0,6,1,9],[],[4,10],[6,3,2,7,5]],[4,0]],[[[3,5,4]],9,[],1]]
|
||||||
|
[[8,[[5,10,9,3]],[[10,6,3],2,[8,0,2,8,3],[5,4,7],10],7],[1,3,[[0],[7,0,8,4,8],10,2,7],[7,7,[],[9,5,4]],6],[[],[[1,8,4,9],5,8,1,4],3],[],[8,[9,[10,1,3]],4,[8,[7,3,2,3],7,[10]],[0,7,[5,10,1]]]]
|
||||||
|
|
||||||
|
[[4,10,[]],[2],[2,7]]
|
||||||
|
[[5],[[5,6,8,[10,5,1]],5],[0,[6,[10,2,4,5],1,7],1,[9,10,[9,9,1,10,10]],[[8],[5,0,9,0,5],[3],[8,4,10]]]]
|
||||||
|
|
||||||
|
[[[[10,6,2],[],[6,9,0,4,2],6],[],[10,4],1],[[10,[3,1,2,6],[9,3,1]],6]]
|
||||||
|
[[9,[]]]
|
||||||
|
|
||||||
|
[[[],[[2,10,6,0],9]],[10,0],[6,[]]]
|
||||||
|
[[6,[],[[10],[]],[[9],10]],[0,[4],8],[[8,[7,5,9,2,3]],3,6,9]]
|
||||||
|
|
||||||
|
[[[]],[],[6],[[3,[10],[3,2,2,8,0],[1]]]]
|
||||||
|
[[],[[],6,8,[[10,7,2,9,9],[8,8,2,5]],0],[[8,[0,10,2,8]],[8,9,2,5],3,[[9,1,7,4,10],[1,8],[],0],[]],[[7,1],7,[8,3,0,3,[6,7,6]],2]]
|
||||||
|
|
||||||
|
[[[[8,8,8]],[10,[],4],10],[]]
|
||||||
|
[[],[],[10,[[8,8,5,10,2],3],8,[[4],[],[2,1,4,9,6]],[[7,1]]]]
|
||||||
|
|
||||||
|
[[7,8,9,[],[0]]]
|
||||||
|
[[[],10,9,[[1],3,0,[9,7,9,5],5],[]],[2,[[7,3,1,4],[7,3]],2]]
|
||||||
|
|
||||||
|
[[[]],[[[9,1,7,2,1],[4],4,3,1],10,5,[[3,3]],7],[2,4,8,[[8,4],[7,9,5,2,3],1],1],[9,[[6,7,4,8],[]],3],[10]]
|
||||||
|
[[],[]]
|
||||||
|
|
||||||
|
[[7,6,8],[4,[[2],[1,5],5],1,9,8],[[]],[],[]]
|
||||||
|
[[6,9,6,8,[6,[],[4,6,1,7,4],3]],[[6,[4,0,6,4,9]]],[[[]],8,[]],[[[1,6,1],[3,10,4],[9],2]],[0,0,[[2],[7]],6,[[10,6],8,6,5]]]
|
||||||
|
|
||||||
|
[[[7,[10,1,1,7],[0,0,10,3,3],[]],1,[[10,5,1],[7,4,2,5,6]]],[2,[10,[2],[8],2],[4,[9,4,9,0,1],[0,2,4,2]]],[2,9,[[2],[10,10,8,0],[],7],8,[1]],[],[1]]
|
||||||
|
[[],[1,[5,4,[6,2],[1],0],7,[[]]],[],[1,7,2,4]]
|
||||||
|
|
||||||
|
[[2,7,[[]]]]
|
||||||
|
[[[10],[[7]],[5,[3,9,7,2],4,5,1],[[4,10,0,8,3],[0,2,10,5,5],[0,7,0,0],1,1]],[[[1],[7,9,1,2,1],[5,1,1,1,6]],[[9],7,[6,9,0]]],[[6,[4,2],3,[6,1,5,3],10],[4,6,[8]],[3,10,[6,2,10,9]],10,9]]
|
||||||
|
|
||||||
|
[[[10,8,[7]]],[[[],[5,3]],[10,[8,5,5],0,5],[]],[[4,[3,2,5],8,[]],5,1,4],[[[7],3],[5,4],8,10,1],[[6,10],4]]
|
||||||
|
[[[[],[1,6],8,[7]],8],[9,[9,[6,5],[8,0,6],6,4],10,[],[[7,5,7,10],2,[6],[8,9]]]]
|
||||||
|
|
||||||
|
[[[],[[4,10],2,1,[]],2],[2,9,8,3,10],[7,[0,1,[7,10,10,9,5],9,[]]]]
|
||||||
|
[[2],[[3,3,5,1],1,9],[9],[6,[4,[0,6,7,4,6],[3],[]]],[[[],[],0,7],[5,[6,5],[9,10],[0,2,5],5],2]]
|
||||||
|
|
||||||
|
[[[8,2,[9,5,8],8,[7,2,2,9,5]],7,[[4,1]],1]]
|
||||||
|
[[[[0]],[],[[9],1],7,1]]
|
||||||
|
|
||||||
|
[[[9,4],[],[]]]
|
||||||
|
[[[],9,0,[]],[5,[[4,3,3],6,[3,5,1],[],1],[1,[7]],[4]]]
|
||||||
|
|
||||||
|
[[2,8,7,[10,[0,4],[3,9,1,5,2],1],[[3],[0]]]]
|
||||||
|
[[3,4,[[2]],4],[],[8,9,6,[7,[5,3,5,7],[]],[[10,7]]]]
|
||||||
|
|
||||||
|
[[],[[],[5,6,2],7,8],[[3,3,5,1,2],[2,1,2,3],6,[],3],[5,8,6],[3,[7,7,[],[],5],8,[[10,0,5,7,6],[5,9],7,[]]]]
|
||||||
|
[[[8,0,[0,7,6],3],[1,[],[3,5,10,0],[3],[3,10,5,4]],[[7,10,6,0],[7],[],2,[9,2]],3,3],[10,[[3,1],8,[1,0,7],[],8]]]
|
||||||
|
|
||||||
|
[[[10],8,9,0],[[0,[4,0,9],[]]],[3,[[],7,[4,7,5],4],[9,10,7,[10,10,10,8],5],3,8]]
|
||||||
|
[[[],2,10,[4,5,[9,9,6,0,10],[1,0,1],3],9],[],[[6,[6],4,3]]]
|
||||||
|
|
||||||
|
[[6,9,[[2,10,9]]],[[[4,7,2,6],[]],[[7,8,5,2,8],8,[0,8,0,4,3],1,[3,10,10,10,0]],3,9,[[3,10,5],[7,5,0]]],[[3,0,[3],3,0],[[],5,[1,4],6,[1,4,0]],[[5,7,0,4]]],[]]
|
||||||
|
[[[0,7,[10],[1],[7,5,7]],[9,[3,9,6],7,8,9],[],2,[]]]
|
||||||
|
|
||||||
|
[[10,6,8,10],[8,7,[[8]]]]
|
||||||
|
[[[3]],[6,10],[[4,3,[],[7,0,7,1],7],8],[9,[5,[7]],[3,[10,2,7],[8,9]],7],[]]
|
||||||
|
|
||||||
|
[[0,[[7]],[[9,6,7],5,5]]]
|
||||||
|
[[[[0,9],0,[0,7,2,1,1]],[]],[5,6,[[4,6,5,8],4],6],[4,[[6,6,9,5,8],[]],3,8],[[[1,1,8,6,7]]]]
|
||||||
|
|
||||||
|
[[3,[[2,8,4,2],7,[10,0]],[0,3,[10,6,9],0,[10]],1,5],[4],[[0,[7,0,5,0],0],10,4,8,1],[5],[[[8,1],8,[8,4,5,10,9],6],[[9,1,7],[0,8]],[10],3]]
|
||||||
|
[[[6,[0,1,1,4],2,6,[]]],[[],4,[[0],[0]]],[3],[[],[],4]]
|
||||||
|
|
||||||
|
[[4,0,6,9],[[7,[1,6,10,8],8],[0,[]],1],[1,6,9,10]]
|
||||||
|
[[[],[[7,7],[10,1,10,9],[1,9,6],[]],[[8]],4,[]],[],[[10,2,[]],4,[[10,0,5,1],[6],7],[1],1]]
|
||||||
|
|
||||||
|
[[1,[[3],[],10,0,8],[7,9,[4,9,2]],[[1,7,8,5,0],[0,9,5,9,5],0,[3],4]],[[],4,1,[[3,8],[],7,0,1]],[[10,8,[0],[8,5,6],10],4,1,[2],[]]]
|
||||||
|
[[5]]
|
||||||
|
|
||||||
|
[[5,[[9,4,9,6],[0,6],2],[0,0,[6,0,9,10],[3,3,9,6,0]],[8,3],9],[[[6,6,1]],[[0],5,3,[6,8,0,4,10],10],6,[[1,4,4]],6]]
|
||||||
|
[[8,0,[[],1,[0,4],2]],[[],[]],[],[[10],[0,1,9,[2]]]]
|
||||||
|
|
||||||
|
[[],[3,[[10],[3,5,1,0,6],[0,9,9,10],0]]]
|
||||||
|
[[[1,6,[5,9,6,6,8],[2,9,6,4,3]],[],[],[[1,9],[7,3,6,7],4,9,8]],[[],[7,10,6],9],[6,[0,9,4,[4,7,1,7],6],6],[9],[[[0,8,9],[]],6,[4,7,9,2,3],[0,[6,3,6,2,6]]]]
|
||||||
|
|
||||||
|
[[[6],[[3,8],[4,2,3,9]],0,[[9,7,7],[],[],[7],[3,0,0,2]]],[8],[10,7]]
|
||||||
|
[[2,6,6],[[4,8,9],[[6,8,0],1,3,[4,3,8,0,3],[7,3,1,10,4]],[[2,3,7],[4,7,10],2],[[1,5,0,10,9],3]],[[[6,1,3,0]],2,[[1],8,2]],[[0,10,[1],[4,7,0]],[[1,5],[2],1,8,[9,1,7,0,1]],9],[6,10,[8,7]]]
|
||||||
|
|
||||||
|
[[9,[[7,4,9],[]],[9]]]
|
||||||
|
[[[[]]],[10],[4,[3,[2,5],8,0,8],7],[]]
|
||||||
|
|
||||||
|
[[[[7,3,10,4,9],4,10,2],[8],[[],[],6,10]],[[[7,4,9,9,5],3],10,1,1],[2,[1,8,[],[7,0]],1,[[3,9],6,[2,10],3],[8,0]],[[3,6,[5,5,1],[4,1,0,9]],[3,[3,1,5,5]],6]]
|
||||||
|
[[[[10],1,[10,2,3,4,2],2],[]]]
|
||||||
|
|
||||||
|
[[3,3],[[[8,10],2,[5,4]],[2,[7,3,8],[0,4,3,7,2]],[0],4]]
|
||||||
|
[[6,7,6],[[5,3],8]]
|
||||||
|
|
||||||
|
[[5,5,[6,[8,8]],5,[]],[10,[],5,10,6],[[[9,6,0,6],[0,5,6,1,0],[1,0,6,3,7],4],[5],9,[],4],[],[[3]]]
|
||||||
|
[[[[2,4],[3,7,3]],[[0,1],[9,0,7,7,10],[6,4,0,0,0],[6,7,4,5,8],[8]],10],[0,3,[6,8,[],[7,6,1,2,7],3],[2,[],8,2]],[],[[8],1,3]]
|
||||||
|
|
||||||
|
[[[[9]]],[[],[[],[7,6,0],[1,2,9,5]],[]],[8,9,9]]
|
||||||
|
[[8,1,3,6],[]]
|
||||||
|
|
||||||
|
[[[1],[8,7,3],[[8,4,9],4]]]
|
||||||
|
[[2,9,[[2,7,2]]],[1,0,[7,[8,4,8,8],[],[],[]]],[8,[[6,5,2,5]],9,[3],[4,0,[0,2,5,6,2],[2,3,4,3]]],[],[5,3,[2,8,4]]]
|
||||||
|
|
||||||
|
[[8,[8,[6,5,5],1,[7,10,4,2,0]],1,[1,5,[7],[2,2,4,10,1],[8,4,7]],4],[[1,9],[8,[3,8,0],[],0],[[8,5],[8,8,5,7]],[[8,4,1],2],8],[],[7,[[5]]],[[5,[4,8,1,0],[10,0]],[[10,1,9]],4,1,3]]
|
||||||
|
[[[[9],0,9,2,6],[6],[[1,0],8,[3,4,3],[10,0]]],[2]]
|
||||||
|
|
||||||
|
[[7]]
|
||||||
|
[[[6,10,[3,6,7,9]],[[0,3,1,7],[8,8,0,10],1,[]]],[0,1],[8,[7],[[7,5,10,0,4],[7,3],8,[9,9,4,0]],[7,8,[10,0,3]]]]
|
||||||
|
|
||||||
|
[[],[],[]]
|
||||||
|
[[2,4,[],5,7],[10,[4],[[5,5,5],[4,0,10,1,10],[]],4,[]],[4],[]]
|
||||||
|
|
||||||
|
[[[]],[[7,8,7],[[2,3,10,2],[0],3,[5,2]],[]],[9,[0],[[4,8,4,7,2],[0,2,3,3],5],9],[[[],[]]],[1]]
|
||||||
|
[[1,[10,[7,4,9,6]],[4,[6,9],10,2]],[[],[9],4,4],[6,[[9,2,0,4],[7,5,1],[2],4]],[2,9,[7,[5],[3],6,[7,4,2,7,8]],5],[[[10],10,[0,2,4,2,0],[6,0,0,4,10],[]],7,9,2,[6]]]
|
||||||
|
|
||||||
|
[[[[5,6,7]],8,1,[[8,7,1,3]]],[7,2],[[5],5,0],[[8,10],8,0,[1]],[[[2,0,8,5],1,[0,6,1]],[]]]
|
||||||
|
[[],[[2,6,2]]]
|
||||||
|
|
||||||
|
[[],[],[[1,3]],[[[9],[6,3,4,3],[9,0,6,5]],[3,[],4,9,[3,6,0,2]],8],[[4,[4,5],0,4,[4]]]]
|
||||||
|
[[[],1,4,6]]
|
||||||
|
|
||||||
|
[[[2,[1],[],9,[9,5,8,6]]],[5,[[4,3,3,5],[],10,[10,3,8]]],[2],[9],[[10,0,9,[2,10,0,7,4]],[[],5]]]
|
||||||
|
[[[[],8],[4,5,5,[8,1,7,8,4]]]]
|
||||||
|
|
||||||
|
[[4],[[[5,2,7],[9,7,0],[4,1,7],[1,6]],[],[[5,8],[8,2,5,3,1],1,2],0,[]],[[6,[10,4,2],0,10,[1,8,1]]],[[8,7,[6,9,6,6]]]]
|
||||||
|
[[],[[7,[],9],[[8],[5,3],[7,1]],[10,7],5,4],[7,0],[[6,[10,2,8,9,10]],[9,[0,4,10,0,9],[10,9,6,7]],[],[[1,10,10,5]]]]
|
||||||
|
|
||||||
|
[[5,[4,6,[10,4,7,4,8]],[9,[9,1,8],[8,9,3,2,4],[10,10,9,8,7]],2,[9,3]],[0,7,[[3,2,2]],[]],[9,[],10,3],[2,[],2]]
|
||||||
|
[[10,[[7,10,6],[5,5,6]],[5,[6,0,8],7,4,[2,8,7,0]]]]
|
||||||
|
|
||||||
|
[[4,[[2,4,7],[5,7,0],[8,0,0],[3,1,4],7],[7,[9],[6,9,2]],4,[8]],[10,[],6],[[5],0,10,[1],[[]]],[[[5,8,3,3],10,10,9,[]],1,[0]],[[],[0,[7,8],[0,5,2,8,4]]]]
|
||||||
|
[[4,[0,9,[4,9],[],9]]]
|
||||||
|
|
||||||
|
[[],[10],[[],[3,[5,7,10],0],[],[0]],[4,4,[[],5,[9,0,8,9],1]],[]]
|
||||||
|
[[3,[],[[]],[[2,5,6,8,6],8],7],[5,5,4],[[9,[],7],[[2,5,9,7,7]],[[5,1,0],[8,2],[1,2,4,6],[5,1,2,0],[0]],[0,5,[0,0,10,0]]]]
|
||||||
|
|
||||||
|
[[[[8,9,2,0],5],0,6]]
|
||||||
|
[[[[],[1,3,3,5],[10,1,2,5],6,[1,8,5,0]],[8,8,9,8],3,[3,[],[4]],[8,[],8,0,5]],[7],[[3,0,5,10,[]]],[],[[2,4,2,[10,8,8,6,7],0],[[2,5,3,7],4,[6,10,10],[1,10,0]],9,[[6],4,1]]]
|
||||||
|
|
||||||
|
[[[4],[[9,2,10],[7],[2,10,5,2]],6,[4,[1,10,3]]],[6]]
|
||||||
|
[[5,[[5],8,10,[1,2,2,10,4],0],[[1,10],[3,0,10,2,8]],[[],0,[7],1,[2]]]]
|
||||||
|
|
||||||
|
[[5,4,0,[[8,3],4]],[10,[[],[6],[],[],9]],[[9],[],[[0,4],5,0]]]
|
||||||
|
[[[[2],6,8,9],3,[[9,7,3,4,2],1],4,[10,3,6,[7,1]]],[8,5,[],[[3,5,9],6,[2,7,3],[7,6,8,4,3]],3]]
|
||||||
|
|
||||||
|
[[[3,[1,10,0,3,8],10],5,[3,[3,5,0,10],4,[8,3],[7]]],[],[4,[],[4,[2,5,8,0],0,[6,2]],7]]
|
||||||
|
[[6,[[7],6,7],5],[4,8,10,[[7,1,2],2],[[1]]],[1,[4,[3,5,4,6],[0],[8,9,1,1]],1]]
|
||||||
|
|
||||||
|
[[[[8,8],[0,8]],5,7,[1,6,[7,3,10,9,8]]],[5,4,1],[],[6,10,0],[6,3,[[5,0,4]],[[9,9,6,8,2],[],3,[1,10,7,9]]]]
|
||||||
|
[[],[5,10,[[5,5],[5,5,10],[3,7,5]]]]
|
||||||
|
|
||||||
|
[[[4,[9,7,7,1,4]],[7,[1,5,5],[8]],[[3,10,2,0]]]]
|
||||||
|
[[9,3,[[9],[],6,7],[[3],[7,2,10,8,4],[5,5,6],[]],3],[],[1],[],[3,[0],5,[[7,2,10,3,10],3,[2,9]]]]
|
||||||
|
|
||||||
|
[[10,[[7,4,0],[7,10,5,2]],[8,[10,8,2]],[]],[[[5,3,10,5,0],6,0,[]],9],[1,5,[[1,3,5,9],6,7],[[8,6,6,6],1,[10,4,2,0,4],9,7]]]
|
||||||
|
[[6,7],[[8,[],7,1,8],7,4,[3,7,5]],[]]
|
||||||
|
|
||||||
|
[[2,[3,[6,3,8],[3,3,4,9,10]]]]
|
||||||
|
[[4],[[6,[],[5],[4,9,10]],[9,8],4],[[[]],[5,[6,8]],4],[0,9],[[[5,9],[6,8,8,0,8],[6,5],0,[]]]]
|
||||||
|
|
||||||
|
[[0],[[[7,3]],[6,[8,0],[0,4,10],9,2],4]]
|
||||||
|
[[9,[5,[4,3]]],[3,1],[[],5,[[],[5,6],[4,4,1,5],[9]],6],[10,[[0,6,6,5,1],[4,1,8],8],9]]
|
||||||
|
|
||||||
|
[[[[3,7,10,1,4],3,6,[9,2]]],[[],[[1,5,4,2,10],[10],6],10,[[8],[4],[0],8]],[[[]]]]
|
||||||
|
[[9,[[],0,[7,10,8,2]],1],[4],[[],[3,2,9],[3,[0,1,0,10]],1,6]]
|
||||||
|
|
||||||
|
[[[[5,7,5,6],9,[7,9,5,2,2],[9]],[[7,10,8,4,2]]],[3,2,0]]
|
||||||
|
[[[],[[6],[6],[7,6,8,10],[4,8,6,8],[0]],5,4],[]]
|
||||||
|
|
||||||
|
[[6,2,[],[[2,7,9,9]],[]],[0,[[2,1],4,[4,3],1],5,[3,[7,2]]],[7,[]],[1]]
|
||||||
|
[[9,5,3,[4,10,[8,8,2,4,7],[1]],7],[3,[]],[[[9,6,3,8,3],[],[8,9,3,6]],[8,9,[2,1]],6],[[[7]],[[7,10,6,10],8],8,[2,0,[3],0]]]
|
||||||
|
|
||||||
|
[[[],[[6,0,1,9,5],1]],[10,9,[[],5,7],[7,[6,6],3,[1,1]],[[],10,[9],[1,7]]],[1,1]]
|
||||||
|
[[4,[4,[4,5],[9,2,1],[7,7,5],[9,8,6,4]]],[[7,[0,10,10,3,4],5],5,7,1,[[5,8,10]]],[[6,[],3],8],[3,10]]
|
||||||
|
|
||||||
|
[[0,[[3,2],10]],[10,0,4,[[2,10,2],[5]]],[9,[[3,8,2,4]],6,8,[7,[6,0,10,5],[8,7],[6,3,7,7,6],[4,10,0,6,1]]],[]]
|
||||||
|
[[[[0,10],10],0,[[7,10,2],[7,7,3,7],10,7],[[5],0,3,9,5],[[],1,[5,1,3,5,8],[7,0,9,8,10]]],[],[],[3,[1,[9,2,4,8,10]],8,[[],3,[1]]],[[9,[9,1,1],10],[[9,3],[8,3,10,5],1],[[0,1,4,0],[6,10,3,7],[2,3]],[9,[],[2,1,3,4]],7]]
|
||||||
|
|
||||||
|
[[[[10,9,8],[1,10,2,9],2,2,[0,0,8]]],[[],10,7,[],[]],[3,[7,[8,5,10],4]],[6,7,4,0],[[0,[7,0,10]]]]
|
||||||
|
[[[]],[[[],[10,8,9],2,[2,1,6]],[[3,10,6,7,6],1,3],[],10,[1]],[],[7,1,[[10],0],3]]
|
||||||
|
|
||||||
|
[[[4,[5,5,2,3],0,6,[9,4,4]],[],2]]
|
||||||
|
[[],[6,9,8,[]],[6,6,9,[[10,2,2,10,2],[1],9,8,6]],[],[[[5,1],[10,7,4,9]]]]
|
||||||
|
|
||||||
|
[[2,3,3,[[7,5,4,1],10]],[[1,7,3,[8,7,8,5,5]],[[8,0,1,4],[8],[5,4,6,2,7],4,[1,0]]],[8],[4,[],9,8,[[3,8,9],4,7]],[[],[[3,3,9],[3,4],[0,8],0,[1,2,7]],[[2,1,1,9,5]],[[0,7]]]]
|
||||||
|
[[9,1],[[],[[2,6,10,9,0],4,[],[6],[10]],[9,2,2,[5]],[[6,0,9],[3,2,10,0],7,3,10],[[5,1,7],[7,5,7,5,7],1]]]
|
||||||
|
|
||||||
|
[]
|
||||||
|
[[[[10],6,[1,8]],[],7]]
|
||||||
|
|
||||||
|
[[[5,0,0],2,10,[1,8],4]]
|
||||||
|
[[[]],[1],[],[1]]
|
||||||
|
|
||||||
|
[[1,[],[6,7,6,[]],[3,10,[7,4,5,6,10],[4,7,9]],8],[0,5,3,[[9,0],3],1],[1,8,5,8,[[2,8,10,4],[],7,9]]]
|
||||||
|
[[[[],0,[1,4,3,4],6],[[0],[],[],4,5]]]
|
||||||
|
|
||||||
|
[[3,8],[9],[[[5],[],3],[4,0,[6,9],6,0],4,[[10,4,7,0,10],8,10,3,0],[9,9,8,9]],[[5,8,10],[[9,2,0],1],8,[]],[4,[[5,10,9,10]],2,3]]
|
||||||
|
[[],[2],[],[10,[6,[4,6,5,5],4,3],4,[10,[7,8,0],[],6]]]
|
||||||
|
|
||||||
|
[[3],[[[2,4,3,7,1],[4,0,8,1],[4]],3]]
|
||||||
|
[[7],[[7,[2,0,8,3],[]]],[9],[[[2,9,1,8,3],[3,0]],[[9,2,8,2,3],0,4,1,4],2,1,9],[[[10,6,5,8,2],7,[9],[]],0,[10,10,[9,10,7,5,2]],[],[[],7]]]
|
||||||
|
|
||||||
|
[[3,[4,9,10,[0,4,6]],[4,3,9],0,6],[4,[],[[6],4,8]],[[2,6],[],[[4,4,8,5,5],[9]],[[1,10,3,1,10]]],[5,[6,7,6],9,[]],[8,7]]
|
||||||
|
[[],[2,10,[[1,10,10,6,8]]],[],[[9,9,[]]],[]]
|
||||||
|
|
||||||
|
[[[],1],[5],[[[8,8,7,0],[4,7,10],5],[10,2,[],8,[2,6,2]],[]],[[],[],5,[],[[7,1,10,3]]]]
|
||||||
|
[[[[6,2,10,6]],[],[6,8]],[[[3,8],[3,1,8,7]],9,5],[],[]]
|
||||||
|
|
||||||
|
[[],[6],[[],8]]
|
||||||
|
[[[[6,0,6]],[2,2,10,7,7],10]]
|
||||||
|
|
||||||
|
[[5,8],[2,[],4,2,0],[0,9,3]]
|
||||||
|
[[[5,0,[6,9,10,9,6],10],[[5],3,2,3,0]]]
|
||||||
|
|
||||||
|
[[[[],[0,5,8,10]],[6,[10],10,2,[4,1,10]]],[6],[[[10],[2,2,0,3,0],1,[4,6]],[2,[6,10,3,2],1,7],[],2]]
|
||||||
|
[[[],1,[[9,3,2],[5,4,1,5,7]],2,8],[4,[5,[9,5]],[3],[[],4,[2,1]]],[7],[10,8,3,[5,[6,7,6,1],3],2]]
|
||||||
|
|
||||||
|
[[[[9,0,8]],[8],5,9],[[4,[4,0,3,3],[4],[6]],5,[7,[],[9,2,0],[5,5,10,9,7]],0,[[4],[10],[10],10]],[],[[[2],6,[8,6],10,0],8]]
|
||||||
|
[[4],[2,3,[[5,8,9],[1],[4]]]]
|
||||||
|
|
||||||
|
[[[[4,5,10,4]],6]]
|
||||||
|
[[[1,8,[9,3,4,10],4]],[7,1],[4,[[1,5,3],[6]],[2,[1,7,10,2],[5,5,10,4,9],[]],8,[]],[[],2,5],[[9],8,[[7,6,1,0]],[]]]
|
||||||
|
|
||||||
|
[[9,10],[6,[[]],9,6,[6,7,[0,0,7,6]]],[],[[]],[]]
|
||||||
|
[[],[6,[[2],10,9,2,1],10,0,9],[0,[0],9],[[[2,10],2,6,[4]],0,5]]
|
||||||
|
|
||||||
|
[[5,10,[2],[[10,2,9],[0,8,8],6,[10,4,4,7],[8,7]],2],[8,[2,[6,1,8,1,7],[3,9,10,0,0],3,[5,2,3,8,9]]],[[[4,2,5,4],4,1,6,[5,5]],[[1],7,6],2,6]]
|
||||||
|
[[2],[9,[2]]]
|
||||||
|
|
||||||
|
[[5,[7],9,[6,[8],[0,1,7,7],3],7]]
|
||||||
|
[[1,[8,10,[4,2,0,4,8],[10,4,7,5,0]]],[5,2,[2],4],[],[0,6,8,[[1],5,2,[6,5,4,2]]],[10,[],9]]
|
||||||
|
|
||||||
|
[[[],[9,[5,7,5],7,[2,10],[3,3]],8]]
|
||||||
|
[[],[[[10,0,4,0],10,[],[10,9,5,6],8],1,[[7,5,4],[9,6,2,4],6,[1,5],[8,7,9]],9],[],[9,[5,[2,3,1,3,9],10,9],4]]
|
||||||
|
|
||||||
|
[[6,4,[]]]
|
||||||
|
[[[[2,4,8,2],2,[],[5,3,6,5],[4]]],[2,[1,4,5,[7,7,6],3],2],[[5,[8],4,[5]]],[3,1]]
|
||||||
|
|
||||||
|
[[8,[3,0],6],[8,[6,1],[[6,3,2],6,7,[8,7],0]],[[4,0],[9],[[3,1],[4,1,7,8,0],[5,5,6,4],10]],[0,[10,[7,6],8,[9,1,1,9,3],10],[[3],1,1]],[[[9],5],6]]
|
||||||
|
[[4],[[2,3,7,[10],10]],[[[],8],0,[2],[6,[5,0,4,3,6],5,[],4]],[7,[2,[8,2,1],3]],[[[5,6,0,5],6],[9],7,1,[]]]
|
||||||
|
|
||||||
|
[[10,[2,6,[3,5,6],6],9],[],[9],[4,1]]
|
||||||
|
[[],[],[[1],3,[[6,9,6],[],[6,6,2,2],[10]]]]
|
||||||
|
|
||||||
|
[[[1]],[[],6],[],[[10],3,[],[[1,6,10,9],[10],[2,8,1]]]]
|
||||||
|
[[],[[8,7,[6,8,6,4],6],4,9]]
|
||||||
|
|
||||||
|
[[9],[2,3,[9,[],[10,10,8]]],[],[9,[5,[8,0,5],[8,4,8,7]]],[[[7,2,2],4,9,[3,6]],7,5,1,0]]
|
||||||
|
[[[[7,10,1,0,6],[],[0,7,10,9]]],[[1,[0]],1,[[4,1],8,1],2],[[[],[5,3],[],3,[2,10,10,9,9]]]]
|
||||||
|
|
||||||
|
[[[0,[3,5,8],[0],10,3],7],[[3,5,[],2]]]
|
||||||
|
[[],[0,[4,1],6,[6,[4],[2,3,3],6,[6,0]]],[],[[[]],0,[]]]
|
||||||
|
|
||||||
|
[[6,[],8],[9,5]]
|
||||||
|
[[1,1],[[[3,3],1,[4,7,3,0]],3,6],[1,[9,[]],[[8,9],[3,4,7,8,10]]]]
|
||||||
|
|
||||||
|
[[0,[4,1,[10,0,5],[]],4,[9]],[[4],[]],[7],[]]
|
||||||
|
[[0,[10,3,[5,7,3],[5],[]],[[9,3,7,9,7],5,[1,7,8,7],[]],[[4],0,[],2],[[7,2,10,7,0],10,5,[]]],[5,10,[5,[2,3],0,[3,10,7,10]],5],[[8,2,10],[4,[]],0,2,8],[4,[9,[2,4,10]],[[2,4,7],5],[[2]]],[[1,[0,9,3],7,[]],[[],[],2],3]]
|
||||||
|
|
||||||
|
[[[[1,10],2,3,[10,1,3,0,5]],5,10,8,[[5,2,10,4,0],[3,0,7],[2,3,9,8],[10,10,5,2]]]]
|
||||||
|
[[6,[10,[],[2,0],7],[[3,8,3],[],[10,6],3],1,[[],1,[3,3],6,5]],[[[]],[[10,2],10,7,10,8]],[[],[]]]
|
||||||
|
|
||||||
|
[[6,6]]
|
||||||
|
[[6,[5],0,[[4,6],[9,2,8,10,1],[3,10,3,9],[10,9],7],2],[10],[[0,7,[3,7,7,3],[3,6],[2,10]],2,[1,2],6,7],[[[],8,10,6,9],8,[[7,8],8,6,5],[[8,0,10],[0,1,1],3,7],2]]
|
||||||
|
|
||||||
|
[[2,8,[]],[[],[0,[4]]]]
|
||||||
|
[[[8,[10,10,7],[9,1,8,5]],5,[2,[9,9],[9,6],1,[10,7,4]],2],[[2,[5,6,9,2],1,9,[4]],9,3,6],[[8,[6],[]],[9,[0,5,7],2,0,[]],8],[7,2]]
|
||||||
|
|
||||||
|
[[[],9,[4,5],[7],4],[[],[0,9,[4,2],9,[6,3,0,2,4]],[[7],[1,7],3,[6,8,10]],0,0],[7],[[[2,2,6,8],[0,2,0,8],7,[7,6,2,5]],[6],8,5,[[0,6,2,8,3],[8,1,9,4]]]]
|
||||||
|
[[7,10,[],4],[[5,[3,3,2,2,6],[],1],6,2,0],[[9],[[]],0]]
|
||||||
|
|
||||||
|
[[[8,[2]],[[6,7,10,10,4],[1],7],[4,[5,8]],7,[9,[],[7],4,[0,3,4,4]]],[[2,10],9,[10,8,5,[9,7,10,6]],[[],[6,1,4,5,6],2,2],[6]],[10,[],[6,6,10],0],[]]
|
||||||
|
[[[5,[6,4,5],[3]],[],[7],[[0]],[]],[7],[],[[[9,7,9,0],0,10,[3]],8,10,[]],[9,1,[],3]]
|
||||||
|
|
||||||
|
[[4,[[1,7,6,10],[10,1,4],3]],[1,[4]],[[[4,8,2,5,3],8,8,[4,0,1,7,5],[9,4,5,10,6]],4],[6],[4,[5,[8,1,10,6,9],6,[1,3,10,5]],2]]
|
||||||
|
[[],[8,5,7],[]]
|
||||||
|
|
||||||
|
[4,8,9,4,9]
|
||||||
|
[4,8,9,4]
|
||||||
|
|
||||||
|
[[[],[9,[10],2,[8,10,3,9],[9,2,6,0,3]],[[0],3,8,6,[0,7,5,7,5]],5,6],[[[2,9,5,7,0],10,[9,7],9,[8,7,7,7]]],[[10]]]
|
||||||
|
[[]]
|
||||||
|
|
||||||
|
[[4],[[],10,10],[2,[[1,5]],6,[[],[5],[8,1,1,2]],1],[[],[7]],[5]]
|
||||||
|
[[[[3,9,4,6]],6],[],[6],[2],[[[6,1,10],2],10,[],[[8,8,5,7,9],8,[2,6,9,1]]]]
|
||||||
|
|
||||||
|
[[7,8,0,[[2],4,[0,1,7,4],[3,1,5,5]]],[]]
|
||||||
|
[[[[],7,[3,0],2],[[]]],[9,[8,[6,3],0,[0,10,4,5,6],4],[[9,8,6,3],[9],[4,5,0],[4,0,8,4,2]]],[[1]],[],[0]]
|
||||||
|
|
||||||
|
[[[[2,2],4,[10,9,8,9],7,[]],[[6,5,9,10,10],3],[[0,7,8,4,8]],6],[2],[6,7,3,[5]]]
|
||||||
|
[[10,[10,3,[0,5,9,3],[0,3,3,6,6]]]]
|
81
day13/src/main.rs
Normal file
81
day13/src/main.rs
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::cmp::Ordering;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{BufReader, BufRead};
|
||||||
|
|
||||||
|
fn parse_num(s: &[u8]) -> (u64, usize) {
|
||||||
|
let mut num: u64 = 0;
|
||||||
|
let mut len = 0;
|
||||||
|
for i in 0..s.len() {
|
||||||
|
if s[i].is_ascii_digit() {
|
||||||
|
num = num*10 + (s[i] as u64 - '0' as u64);
|
||||||
|
len += 1;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(num, len)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assuming no malformed input
|
||||||
|
fn compare(left: &[u8], right: &[u8]) -> Ordering {
|
||||||
|
if left.len() == 0 {
|
||||||
|
return Ordering::Less;
|
||||||
|
}
|
||||||
|
if right.len() == 0 {
|
||||||
|
return Ordering::Greater;
|
||||||
|
}
|
||||||
|
let (l, r) = (left[0], right[0]);
|
||||||
|
if l == b',' && r == b',' {
|
||||||
|
compare(&left[1..], &right[1..])
|
||||||
|
} else if l == b'[' && r == b'[' {
|
||||||
|
compare(&left[1..], &right[1..])
|
||||||
|
} else if l == b']' && r == b']' {
|
||||||
|
compare(&left[1..], &right[1..])
|
||||||
|
} else if l == b']' {
|
||||||
|
Ordering::Less
|
||||||
|
} else if r == b']' {
|
||||||
|
Ordering::Greater
|
||||||
|
} else if l == b'[' {
|
||||||
|
let (num, len) = parse_num(right);
|
||||||
|
compare(
|
||||||
|
&left,
|
||||||
|
&[b"[", num.to_string().as_bytes(), b"]", &right[len..]].concat())
|
||||||
|
} else if r == b'[' {
|
||||||
|
let (num, len) = parse_num(left);
|
||||||
|
compare(
|
||||||
|
&[b"[", num.to_string().as_bytes(), b"]", &left[len..]].concat(),
|
||||||
|
&right)
|
||||||
|
} else {
|
||||||
|
let (lnum, llen) = parse_num(left);
|
||||||
|
let (rnum, rlen) = parse_num(right);
|
||||||
|
if lnum < rnum {
|
||||||
|
Ordering::Less
|
||||||
|
} else if lnum > rnum {
|
||||||
|
Ordering::Greater
|
||||||
|
} else {
|
||||||
|
compare(&left[llen..], &right[rlen..])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let file = File::open(&env::args().nth(1).expect("input")).expect("io err");
|
||||||
|
let mut lines: Vec<_> = BufReader::new(file).lines().flatten()
|
||||||
|
.filter(|line| line != "").collect();
|
||||||
|
lines.push(String::from("[[2]]"));
|
||||||
|
lines.push(String::from("[[6]]"));
|
||||||
|
lines.sort_unstable_by(|s1, s2| compare(s1.as_bytes(), s2.as_bytes()));
|
||||||
|
|
||||||
|
let (mut six, mut two): (usize, usize) = (0, 0);
|
||||||
|
for (i, line) in lines.iter().enumerate() {
|
||||||
|
if line == "[[6]]" {
|
||||||
|
six = i + 1;
|
||||||
|
}
|
||||||
|
if line == "[[2]]" {
|
||||||
|
two = i + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!("{:?}", six*two);
|
||||||
|
}
|
74
day13/src/main1.rs
Normal file
74
day13/src/main1.rs
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{BufReader, BufRead};
|
||||||
|
|
||||||
|
fn parse_num(s: &[u8]) -> (u64, usize) {
|
||||||
|
let mut num: u64 = 0;
|
||||||
|
let mut len = 0;
|
||||||
|
for i in 0..s.len() {
|
||||||
|
if s[i].is_ascii_digit() {
|
||||||
|
num = num*10 + (s[i] as u64 - '0' as u64);
|
||||||
|
len += 1;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(num, len)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assuming no malformed input
|
||||||
|
fn is_in_order(left: &[u8], right: &[u8]) -> bool {
|
||||||
|
//println!(">> {:?}, {:?} -- {:?}", str::from_utf8(left), str::from_utf8(right));
|
||||||
|
if left.len() == 0 {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if right.len() == 0 {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
let (l, r) = (left[0], right[0]);
|
||||||
|
if l == b',' && r == b',' {
|
||||||
|
is_in_order(&left[1..], &right[1..])
|
||||||
|
} else if l == b'[' && r == b'[' {
|
||||||
|
is_in_order(&left[1..], &right[1..])
|
||||||
|
} else if l == b']' && r == b']' {
|
||||||
|
is_in_order(&left[1..], &right[1..])
|
||||||
|
} else if l == b']' {
|
||||||
|
true
|
||||||
|
} else if r == b']' {
|
||||||
|
false
|
||||||
|
} else if l == b'[' {
|
||||||
|
let (num, len) = parse_num(right);
|
||||||
|
is_in_order(&left, &[b"[", num.to_string().as_bytes(), b"]", &right[len..]].concat())
|
||||||
|
} else if r == b'[' {
|
||||||
|
let (num, len) = parse_num(left);
|
||||||
|
is_in_order(&[b"[", num.to_string().as_bytes(), b"]", &left[len..]].concat(), &right)
|
||||||
|
} else {
|
||||||
|
let (lnum, llen) = parse_num(left);
|
||||||
|
let (rnum, rlen) = parse_num(right);
|
||||||
|
if lnum < rnum {
|
||||||
|
true
|
||||||
|
} else if lnum > rnum {
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
is_in_order(&left[llen..], &right[rlen..])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let file = File::open(&env::args().nth(1).expect("input")).expect("io err");
|
||||||
|
let lines: Vec<String> = BufReader::new(file).lines().flatten().collect();
|
||||||
|
// TODO: array_chunks() for lazy iter?
|
||||||
|
let blocks: Vec<_> = lines.chunks(3).collect();
|
||||||
|
|
||||||
|
let mut sum = 0;
|
||||||
|
for (i, block) in blocks.iter().enumerate() {
|
||||||
|
// TODO: return error here instead of assert?
|
||||||
|
assert!((block.len() == 3 && block[2] == "") || block.len() == 2);
|
||||||
|
if is_in_order(block[0].as_bytes(), block[1].as_bytes()) {
|
||||||
|
sum += i + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!("Answer: {:?}", sum);
|
||||||
|
}
|
23
day13/test.txt
Normal file
23
day13/test.txt
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
[1,1,3,1,1]
|
||||||
|
[1,1,5,1,1]
|
||||||
|
|
||||||
|
[[1],[2,3,4]]
|
||||||
|
[[1],4]
|
||||||
|
|
||||||
|
[9]
|
||||||
|
[[8,7,6]]
|
||||||
|
|
||||||
|
[[4,4],4,4]
|
||||||
|
[[4,4],4,4,4]
|
||||||
|
|
||||||
|
[7,7,7,7]
|
||||||
|
[7,7,7]
|
||||||
|
|
||||||
|
[]
|
||||||
|
[3]
|
||||||
|
|
||||||
|
[[[]]]
|
||||||
|
[[]]
|
||||||
|
|
||||||
|
[1,[2,[3,[4,[5,6,7]]]],8,9]
|
||||||
|
[1,[2,[3,[4,[5,6,0]]]],8,9]
|
7
day14/Cargo.lock
generated
Normal file
7
day14/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "day14"
|
||||||
|
version = "0.1.0"
|
8
day14/Cargo.toml
Normal file
8
day14/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "day14"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
151
day14/input.txt
Normal file
151
day14/input.txt
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
481,92 -> 481,96 -> 476,96 -> 476,99 -> 487,99 -> 487,96 -> 485,96 -> 485,92
|
||||||
|
460,73 -> 460,70 -> 460,73 -> 462,73 -> 462,69 -> 462,73 -> 464,73 -> 464,65 -> 464,73 -> 466,73 -> 466,65 -> 466,73 -> 468,73 -> 468,64 -> 468,73 -> 470,73 -> 470,68 -> 470,73 -> 472,73 -> 472,68 -> 472,73
|
||||||
|
470,76 -> 470,80 -> 466,80 -> 466,84 -> 481,84 -> 481,80 -> 474,80 -> 474,76
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
495,155 -> 499,155
|
||||||
|
460,73 -> 460,70 -> 460,73 -> 462,73 -> 462,69 -> 462,73 -> 464,73 -> 464,65 -> 464,73 -> 466,73 -> 466,65 -> 466,73 -> 468,73 -> 468,64 -> 468,73 -> 470,73 -> 470,68 -> 470,73 -> 472,73 -> 472,68 -> 472,73
|
||||||
|
500,138 -> 505,138
|
||||||
|
484,39 -> 484,38 -> 484,39 -> 486,39 -> 486,33 -> 486,39 -> 488,39 -> 488,30 -> 488,39 -> 490,39 -> 490,35 -> 490,39 -> 492,39 -> 492,38 -> 492,39 -> 494,39 -> 494,30 -> 494,39 -> 496,39 -> 496,36 -> 496,39
|
||||||
|
481,92 -> 481,96 -> 476,96 -> 476,99 -> 487,99 -> 487,96 -> 485,96 -> 485,92
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
460,73 -> 460,70 -> 460,73 -> 462,73 -> 462,69 -> 462,73 -> 464,73 -> 464,65 -> 464,73 -> 466,73 -> 466,65 -> 466,73 -> 468,73 -> 468,64 -> 468,73 -> 470,73 -> 470,68 -> 470,73 -> 472,73 -> 472,68 -> 472,73
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
460,73 -> 460,70 -> 460,73 -> 462,73 -> 462,69 -> 462,73 -> 464,73 -> 464,65 -> 464,73 -> 466,73 -> 466,65 -> 466,73 -> 468,73 -> 468,64 -> 468,73 -> 470,73 -> 470,68 -> 470,73 -> 472,73 -> 472,68 -> 472,73
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
489,115 -> 489,119 -> 481,119 -> 481,126 -> 494,126 -> 494,119 -> 493,119 -> 493,115
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
485,112 -> 485,102 -> 485,112 -> 487,112 -> 487,111 -> 487,112 -> 489,112 -> 489,105 -> 489,112
|
||||||
|
481,92 -> 481,96 -> 476,96 -> 476,99 -> 487,99 -> 487,96 -> 485,96 -> 485,92
|
||||||
|
484,39 -> 484,38 -> 484,39 -> 486,39 -> 486,33 -> 486,39 -> 488,39 -> 488,30 -> 488,39 -> 490,39 -> 490,35 -> 490,39 -> 492,39 -> 492,38 -> 492,39 -> 494,39 -> 494,30 -> 494,39 -> 496,39 -> 496,36 -> 496,39
|
||||||
|
470,49 -> 470,53 -> 468,53 -> 468,60 -> 477,60 -> 477,53 -> 476,53 -> 476,49
|
||||||
|
483,160 -> 487,160
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
460,73 -> 460,70 -> 460,73 -> 462,73 -> 462,69 -> 462,73 -> 464,73 -> 464,65 -> 464,73 -> 466,73 -> 466,65 -> 466,73 -> 468,73 -> 468,64 -> 468,73 -> 470,73 -> 470,68 -> 470,73 -> 472,73 -> 472,68 -> 472,73
|
||||||
|
491,131 -> 502,131 -> 502,130
|
||||||
|
475,88 -> 475,89 -> 483,89 -> 483,88
|
||||||
|
483,164 -> 487,164
|
||||||
|
498,147 -> 503,147
|
||||||
|
505,147 -> 510,147
|
||||||
|
485,112 -> 485,102 -> 485,112 -> 487,112 -> 487,111 -> 487,112 -> 489,112 -> 489,105 -> 489,112
|
||||||
|
516,150 -> 521,150
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
496,13 -> 501,13
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
484,39 -> 484,38 -> 484,39 -> 486,39 -> 486,33 -> 486,39 -> 488,39 -> 488,30 -> 488,39 -> 490,39 -> 490,35 -> 490,39 -> 492,39 -> 492,38 -> 492,39 -> 494,39 -> 494,30 -> 494,39 -> 496,39 -> 496,36 -> 496,39
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
512,147 -> 517,147
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
497,141 -> 502,141
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
460,73 -> 460,70 -> 460,73 -> 462,73 -> 462,69 -> 462,73 -> 464,73 -> 464,65 -> 464,73 -> 466,73 -> 466,65 -> 466,73 -> 468,73 -> 468,64 -> 468,73 -> 470,73 -> 470,68 -> 470,73 -> 472,73 -> 472,68 -> 472,73
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
484,39 -> 484,38 -> 484,39 -> 486,39 -> 486,33 -> 486,39 -> 488,39 -> 488,30 -> 488,39 -> 490,39 -> 490,35 -> 490,39 -> 492,39 -> 492,38 -> 492,39 -> 494,39 -> 494,30 -> 494,39 -> 496,39 -> 496,36 -> 496,39
|
||||||
|
480,162 -> 484,162
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
485,112 -> 485,102 -> 485,112 -> 487,112 -> 487,111 -> 487,112 -> 489,112 -> 489,105 -> 489,112
|
||||||
|
489,155 -> 493,155
|
||||||
|
460,73 -> 460,70 -> 460,73 -> 462,73 -> 462,69 -> 462,73 -> 464,73 -> 464,65 -> 464,73 -> 466,73 -> 466,65 -> 466,73 -> 468,73 -> 468,64 -> 468,73 -> 470,73 -> 470,68 -> 470,73 -> 472,73 -> 472,68 -> 472,73
|
||||||
|
484,39 -> 484,38 -> 484,39 -> 486,39 -> 486,33 -> 486,39 -> 488,39 -> 488,30 -> 488,39 -> 490,39 -> 490,35 -> 490,39 -> 492,39 -> 492,38 -> 492,39 -> 494,39 -> 494,30 -> 494,39 -> 496,39 -> 496,36 -> 496,39
|
||||||
|
460,73 -> 460,70 -> 460,73 -> 462,73 -> 462,69 -> 462,73 -> 464,73 -> 464,65 -> 464,73 -> 466,73 -> 466,65 -> 466,73 -> 468,73 -> 468,64 -> 468,73 -> 470,73 -> 470,68 -> 470,73 -> 472,73 -> 472,68 -> 472,73
|
||||||
|
460,73 -> 460,70 -> 460,73 -> 462,73 -> 462,69 -> 462,73 -> 464,73 -> 464,65 -> 464,73 -> 466,73 -> 466,65 -> 466,73 -> 468,73 -> 468,64 -> 468,73 -> 470,73 -> 470,68 -> 470,73 -> 472,73 -> 472,68 -> 472,73
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
498,157 -> 502,157
|
||||||
|
460,73 -> 460,70 -> 460,73 -> 462,73 -> 462,69 -> 462,73 -> 464,73 -> 464,65 -> 464,73 -> 466,73 -> 466,65 -> 466,73 -> 468,73 -> 468,64 -> 468,73 -> 470,73 -> 470,68 -> 470,73 -> 472,73 -> 472,68 -> 472,73
|
||||||
|
460,73 -> 460,70 -> 460,73 -> 462,73 -> 462,69 -> 462,73 -> 464,73 -> 464,65 -> 464,73 -> 466,73 -> 466,65 -> 466,73 -> 468,73 -> 468,64 -> 468,73 -> 470,73 -> 470,68 -> 470,73 -> 472,73 -> 472,68 -> 472,73
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
491,147 -> 496,147
|
||||||
|
484,39 -> 484,38 -> 484,39 -> 486,39 -> 486,33 -> 486,39 -> 488,39 -> 488,30 -> 488,39 -> 490,39 -> 490,35 -> 490,39 -> 492,39 -> 492,38 -> 492,39 -> 494,39 -> 494,30 -> 494,39 -> 496,39 -> 496,36 -> 496,39
|
||||||
|
484,39 -> 484,38 -> 484,39 -> 486,39 -> 486,33 -> 486,39 -> 488,39 -> 488,30 -> 488,39 -> 490,39 -> 490,35 -> 490,39 -> 492,39 -> 492,38 -> 492,39 -> 494,39 -> 494,30 -> 494,39 -> 496,39 -> 496,36 -> 496,39
|
||||||
|
489,115 -> 489,119 -> 481,119 -> 481,126 -> 494,126 -> 494,119 -> 493,119 -> 493,115
|
||||||
|
484,39 -> 484,38 -> 484,39 -> 486,39 -> 486,33 -> 486,39 -> 488,39 -> 488,30 -> 488,39 -> 490,39 -> 490,35 -> 490,39 -> 492,39 -> 492,38 -> 492,39 -> 494,39 -> 494,30 -> 494,39 -> 496,39 -> 496,36 -> 496,39
|
||||||
|
484,39 -> 484,38 -> 484,39 -> 486,39 -> 486,33 -> 486,39 -> 488,39 -> 488,30 -> 488,39 -> 490,39 -> 490,35 -> 490,39 -> 492,39 -> 492,38 -> 492,39 -> 494,39 -> 494,30 -> 494,39 -> 496,39 -> 496,36 -> 496,39
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
470,76 -> 470,80 -> 466,80 -> 466,84 -> 481,84 -> 481,80 -> 474,80 -> 474,76
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
475,88 -> 475,89 -> 483,89 -> 483,88
|
||||||
|
460,73 -> 460,70 -> 460,73 -> 462,73 -> 462,69 -> 462,73 -> 464,73 -> 464,65 -> 464,73 -> 466,73 -> 466,65 -> 466,73 -> 468,73 -> 468,64 -> 468,73 -> 470,73 -> 470,68 -> 470,73 -> 472,73 -> 472,68 -> 472,73
|
||||||
|
486,162 -> 490,162
|
||||||
|
460,73 -> 460,70 -> 460,73 -> 462,73 -> 462,69 -> 462,73 -> 464,73 -> 464,65 -> 464,73 -> 466,73 -> 466,65 -> 466,73 -> 468,73 -> 468,64 -> 468,73 -> 470,73 -> 470,68 -> 470,73 -> 472,73 -> 472,68 -> 472,73
|
||||||
|
508,144 -> 513,144
|
||||||
|
481,92 -> 481,96 -> 476,96 -> 476,99 -> 487,99 -> 487,96 -> 485,96 -> 485,92
|
||||||
|
460,73 -> 460,70 -> 460,73 -> 462,73 -> 462,69 -> 462,73 -> 464,73 -> 464,65 -> 464,73 -> 466,73 -> 466,65 -> 466,73 -> 468,73 -> 468,64 -> 468,73 -> 470,73 -> 470,68 -> 470,73 -> 472,73 -> 472,68 -> 472,73
|
||||||
|
470,49 -> 470,53 -> 468,53 -> 468,60 -> 477,60 -> 477,53 -> 476,53 -> 476,49
|
||||||
|
477,164 -> 481,164
|
||||||
|
485,112 -> 485,102 -> 485,112 -> 487,112 -> 487,111 -> 487,112 -> 489,112 -> 489,105 -> 489,112
|
||||||
|
504,141 -> 509,141
|
||||||
|
489,164 -> 493,164
|
||||||
|
480,42 -> 485,42
|
||||||
|
484,39 -> 484,38 -> 484,39 -> 486,39 -> 486,33 -> 486,39 -> 488,39 -> 488,30 -> 488,39 -> 490,39 -> 490,35 -> 490,39 -> 492,39 -> 492,38 -> 492,39 -> 494,39 -> 494,30 -> 494,39 -> 496,39 -> 496,36 -> 496,39
|
||||||
|
470,49 -> 470,53 -> 468,53 -> 468,60 -> 477,60 -> 477,53 -> 476,53 -> 476,49
|
||||||
|
485,112 -> 485,102 -> 485,112 -> 487,112 -> 487,111 -> 487,112 -> 489,112 -> 489,105 -> 489,112
|
||||||
|
484,39 -> 484,38 -> 484,39 -> 486,39 -> 486,33 -> 486,39 -> 488,39 -> 488,30 -> 488,39 -> 490,39 -> 490,35 -> 490,39 -> 492,39 -> 492,38 -> 492,39 -> 494,39 -> 494,30 -> 494,39 -> 496,39 -> 496,36 -> 496,39
|
||||||
|
489,115 -> 489,119 -> 481,119 -> 481,126 -> 494,126 -> 494,119 -> 493,119 -> 493,115
|
||||||
|
486,157 -> 490,157
|
||||||
|
460,73 -> 460,70 -> 460,73 -> 462,73 -> 462,69 -> 462,73 -> 464,73 -> 464,65 -> 464,73 -> 466,73 -> 466,65 -> 466,73 -> 468,73 -> 468,64 -> 468,73 -> 470,73 -> 470,68 -> 470,73 -> 472,73 -> 472,68 -> 472,73
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
470,76 -> 470,80 -> 466,80 -> 466,84 -> 481,84 -> 481,80 -> 474,80 -> 474,76
|
||||||
|
485,112 -> 485,102 -> 485,112 -> 487,112 -> 487,111 -> 487,112 -> 489,112 -> 489,105 -> 489,112
|
||||||
|
501,144 -> 506,144
|
||||||
|
484,39 -> 484,38 -> 484,39 -> 486,39 -> 486,33 -> 486,39 -> 488,39 -> 488,30 -> 488,39 -> 490,39 -> 490,35 -> 490,39 -> 492,39 -> 492,38 -> 492,39 -> 494,39 -> 494,30 -> 494,39 -> 496,39 -> 496,36 -> 496,39
|
||||||
|
485,112 -> 485,102 -> 485,112 -> 487,112 -> 487,111 -> 487,112 -> 489,112 -> 489,105 -> 489,112
|
||||||
|
470,76 -> 470,80 -> 466,80 -> 466,84 -> 481,84 -> 481,80 -> 474,80 -> 474,76
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
460,73 -> 460,70 -> 460,73 -> 462,73 -> 462,69 -> 462,73 -> 464,73 -> 464,65 -> 464,73 -> 466,73 -> 466,65 -> 466,73 -> 468,73 -> 468,64 -> 468,73 -> 470,73 -> 470,68 -> 470,73 -> 472,73 -> 472,68 -> 472,73
|
||||||
|
492,166 -> 496,166
|
||||||
|
509,150 -> 514,150
|
||||||
|
484,39 -> 484,38 -> 484,39 -> 486,39 -> 486,33 -> 486,39 -> 488,39 -> 488,30 -> 488,39 -> 490,39 -> 490,35 -> 490,39 -> 492,39 -> 492,38 -> 492,39 -> 494,39 -> 494,30 -> 494,39 -> 496,39 -> 496,36 -> 496,39
|
||||||
|
480,134 -> 480,135 -> 500,135 -> 500,134
|
||||||
|
460,73 -> 460,70 -> 460,73 -> 462,73 -> 462,69 -> 462,73 -> 464,73 -> 464,65 -> 464,73 -> 466,73 -> 466,65 -> 466,73 -> 468,73 -> 468,64 -> 468,73 -> 470,73 -> 470,68 -> 470,73 -> 472,73 -> 472,68 -> 472,73
|
||||||
|
486,166 -> 490,166
|
||||||
|
494,144 -> 499,144
|
||||||
|
481,92 -> 481,96 -> 476,96 -> 476,99 -> 487,99 -> 487,96 -> 485,96 -> 485,92
|
||||||
|
460,73 -> 460,70 -> 460,73 -> 462,73 -> 462,69 -> 462,73 -> 464,73 -> 464,65 -> 464,73 -> 466,73 -> 466,65 -> 466,73 -> 468,73 -> 468,64 -> 468,73 -> 470,73 -> 470,68 -> 470,73 -> 472,73 -> 472,68 -> 472,73
|
||||||
|
484,39 -> 484,38 -> 484,39 -> 486,39 -> 486,33 -> 486,39 -> 488,39 -> 488,30 -> 488,39 -> 490,39 -> 490,35 -> 490,39 -> 492,39 -> 492,38 -> 492,39 -> 494,39 -> 494,30 -> 494,39 -> 496,39 -> 496,36 -> 496,39
|
||||||
|
460,73 -> 460,70 -> 460,73 -> 462,73 -> 462,69 -> 462,73 -> 464,73 -> 464,65 -> 464,73 -> 466,73 -> 466,65 -> 466,73 -> 468,73 -> 468,64 -> 468,73 -> 470,73 -> 470,68 -> 470,73 -> 472,73 -> 472,68 -> 472,73
|
||||||
|
484,39 -> 484,38 -> 484,39 -> 486,39 -> 486,33 -> 486,39 -> 488,39 -> 488,30 -> 488,39 -> 490,39 -> 490,35 -> 490,39 -> 492,39 -> 492,38 -> 492,39 -> 494,39 -> 494,30 -> 494,39 -> 496,39 -> 496,36 -> 496,39
|
||||||
|
484,39 -> 484,38 -> 484,39 -> 486,39 -> 486,33 -> 486,39 -> 488,39 -> 488,30 -> 488,39 -> 490,39 -> 490,35 -> 490,39 -> 492,39 -> 492,38 -> 492,39 -> 494,39 -> 494,30 -> 494,39 -> 496,39 -> 496,36 -> 496,39
|
||||||
|
480,134 -> 480,135 -> 500,135 -> 500,134
|
||||||
|
481,46 -> 486,46
|
||||||
|
477,44 -> 482,44
|
||||||
|
470,49 -> 470,53 -> 468,53 -> 468,60 -> 477,60 -> 477,53 -> 476,53 -> 476,49
|
||||||
|
491,131 -> 502,131 -> 502,130
|
||||||
|
492,157 -> 496,157
|
||||||
|
484,39 -> 484,38 -> 484,39 -> 486,39 -> 486,33 -> 486,39 -> 488,39 -> 488,30 -> 488,39 -> 490,39 -> 490,35 -> 490,39 -> 492,39 -> 492,38 -> 492,39 -> 494,39 -> 494,30 -> 494,39 -> 496,39 -> 496,36 -> 496,39
|
||||||
|
488,150 -> 493,150
|
||||||
|
481,92 -> 481,96 -> 476,96 -> 476,99 -> 487,99 -> 487,96 -> 485,96 -> 485,92
|
||||||
|
474,46 -> 479,46
|
||||||
|
484,39 -> 484,38 -> 484,39 -> 486,39 -> 486,33 -> 486,39 -> 488,39 -> 488,30 -> 488,39 -> 490,39 -> 490,35 -> 490,39 -> 492,39 -> 492,38 -> 492,39 -> 494,39 -> 494,30 -> 494,39 -> 496,39 -> 496,36 -> 496,39
|
||||||
|
489,115 -> 489,119 -> 481,119 -> 481,126 -> 494,126 -> 494,119 -> 493,119 -> 493,115
|
||||||
|
460,73 -> 460,70 -> 460,73 -> 462,73 -> 462,69 -> 462,73 -> 464,73 -> 464,65 -> 464,73 -> 466,73 -> 466,65 -> 466,73 -> 468,73 -> 468,64 -> 468,73 -> 470,73 -> 470,68 -> 470,73 -> 472,73 -> 472,68 -> 472,73
|
||||||
|
489,115 -> 489,119 -> 481,119 -> 481,126 -> 494,126 -> 494,119 -> 493,119 -> 493,115
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
470,76 -> 470,80 -> 466,80 -> 466,84 -> 481,84 -> 481,80 -> 474,80 -> 474,76
|
||||||
|
488,46 -> 493,46
|
||||||
|
495,150 -> 500,150
|
||||||
|
474,166 -> 478,166
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
484,44 -> 489,44
|
||||||
|
484,39 -> 484,38 -> 484,39 -> 486,39 -> 486,33 -> 486,39 -> 488,39 -> 488,30 -> 488,39 -> 490,39 -> 490,35 -> 490,39 -> 492,39 -> 492,38 -> 492,39 -> 494,39 -> 494,30 -> 494,39 -> 496,39 -> 496,36 -> 496,39
|
||||||
|
484,39 -> 484,38 -> 484,39 -> 486,39 -> 486,33 -> 486,39 -> 488,39 -> 488,30 -> 488,39 -> 490,39 -> 490,35 -> 490,39 -> 492,39 -> 492,38 -> 492,39 -> 494,39 -> 494,30 -> 494,39 -> 496,39 -> 496,36 -> 496,39
|
||||||
|
489,115 -> 489,119 -> 481,119 -> 481,126 -> 494,126 -> 494,119 -> 493,119 -> 493,115
|
||||||
|
481,92 -> 481,96 -> 476,96 -> 476,99 -> 487,99 -> 487,96 -> 485,96 -> 485,92
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
489,115 -> 489,119 -> 481,119 -> 481,126 -> 494,126 -> 494,119 -> 493,119 -> 493,115
|
||||||
|
492,153 -> 496,153
|
||||||
|
502,150 -> 507,150
|
||||||
|
470,49 -> 470,53 -> 468,53 -> 468,60 -> 477,60 -> 477,53 -> 476,53 -> 476,49
|
||||||
|
475,88 -> 475,89 -> 483,89 -> 483,88
|
||||||
|
480,134 -> 480,135 -> 500,135 -> 500,134
|
||||||
|
470,76 -> 470,80 -> 466,80 -> 466,84 -> 481,84 -> 481,80 -> 474,80 -> 474,76
|
||||||
|
492,26 -> 492,17 -> 492,26 -> 494,26 -> 494,16 -> 494,26 -> 496,26 -> 496,22 -> 496,26 -> 498,26 -> 498,17 -> 498,26 -> 500,26 -> 500,20 -> 500,26 -> 502,26 -> 502,25 -> 502,26 -> 504,26 -> 504,23 -> 504,26 -> 506,26 -> 506,21 -> 506,26 -> 508,26 -> 508,16 -> 508,26 -> 510,26 -> 510,24 -> 510,26
|
||||||
|
480,166 -> 484,166
|
||||||
|
470,49 -> 470,53 -> 468,53 -> 468,60 -> 477,60 -> 477,53 -> 476,53 -> 476,49
|
||||||
|
470,76 -> 470,80 -> 466,80 -> 466,84 -> 481,84 -> 481,80 -> 474,80 -> 474,76
|
||||||
|
485,112 -> 485,102 -> 485,112 -> 487,112 -> 487,111 -> 487,112 -> 489,112 -> 489,105 -> 489,112
|
||||||
|
470,49 -> 470,53 -> 468,53 -> 468,60 -> 477,60 -> 477,53 -> 476,53 -> 476,49
|
105
day14/src/main.rs
Normal file
105
day14/src/main.rs
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{BufReader, BufRead};
|
||||||
|
use std::cmp::{min, max};
|
||||||
|
|
||||||
|
fn parse_num(s: &[u8]) -> (usize, usize) {
|
||||||
|
let mut num: usize = 0;
|
||||||
|
let mut len = 0;
|
||||||
|
for i in 0..s.len() {
|
||||||
|
if s[i].is_ascii_digit() {
|
||||||
|
num = num*10 + (s[i] as usize - '0' as usize);
|
||||||
|
len += 1;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(num, len)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn print_map(map: &Vec<Vec<char>>) {
|
||||||
|
for row in map {
|
||||||
|
let s: String = row.iter().collect();
|
||||||
|
println!("{}", s);
|
||||||
|
}
|
||||||
|
println!("");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let file = File::open(&env::args().nth(1).expect("input")).expect("io err");
|
||||||
|
let lines = BufReader::new(file).lines();
|
||||||
|
let (mut minx, mut miny, mut maxx, mut maxy) =
|
||||||
|
(usize::MAX, usize::MAX, 0, 0);
|
||||||
|
let mut lists: Vec<Vec<(usize, usize)>> = Vec::new();
|
||||||
|
|
||||||
|
for line in lines.flatten() {
|
||||||
|
let l_bytes = line.as_bytes();
|
||||||
|
let mut cursor = 0;
|
||||||
|
let mut list: Vec<(usize, usize)> = Vec::new();
|
||||||
|
while cursor < l_bytes.len() {
|
||||||
|
let (x, lenx) = parse_num(&l_bytes[cursor..]);
|
||||||
|
let (y, leny) = parse_num(&l_bytes[cursor + lenx + 1..]);
|
||||||
|
list.push((x, y));
|
||||||
|
minx = if x < minx {x} else {minx};
|
||||||
|
miny = if y < miny {y} else {miny};
|
||||||
|
maxx = if x > maxx {x} else {maxx};
|
||||||
|
maxy = if y > maxy {y} else {maxy};
|
||||||
|
cursor = cursor + lenx + 1 + leny + 4;
|
||||||
|
}
|
||||||
|
lists.push(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
// part2 hack here
|
||||||
|
minx = 0;
|
||||||
|
maxx = 1000;
|
||||||
|
maxy = maxy + 2;
|
||||||
|
lists.push(vec![(minx, maxy), (maxx, maxy)]);
|
||||||
|
|
||||||
|
println!("{:?} {:?} {:?} {:?}", minx, miny, maxx, maxy);
|
||||||
|
let mut map: Vec<Vec<char>> =
|
||||||
|
vec![vec!['.'; maxx - minx + 3]; maxy + 1];
|
||||||
|
for list in lists {
|
||||||
|
let (mut xprev, mut yprev) = &list[0];
|
||||||
|
for (x, y) in &list[1..] {
|
||||||
|
if *x == xprev {
|
||||||
|
for ty in *min(y, &yprev)..=*max(y, &yprev) {
|
||||||
|
map[ty][*x - minx + 1] = '#';
|
||||||
|
}
|
||||||
|
} else if *y == yprev {
|
||||||
|
for tx in *min(x, &xprev)..=*max(x, &xprev) {
|
||||||
|
map[*y][tx - minx + 1] = '#';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xprev = *x;
|
||||||
|
yprev = *y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print_map(&map);
|
||||||
|
|
||||||
|
let mut total = 0;
|
||||||
|
'map: loop {
|
||||||
|
let (mut rockx, mut rocky) = (500, 0);
|
||||||
|
'rock: loop {
|
||||||
|
//println!("{:?}, {:?}", rockx, rocky);
|
||||||
|
if map[rocky + 1][rockx + 1 - minx] == '.' {
|
||||||
|
rocky = rocky + 1;
|
||||||
|
} else if map[rocky + 1][rockx + 1 - minx - 1] == '.' {
|
||||||
|
rocky = rocky + 1;
|
||||||
|
rockx = rockx - 1;
|
||||||
|
} else if map[rocky + 1][rockx + 1 - minx + 1] == '.' {
|
||||||
|
rocky = rocky + 1;
|
||||||
|
rockx = rockx + 1;
|
||||||
|
} else {
|
||||||
|
map[rocky][rockx - minx + 1] = 'o';
|
||||||
|
total += 1;
|
||||||
|
if rockx == 500 && rocky == 0 {
|
||||||
|
break 'map;
|
||||||
|
}
|
||||||
|
//print_map(&map);
|
||||||
|
break 'rock;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print_map(&map);
|
||||||
|
println!("{:?}", total);
|
||||||
|
}
|
97
day14/src/main1.rs
Normal file
97
day14/src/main1.rs
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{BufReader, BufRead};
|
||||||
|
use std::cmp::{min, max};
|
||||||
|
|
||||||
|
fn parse_num(s: &[u8]) -> (usize, usize) {
|
||||||
|
let mut num: usize = 0;
|
||||||
|
let mut len = 0;
|
||||||
|
for i in 0..s.len() {
|
||||||
|
if s[i].is_ascii_digit() {
|
||||||
|
num = num*10 + (s[i] as usize - '0' as usize);
|
||||||
|
len += 1;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(num, len)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn print_map(map: &Vec<Vec<char>>) {
|
||||||
|
for row in map {
|
||||||
|
let s: String = row.iter().collect();
|
||||||
|
println!("{}", s);
|
||||||
|
}
|
||||||
|
println!("");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let file = File::open(&env::args().nth(1).expect("input")).expect("io err");
|
||||||
|
let lines = BufReader::new(file).lines();
|
||||||
|
let (mut minx, mut miny, mut maxx, mut maxy) =
|
||||||
|
(usize::MAX, usize::MAX, 0, 0);
|
||||||
|
let mut lists: Vec<Vec<(usize, usize)>> = Vec::new();
|
||||||
|
|
||||||
|
for line in lines.flatten() {
|
||||||
|
let l_bytes = line.as_bytes();
|
||||||
|
let mut cursor = 0;
|
||||||
|
let mut list: Vec<(usize, usize)> = Vec::new();
|
||||||
|
while cursor < l_bytes.len() {
|
||||||
|
let (x, lenx) = parse_num(&l_bytes[cursor..]);
|
||||||
|
let (y, leny) = parse_num(&l_bytes[cursor + lenx + 1..]);
|
||||||
|
list.push((x, y));
|
||||||
|
minx = if x < minx {x} else {minx};
|
||||||
|
miny = if y < miny {y} else {miny};
|
||||||
|
maxx = if x > maxx {x} else {maxx};
|
||||||
|
maxy = if y > maxy {y} else {maxy};
|
||||||
|
cursor = cursor + lenx + 1 + leny + 4;
|
||||||
|
}
|
||||||
|
lists.push(list);
|
||||||
|
}
|
||||||
|
println!("{:?} {:?} {:?} {:?}", minx, miny, maxx, maxy);
|
||||||
|
let mut map: Vec<Vec<char>> =
|
||||||
|
vec![vec!['.'; maxx - minx + 3]; maxy + 1];
|
||||||
|
for list in lists {
|
||||||
|
let (mut xprev, mut yprev) = &list[0];
|
||||||
|
for (x, y) in &list[1..] {
|
||||||
|
if *x == xprev {
|
||||||
|
for ty in *min(y, &yprev)..=*max(y, &yprev) {
|
||||||
|
map[ty][*x - minx + 1] = '#';
|
||||||
|
}
|
||||||
|
} else if *y == yprev {
|
||||||
|
for tx in *min(x, &xprev)..=*max(x, &xprev) {
|
||||||
|
map[*y][tx - minx + 1] = '#';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xprev = *x;
|
||||||
|
yprev = *y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print_map(&map);
|
||||||
|
|
||||||
|
let mut total = 0;
|
||||||
|
'map: loop {
|
||||||
|
let (mut rockx, mut rocky) = (500, 0);
|
||||||
|
'rock: loop {
|
||||||
|
//println!("{:?}, {:?}", rockx, rocky);
|
||||||
|
if rockx < minx || rockx > maxx || rocky == maxy {
|
||||||
|
break 'map;
|
||||||
|
} else if map[rocky + 1][rockx + 1 - minx] == '.' {
|
||||||
|
rocky = rocky + 1;
|
||||||
|
} else if map[rocky + 1][rockx + 1 - minx - 1] == '.' {
|
||||||
|
rocky = rocky + 1;
|
||||||
|
rockx = rockx - 1;
|
||||||
|
} else if map[rocky + 1][rockx + 1 - minx + 1] == '.' {
|
||||||
|
rocky = rocky + 1;
|
||||||
|
rockx = rockx + 1;
|
||||||
|
} else {
|
||||||
|
map[rocky][rockx - minx + 1] = 'o';
|
||||||
|
total += 1;
|
||||||
|
//print_map(&map);
|
||||||
|
break 'rock;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print_map(&map);
|
||||||
|
println!("{:?}", total);
|
||||||
|
}
|
2
day14/test.txt
Normal file
2
day14/test.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
498,4 -> 498,6 -> 496,6
|
||||||
|
503,4 -> 502,4 -> 502,9 -> 494,9
|
7
day15/Cargo.lock
generated
Normal file
7
day15/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "day15"
|
||||||
|
version = "0.1.0"
|
8
day15/Cargo.toml
Normal file
8
day15/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "day15"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
33
day15/input.txt
Normal file
33
day15/input.txt
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
Sensor at x=2899860, y=3122031: closest beacon is at x=2701269, y=3542780
|
||||||
|
Sensor at x=1836719, y=1116779: closest beacon is at x=2037055, y=2000000
|
||||||
|
Sensor at x=3995802, y=2706630: closest beacon is at x=3944538, y=3053285
|
||||||
|
Sensor at x=2591204, y=2008272: closest beacon is at x=2597837, y=2509170
|
||||||
|
Sensor at x=2546593, y=1538222: closest beacon is at x=2037055, y=2000000
|
||||||
|
Sensor at x=252214, y=61954: closest beacon is at x=1087565, y=-690123
|
||||||
|
Sensor at x=950, y=1106672: closest beacon is at x=-893678, y=1276864
|
||||||
|
Sensor at x=1349445, y=1752783: closest beacon is at x=2037055, y=2000000
|
||||||
|
Sensor at x=3195828, y=3483667: closest beacon is at x=3334657, y=3531523
|
||||||
|
Sensor at x=2057761, y=2154359: closest beacon is at x=2037055, y=2000000
|
||||||
|
Sensor at x=2315350, y=3364640: closest beacon is at x=2701269, y=3542780
|
||||||
|
Sensor at x=327139, y=2426600: closest beacon is at x=-88420, y=3646947
|
||||||
|
Sensor at x=3943522, y=2854345: closest beacon is at x=3944538, y=3053285
|
||||||
|
Sensor at x=3358620, y=516881: closest beacon is at x=3260516, y=2246079
|
||||||
|
Sensor at x=1788376, y=8679: closest beacon is at x=1087565, y=-690123
|
||||||
|
Sensor at x=3344883, y=3537985: closest beacon is at x=3334657, y=3531523
|
||||||
|
Sensor at x=2961064, y=2697125: closest beacon is at x=2597837, y=2509170
|
||||||
|
Sensor at x=3780090, y=2093546: closest beacon is at x=3260516, y=2246079
|
||||||
|
Sensor at x=3291917, y=3398703: closest beacon is at x=3334657, y=3531523
|
||||||
|
Sensor at x=3999864, y=2998005: closest beacon is at x=3944538, y=3053285
|
||||||
|
Sensor at x=2919272, y=3732950: closest beacon is at x=2701269, y=3542780
|
||||||
|
Sensor at x=2057404, y=2947435: closest beacon is at x=2037055, y=2000000
|
||||||
|
Sensor at x=1072126, y=645784: closest beacon is at x=1087565, y=-690123
|
||||||
|
Sensor at x=3549465, y=2554712: closest beacon is at x=3260516, y=2246079
|
||||||
|
Sensor at x=3550313, y=3121694: closest beacon is at x=3944538, y=3053285
|
||||||
|
Sensor at x=3405149, y=3483630: closest beacon is at x=3334657, y=3531523
|
||||||
|
Sensor at x=2600212, y=3961193: closest beacon is at x=2701269, y=3542780
|
||||||
|
Sensor at x=1102632, y=3932527: closest beacon is at x=-88420, y=3646947
|
||||||
|
Sensor at x=67001, y=3506079: closest beacon is at x=-88420, y=3646947
|
||||||
|
Sensor at x=3994250, y=3975025: closest beacon is at x=3944538, y=3053285
|
||||||
|
Sensor at x=3019750, y=2125144: closest beacon is at x=3260516, y=2246079
|
||||||
|
Sensor at x=3282319, y=3656404: closest beacon is at x=3334657, y=3531523
|
||||||
|
Sensor at x=2797371, y=3645126: closest beacon is at x=2701269, y=3542780
|
83
day15/src/main.rs
Normal file
83
day15/src/main.rs
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{BufReader, BufRead};
|
||||||
|
use std::cmp::{min, max};
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
fn parse_num(s: &[u8]) -> (i64, usize) {
|
||||||
|
let mut num: i64 = 0;
|
||||||
|
let negative = s[0] == '-' as u8;
|
||||||
|
let start = if negative {1} else {0};
|
||||||
|
let mut len = if negative {1} else {0};
|
||||||
|
|
||||||
|
for i in start..s.len() {
|
||||||
|
if s[i].is_ascii_digit() {
|
||||||
|
num = num*10 + (s[i] as i64 - '0' as i64);
|
||||||
|
len += 1;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(if negative {-num} else {num}, len)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn combine(ranges: &mut Vec<(i64, i64)>, l: i64, r: i64) {
|
||||||
|
for (l0, r0) in ranges.iter_mut() {
|
||||||
|
if *l0 <= r && l <= *r0 {
|
||||||
|
*l0 = min(*l0, l);
|
||||||
|
*r0 = max(*r0, r);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ranges.len() > 0 {
|
||||||
|
let (_, last_r) = ranges.last_mut().unwrap();
|
||||||
|
if l == *last_r + 1 {
|
||||||
|
*last_r = r;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ranges.push((l, r));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let file = File::open(&env::args().nth(1).expect("input")).expect("io err");
|
||||||
|
let lines = BufReader::new(file).lines();
|
||||||
|
let mut sensors: Vec<(i64, i64, u64)> = Vec::new();
|
||||||
|
let mut beacons: HashSet<(i64, i64)> = HashSet::new();
|
||||||
|
for line in lines.flatten() {
|
||||||
|
let l_bytes = line.as_bytes();
|
||||||
|
let (sx, e1) = parse_num(&l_bytes[12..]);
|
||||||
|
let (sy, e2) = parse_num(&l_bytes[12 + e1 + 4..]);
|
||||||
|
let (bx, e3) = parse_num(&l_bytes[12 + e1 + 4 + e2 + 25..]);
|
||||||
|
let (by, _) = parse_num(&l_bytes[12 + e1 + 4 + e2 + 25 + e3 + 4..]);
|
||||||
|
sensors.push((sx, sy, ((bx - sx).abs() + (by - sy).abs()) as u64));
|
||||||
|
beacons.insert((bx, by));
|
||||||
|
}
|
||||||
|
sensors.sort_by_key(|(x, _, _)| *x);
|
||||||
|
println!("{:?}", sensors);
|
||||||
|
println!("{:?}", beacons);
|
||||||
|
|
||||||
|
let max_y = &env::args().nth(2).expect("max y").parse::<i64>().unwrap();
|
||||||
|
for target_y in 0..=*max_y {
|
||||||
|
let mut line_coverages: Vec<(i64, i64)> = Vec::new();
|
||||||
|
for (sx, sy, range) in &sensors {
|
||||||
|
let clip = (*range as i64) - (sy - target_y).abs();
|
||||||
|
if clip < 0 {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let startx = sx - clip;
|
||||||
|
let endx = sx + clip;
|
||||||
|
line_coverages.push((startx, endx));
|
||||||
|
}
|
||||||
|
line_coverages.sort_by_key(|(x, _)| *x);
|
||||||
|
let mut coverage: Vec<(i64, i64)> = Vec::new();
|
||||||
|
for (startx, endx) in line_coverages {
|
||||||
|
combine(&mut coverage, startx, endx);
|
||||||
|
}
|
||||||
|
if coverage.len() > 1 {
|
||||||
|
let score = 4000000 * (coverage[0].1 + 1) + target_y;
|
||||||
|
println!("{:?} --> {:?}", coverage, score);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
78
day15/src/main1.rs
Normal file
78
day15/src/main1.rs
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{BufReader, BufRead};
|
||||||
|
use std::cmp::{min, max};
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
fn parse_num(s: &[u8]) -> (i64, usize) {
|
||||||
|
let mut num: i64 = 0;
|
||||||
|
let negative = s[0] == '-' as u8;
|
||||||
|
let start = if negative {1} else {0};
|
||||||
|
let mut len = if negative {1} else {0};
|
||||||
|
|
||||||
|
for i in start..s.len() {
|
||||||
|
if s[i].is_ascii_digit() {
|
||||||
|
num = num*10 + (s[i] as i64 - '0' as i64);
|
||||||
|
len += 1;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(if negative {-num} else {num}, len)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn combine(ranges: &mut Vec<(i64, i64)>, l: i64, r: i64) {
|
||||||
|
for (l0, r0) in ranges.iter_mut() {
|
||||||
|
if *l0 <= r && l <= *r0 {
|
||||||
|
*l0 = min(*l0, l);
|
||||||
|
*r0 = max(*r0, r);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ranges.push((l, r));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let file = File::open(&env::args().nth(1).expect("input")).expect("io err");
|
||||||
|
let lines = BufReader::new(file).lines();
|
||||||
|
let mut sensors: Vec<(i64, i64, u64)> = Vec::new();
|
||||||
|
let mut beacons: HashSet<(i64, i64)> = HashSet::new();
|
||||||
|
for line in lines.flatten() {
|
||||||
|
let l_bytes = line.as_bytes();
|
||||||
|
let (sx, e1) = parse_num(&l_bytes[12..]);
|
||||||
|
let (sy, e2) = parse_num(&l_bytes[12 + e1 + 4..]);
|
||||||
|
let (bx, e3) = parse_num(&l_bytes[12 + e1 + 4 + e2 + 25..]);
|
||||||
|
let (by, _) = parse_num(&l_bytes[12 + e1 + 4 + e2 + 25 + e3 + 4..]);
|
||||||
|
sensors.push((sx, sy, ((bx - sx).abs() + (by - sy).abs()) as u64));
|
||||||
|
beacons.insert((bx, by));
|
||||||
|
}
|
||||||
|
sensors.sort_by_key(|(x, _, _)| *x);
|
||||||
|
println!("{:?}", sensors);
|
||||||
|
println!("{:?}", beacons);
|
||||||
|
|
||||||
|
let target_y = &env::args().nth(2).expect("line").parse::<i64>().unwrap();
|
||||||
|
let mut coverage: Vec<(i64, i64)> = Vec::new();
|
||||||
|
for (sx, sy, range) in sensors {
|
||||||
|
let clip = (range as i64) - (sy - target_y).abs();
|
||||||
|
if clip < 0 {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let startx = sx - clip;
|
||||||
|
let endx = sx + clip;
|
||||||
|
combine(&mut coverage, startx, endx);
|
||||||
|
|
||||||
|
}
|
||||||
|
println!("{:?}", coverage);
|
||||||
|
|
||||||
|
let mut sum = 0;
|
||||||
|
for (l, r) in coverage {
|
||||||
|
let mut overlap = 0;
|
||||||
|
for (bx, by) in &beacons {
|
||||||
|
if *by == *target_y && l <= *bx && r >= *bx {
|
||||||
|
overlap += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sum += r - l + 1 - overlap;
|
||||||
|
}
|
||||||
|
println!("answer: {:?}", sum);
|
||||||
|
}
|
14
day15/test.txt
Normal file
14
day15/test.txt
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
Sensor at x=2, y=18: closest beacon is at x=-2, y=15
|
||||||
|
Sensor at x=9, y=16: closest beacon is at x=10, y=16
|
||||||
|
Sensor at x=13, y=2: closest beacon is at x=15, y=3
|
||||||
|
Sensor at x=12, y=14: closest beacon is at x=10, y=16
|
||||||
|
Sensor at x=10, y=20: closest beacon is at x=10, y=16
|
||||||
|
Sensor at x=14, y=17: closest beacon is at x=10, y=16
|
||||||
|
Sensor at x=8, y=7: closest beacon is at x=2, y=10
|
||||||
|
Sensor at x=2, y=0: closest beacon is at x=2, y=10
|
||||||
|
Sensor at x=0, y=11: closest beacon is at x=2, y=10
|
||||||
|
Sensor at x=20, y=14: closest beacon is at x=25, y=17
|
||||||
|
Sensor at x=17, y=20: closest beacon is at x=21, y=22
|
||||||
|
Sensor at x=16, y=7: closest beacon is at x=15, y=3
|
||||||
|
Sensor at x=14, y=3: closest beacon is at x=15, y=3
|
||||||
|
Sensor at x=20, y=1: closest beacon is at x=15, y=3
|
7
day16/Cargo.lock
generated
Normal file
7
day16/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "day16"
|
||||||
|
version = "0.1.0"
|
8
day16/Cargo.toml
Normal file
8
day16/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "day16"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
52
day16/input.txt
Normal file
52
day16/input.txt
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
Valve AP has flow rate=0; tunnels lead to valves AA, ON
|
||||||
|
Valve QN has flow rate=21; tunnels lead to valves RI, CG
|
||||||
|
Valve LK has flow rate=0; tunnels lead to valves XM, AA
|
||||||
|
Valve HA has flow rate=0; tunnels lead to valves WH, KF
|
||||||
|
Valve DS has flow rate=16; tunnel leads to valve II
|
||||||
|
Valve KD has flow rate=0; tunnels lead to valves KG, QB
|
||||||
|
Valve JW has flow rate=0; tunnels lead to valves AD, KF
|
||||||
|
Valve HU has flow rate=0; tunnels lead to valves UK, CO
|
||||||
|
Valve AE has flow rate=10; tunnels lead to valves IR, PT, UV
|
||||||
|
Valve XA has flow rate=0; tunnels lead to valves CG, EU
|
||||||
|
Valve SE has flow rate=17; tunnels lead to valves YR, AD
|
||||||
|
Valve TR has flow rate=0; tunnels lead to valves AL, CS
|
||||||
|
Valve BS has flow rate=0; tunnels lead to valves YH, XM
|
||||||
|
Valve IJ has flow rate=24; tunnels lead to valves XN, WE
|
||||||
|
Valve AA has flow rate=0; tunnels lead to valves LK, AP, IZ, PC, QD
|
||||||
|
Valve KG has flow rate=0; tunnels lead to valves KD, CS
|
||||||
|
Valve QV has flow rate=0; tunnels lead to valves XM, II
|
||||||
|
Valve PC has flow rate=0; tunnels lead to valves AA, YF
|
||||||
|
Valve GJ has flow rate=20; tunnel leads to valve RI
|
||||||
|
Valve UV has flow rate=0; tunnels lead to valves UK, AE
|
||||||
|
Valve IR has flow rate=0; tunnels lead to valves EU, AE
|
||||||
|
Valve EU has flow rate=13; tunnels lead to valves IR, DT, XA, ON
|
||||||
|
Valve ED has flow rate=0; tunnels lead to valves XN, CO
|
||||||
|
Valve DT has flow rate=0; tunnels lead to valves EU, UK
|
||||||
|
Valve YE has flow rate=0; tunnels lead to valves XM, WS
|
||||||
|
Valve AD has flow rate=0; tunnels lead to valves JW, SE
|
||||||
|
Valve WE has flow rate=0; tunnels lead to valves IJ, NA
|
||||||
|
Valve UK has flow rate=5; tunnels lead to valves UV, DT, QD, HU
|
||||||
|
Valve YR has flow rate=0; tunnels lead to valves OS, SE
|
||||||
|
Valve II has flow rate=0; tunnels lead to valves QV, DS
|
||||||
|
Valve GT has flow rate=0; tunnels lead to valves CS, MN
|
||||||
|
Valve YH has flow rate=0; tunnels lead to valves BS, QB
|
||||||
|
Valve BQ has flow rate=0; tunnels lead to valves XM, KF
|
||||||
|
Valve OS has flow rate=0; tunnels lead to valves YR, NA
|
||||||
|
Valve WH has flow rate=0; tunnels lead to valves QB, HA
|
||||||
|
Valve QB has flow rate=4; tunnels lead to valves WH, KD, YH, IZ
|
||||||
|
Valve ON has flow rate=0; tunnels lead to valves AP, EU
|
||||||
|
Valve IZ has flow rate=0; tunnels lead to valves AA, QB
|
||||||
|
Valve MN has flow rate=25; tunnel leads to valve GT
|
||||||
|
Valve CG has flow rate=0; tunnels lead to valves XA, QN
|
||||||
|
Valve QD has flow rate=0; tunnels lead to valves UK, AA
|
||||||
|
Valve AL has flow rate=0; tunnels lead to valves KF, TR
|
||||||
|
Valve XN has flow rate=0; tunnels lead to valves ED, IJ
|
||||||
|
Valve WS has flow rate=0; tunnels lead to valves YE, CS
|
||||||
|
Valve CO has flow rate=18; tunnels lead to valves ED, PT, HU
|
||||||
|
Valve PT has flow rate=0; tunnels lead to valves CO, AE
|
||||||
|
Valve RI has flow rate=0; tunnels lead to valves QN, GJ
|
||||||
|
Valve CS has flow rate=9; tunnels lead to valves YF, GT, WS, TR, KG
|
||||||
|
Valve YF has flow rate=0; tunnels lead to valves PC, CS
|
||||||
|
Valve NA has flow rate=23; tunnels lead to valves OS, WE
|
||||||
|
Valve KF has flow rate=12; tunnels lead to valves HA, AL, JW, BQ
|
||||||
|
Valve XM has flow rate=3; tunnels lead to valves LK, QV, YE, BS, BQ
|
157
day16/src/main.rs
Normal file
157
day16/src/main.rs
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{BufReader, BufRead};
|
||||||
|
use std::collections::{HashMap, HashSet, VecDeque};
|
||||||
|
use std::cmp::max;
|
||||||
|
use std::str::FromStr;
|
||||||
|
use std::fmt::Debug;
|
||||||
|
use std::hash::{Hash, Hasher};
|
||||||
|
|
||||||
|
const TIME: u64 = 26;
|
||||||
|
|
||||||
|
fn parse_str<T: FromStr>(str: &str) -> Result<(T, usize), <T as FromStr>::Err> {
|
||||||
|
let mut iter = str.chars().peekable();
|
||||||
|
let mut prefix = String::new();
|
||||||
|
|
||||||
|
while let Some(c) = iter.peek() {
|
||||||
|
if !c.to_string().parse::<T>().is_ok() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
prefix.push(iter.next().unwrap());
|
||||||
|
}
|
||||||
|
Ok((prefix.parse::<T>()?, prefix.len()))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Valve {
|
||||||
|
rate: u64,
|
||||||
|
links: Vec<(String, u64)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_input(fname: &String) -> Result<HashMap<String, Valve>, <u64 as FromStr>::Err> {
|
||||||
|
let file = File::open(fname).expect("cannot open input file");
|
||||||
|
let lines = BufReader::new(file).lines();
|
||||||
|
let mut valves = HashMap::new();
|
||||||
|
for line in lines.flatten() {
|
||||||
|
let name = String::from(&line[6..=7]);
|
||||||
|
let (rate, rate_len) = parse_str::<u64>(&line[23..])?;
|
||||||
|
let links_str = &line[23 + rate_len + 24..];
|
||||||
|
let mut link = String::new();
|
||||||
|
let mut links = Vec::new();
|
||||||
|
let mut iter = links_str.chars();
|
||||||
|
loop {
|
||||||
|
match iter.next() {
|
||||||
|
Some(' ') | Some(',') => continue,
|
||||||
|
None => break,
|
||||||
|
Some(c) => {
|
||||||
|
link.push(c);
|
||||||
|
link.push(iter.next().unwrap());
|
||||||
|
links.push((link.clone(), 1));
|
||||||
|
link = String::new();
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
valves.insert(name, Valve { rate, links });
|
||||||
|
}
|
||||||
|
Ok(valves)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn routes_from(valve: &String, valves: &HashMap<String, Valve>) -> Valve {
|
||||||
|
let mut visited = HashSet::from([valve.clone()]);
|
||||||
|
let mut queue = VecDeque::from([(valve.clone(), 0)]);
|
||||||
|
let mut links = Vec::new();
|
||||||
|
while !queue.is_empty() {
|
||||||
|
let (current_valve, current_cost) = queue.pop_front().unwrap();
|
||||||
|
if current_valve != *valve && valves[¤t_valve].rate > 0 {
|
||||||
|
// +1 because it takes 1min to open a valve
|
||||||
|
links.push((current_valve.clone(), current_cost + 1));
|
||||||
|
}
|
||||||
|
for (next_valve, _) in &valves[¤t_valve].links {
|
||||||
|
if !visited.contains(next_valve) {
|
||||||
|
queue.push_back((next_valve.clone(), current_cost + 1));
|
||||||
|
visited.insert(next_valve.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Valve { rate: valves[valve].rate, links: links }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn print_map<T1: Debug, T2: Debug>(map: &HashMap<T1, T2>) {
|
||||||
|
for (k, v) in map {
|
||||||
|
println!("{:?}: {:?}", k, v);
|
||||||
|
}
|
||||||
|
println!("");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||||
|
struct Visited {
|
||||||
|
set: HashSet<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Hash for Visited {
|
||||||
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||||
|
let l = &mut self.set.iter()
|
||||||
|
.filter(|x| *x != "AA")
|
||||||
|
.cloned().collect::<Vec<String>>();
|
||||||
|
l.sort();
|
||||||
|
l.join("");
|
||||||
|
l.hash(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_pressure_map(valves: &HashMap<String, Valve>) -> HashMap<Visited, u64> {
|
||||||
|
let mut max_pressure: HashMap<Visited, u64> = HashMap::new();
|
||||||
|
let mut queue: VecDeque<(String, u64, u64, Visited)> =
|
||||||
|
VecDeque::from([(
|
||||||
|
String::from("AA"), 0, 0,
|
||||||
|
Visited { set: HashSet::new() },
|
||||||
|
)]);
|
||||||
|
while !queue.is_empty() {
|
||||||
|
let (valve, cost, pressure, visited) = queue.pop_front().unwrap();
|
||||||
|
// println!("{}: {}, {}, {:?}", valve, cost, pressure, visited);
|
||||||
|
if let Some(last_max) = max_pressure.get_mut(&visited) {
|
||||||
|
*last_max = max(*last_max, pressure);
|
||||||
|
} else {
|
||||||
|
max_pressure.insert(visited.clone(), pressure);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (hop, hop_cost) in &valves[&valve].links {
|
||||||
|
let new_cost = cost + hop_cost;
|
||||||
|
if new_cost >= TIME || visited.set.contains(hop) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let new_pressure = pressure + (TIME - new_cost)*valves[hop].rate;
|
||||||
|
let mut new_visited = visited.clone();
|
||||||
|
new_visited.set.insert(hop.clone());
|
||||||
|
queue.push_back((hop.clone(), new_cost, new_pressure, new_visited));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
max_pressure
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let input_fname = env::args().nth(1).expect("need input file");
|
||||||
|
let valves = read_input(&input_fname).expect("parse error");
|
||||||
|
let mut good_valves: HashMap<String, Valve> = HashMap::new();
|
||||||
|
for (name, valve) in &valves {
|
||||||
|
if valve.rate > 0 || name == "AA" {
|
||||||
|
good_valves.insert(name.clone(), routes_from(name, &valves));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print_map(&good_valves);
|
||||||
|
|
||||||
|
let pressure_map = get_pressure_map(&good_valves);
|
||||||
|
// print_map(&pressure_map);
|
||||||
|
println!("pressure_map.len(): {}", pressure_map.len());
|
||||||
|
|
||||||
|
let mut max_pressure = 0;
|
||||||
|
for (visited1, pressure1) in &pressure_map {
|
||||||
|
for (visited2, pressure2) in &pressure_map {
|
||||||
|
if visited1.set.is_disjoint(&visited2.set) {
|
||||||
|
max_pressure = max(max_pressure, pressure1 + pressure2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!(">> {} <<", max_pressure);
|
||||||
|
}
|
||||||
|
|
103
day16/src/main1.rs
Normal file
103
day16/src/main1.rs
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{BufReader, BufRead};
|
||||||
|
use std::collections::{HashMap, HashSet, VecDeque};
|
||||||
|
use std::cmp::max;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
fn parse_str<T: FromStr>(str: &str) -> Result<(T, usize), <T as FromStr>::Err> {
|
||||||
|
let mut iter = str.chars().peekable();
|
||||||
|
let mut prefix = String::new();
|
||||||
|
|
||||||
|
while let Some(c) = iter.peek() {
|
||||||
|
if !c.to_string().parse::<T>().is_ok() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
prefix.push(iter.next().unwrap());
|
||||||
|
}
|
||||||
|
Ok((prefix.parse::<T>()?, prefix.len()))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Valve {
|
||||||
|
rate: u64,
|
||||||
|
links: Vec<(String, u64)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_input(fname: &String) -> Result<HashMap<String, Valve>, <u64 as FromStr>::Err> {
|
||||||
|
let file = File::open(fname).expect("cannot open input file");
|
||||||
|
let lines = BufReader::new(file).lines();
|
||||||
|
let mut valves = HashMap::new();
|
||||||
|
for line in lines.flatten() {
|
||||||
|
let name = String::from(&line[6..=7]);
|
||||||
|
let (rate, rate_len) = parse_str::<u64>(&line[23..])?;
|
||||||
|
let links_str = &line[23 + rate_len + 24..];
|
||||||
|
let mut link = String::new();
|
||||||
|
let mut links = Vec::new();
|
||||||
|
let mut iter = links_str.chars();
|
||||||
|
loop {
|
||||||
|
match iter.next() {
|
||||||
|
Some(' ') | Some(',') => continue,
|
||||||
|
None => break,
|
||||||
|
Some(c) => {
|
||||||
|
link.push(c);
|
||||||
|
link.push(iter.next().unwrap());
|
||||||
|
links.push((link.clone(), 1));
|
||||||
|
link = String::new();
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
valves.insert(name, Valve { rate, links });
|
||||||
|
}
|
||||||
|
Ok(valves)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn routes_from(valve: &String, valves: &HashMap<String, Valve>) -> Valve {
|
||||||
|
let mut visited = HashSet::from([valve.clone()]);
|
||||||
|
let mut queue = VecDeque::from([(valve.clone(), 0)]);
|
||||||
|
let mut links = Vec::new();
|
||||||
|
while !queue.is_empty() {
|
||||||
|
let (current_valve, current_cost) = queue.pop_front().unwrap();
|
||||||
|
if current_valve != *valve && valves[¤t_valve].rate > 0 {
|
||||||
|
// +1 because it takes 1min to open a valve
|
||||||
|
links.push((current_valve.clone(), current_cost + 1));
|
||||||
|
}
|
||||||
|
for (next_valve, _) in &valves[¤t_valve].links {
|
||||||
|
if !visited.contains(next_valve) {
|
||||||
|
queue.push_back((next_valve.clone(), current_cost + 1));
|
||||||
|
visited.insert(next_valve.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Valve { rate: valves[valve].rate, links: links }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let input_fname = env::args().nth(1).expect("need input file");
|
||||||
|
let valves = read_input(&input_fname).expect("parse error");
|
||||||
|
let mut good_valves = HashMap::new();
|
||||||
|
for (valve_name, valve) in &valves {
|
||||||
|
if valve.rate > 0 || valve_name == "AA" {
|
||||||
|
good_valves.insert(valve_name, routes_from(valve_name, &valves));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut max_pressure = 0;
|
||||||
|
let mut queue: VecDeque<(String, u64, u64, HashSet<_>)> = VecDeque::from([(
|
||||||
|
String::from("AA"), 0, 0, HashSet::from([String::from("AA")]))]);
|
||||||
|
while !queue.is_empty() {
|
||||||
|
let (valve, cost, pressure, visited) = queue.pop_front().unwrap();
|
||||||
|
max_pressure = max(max_pressure, pressure);
|
||||||
|
for (hop, hop_cost) in &good_valves[&valve].links {
|
||||||
|
if cost + hop_cost >= 30 || visited.contains(hop) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let new_cost = cost + hop_cost;
|
||||||
|
let new_pressure = pressure + (30 - new_cost)*valves[hop].rate;
|
||||||
|
let mut new_visited = visited.clone();
|
||||||
|
new_visited.insert(hop.clone());
|
||||||
|
queue.push_back((hop.clone(), new_cost, new_pressure, new_visited));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!("Max pressure: {}", max_pressure);
|
||||||
|
}
|
10
day16/test.txt
Normal file
10
day16/test.txt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
Valve AA has flow rate=0; tunnels lead to valves DD, II, BB
|
||||||
|
Valve BB has flow rate=13; tunnels lead to valves CC, AA
|
||||||
|
Valve CC has flow rate=2; tunnels lead to valves DD, BB
|
||||||
|
Valve DD has flow rate=20; tunnels lead to valves CC, AA, EE
|
||||||
|
Valve EE has flow rate=3; tunnels lead to valves FF, DD
|
||||||
|
Valve FF has flow rate=0; tunnels lead to valves EE, GG
|
||||||
|
Valve GG has flow rate=0; tunnels lead to valves FF, HH
|
||||||
|
Valve HH has flow rate=22; tunnel leads to valve GG
|
||||||
|
Valve II has flow rate=0; tunnels lead to valves AA, JJ
|
||||||
|
Valve JJ has flow rate=21; tunnel leads to valve II
|
7
day17/Cargo.lock
generated
Normal file
7
day17/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "day17"
|
||||||
|
version = "0.1.0"
|
6
day17/Cargo.toml
Normal file
6
day17/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "day17"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user