-
Notifications
You must be signed in to change notification settings - Fork 0
/
part2.rs
167 lines (151 loc) · 2.7 KB
/
part2.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
use super::*;
use regex::Regex;
use std::collections::HashMap;
type OutputType = super::part1::OutputType;
// 363871 -> too low
pub fn solve(input: &InputType, config: &PuzzleConfig) -> OutputType {
let mut aa = 1; // rs[0]
let mut bb = 0; // rs[1]
let mut cc = 0; // rs[2]
let mut __ = 0; // rs[3]
let mut dd = 0; // rs[4]
let mut ee = 0; // rs[5]
let jmp = |_|{};
// calculate target value
/*
dd += 2;
dd *= dd;
dd *= 19;
dd *= 11;
bb += 6;
bb *= 22;
bb += 21;
dd += bb;
*/
// bb = 153; // = 6 * 22 + 21;
// dd = 989; // = ((2 * 2) * 19) * 11 + bb;
/*
bb = 27;
bb *= 28;
bb += 29;
bb *= 30;
bb *= 14;
bb *= 32;
dd += bb;
aa = 0;
*/
bb = 10550400; //(((27 * 28 + 29) * 30) * 14) * 32;
dd = 10551389; //989 + 10550400;
aa = 0;
for ee in 1 ..= dd {
// the '/ ee' optimization was naturally NOT part of the input and was the entire point
// of this challenge ;)
for cc in 1 ..= dd / ee {
// looking for sweet divisors
if ee * cc == dd {
// accumulate
aa += ee;
}
}
}
return aa;
// ================
// I will keep my
// 0
jmp(7);
// 1
// JUMP FROM 26
// JUMP FROM 35
ee = 1;
// 2
// JUMP FROM 13
cc = 1;
// 3
// JMP FROM 9
bb = ee * cc;
if bb == dd {
jmp(4);
} else {
jmp(5);
}
// 4 (7)
// JUMP FROM 4
aa += ee;
// 5 (8)
// JUMP FROM 4
cc += 1;
if cc > dd {
jmp(6);
} else {
jmp(3);
}
// 6 (12)
// JUMP FROM 9
ee += 1;
if ee > dd {
return aa;
} else {
jmp(2);
}
// 7 (17)
// JUMP FROM 0
dd += 2;
dd *= dd;
dd *= 19;
dd *= 11;
bb += 6;
bb *= 22;
bb += 21;
dd += bb;
//jmp(8 + aa);
if aa < 9 {
jmp(8 + aa);
} else if aa == 9 {
jmp(1);
} else {
return aa;
}
// 8
// jump from 25 if aa == 0
jmp(1);
// 9
// jump from 25 if aa == 1
bb = 27;
// 10
// jump from 25 if aa == 2
bb *= 28;
// 11
// jump from 25 if aa == 3
bb += 29;
// 12
// jump from 25 if aa == 4
bb *= 30;
// 13
// jump from 25 if aa == 5
bb *= 14;
// 14
// jump from 25 if aa == 6
bb *= 32;
// 15
// jump from 25 if aa == 7
dd += bb;
// 16
// jump from 25 if aa == 8
aa = 0;
// 17
// jump from 25 if aa == 9
jmp(1);
0
}
#[cfg(test)]
mod tests {
use super::*;
fn solve_example(name: &str) -> OutputType {
let (input, config) = parse_input(name, false);
solve(&input, &config)
}
#[test]
fn examples() {
assert_eq!(solve_example("example1"), OutputType::default());
}
}