Commit 8736151 1 parent 343d6d0 commit 8736151 Copy full SHA for 8736151
File tree 3 files changed +186
-3
lines changed
3 files changed +186
-3
lines changed Original file line number Diff line number Diff line change 7
7
8
8
using namespace std ;
9
9
10
- #define NUM_HEIGHTS 10
11
10
const bool DEBUG=false ;
12
11
13
12
@@ -28,6 +27,8 @@ int main(int argc,char* argv[]){
28
27
29
28
while (true ){
30
29
getline (inp_file, s);
30
+ stringstream ss;
31
+ ss<<s<<" \n " ;
31
32
32
33
if (inp_file.eof ()){
33
34
Original file line number Diff line number Diff line change 7
7
8
8
using namespace std ;
9
9
10
- #define NUM_HEIGHTS 10
11
10
const bool DEBUG=false ;
12
11
12
+ void do_cycle (int cycle, int X, long int & ans){
13
+ if (abs (X-(cycle-1 )%40 )<2 ){
14
+ cout<<" #" ;
15
+ }
16
+ else {cout<<" ." ;}
17
+ if ((cycle)%40 ==0 ) cout<<endl;
18
+
19
+ if ((cycle-20 )%40 ==0 ){
20
+ if (DEBUG) cout<<" cycle : " <<cycle<<" X : " <<X<<endl;
21
+ ans+=(cycle*X);
22
+ }
23
+ }
13
24
14
25
int main (int argc,char * argv[]){
15
26
@@ -25,10 +36,36 @@ int main(int argc,char* argv[]){
25
36
26
37
long int ans=0 ;
27
38
string s;
39
+ string s1;
40
+ int z;
41
+ int X=1 ;
42
+ int cycle=1 ;
28
43
29
44
while (true ){
30
45
getline (inp_file, s);
31
-
46
+ stringstream ss;
47
+ ss<<s<<" \n " ;
48
+ ss>>s1;
49
+
50
+ do_cycle (cycle,X,ans);
51
+ if (s1[0 ]==' a' ){
52
+ ss>>z;
53
+ cycle+=1 ;
54
+ }
55
+ else if (s1[0 ]==' n' ){
56
+ cycle+=1 ;
57
+ }
58
+ if (s1[0 ]==' a' ){
59
+ do_cycle (cycle,X,ans);
60
+ if (DEBUG) cout<<" adding " <<z<<endl;
61
+ X+=z;
62
+ cycle+=1 ;
63
+ }
64
+
65
+
66
+ // if(cycle>220){ //this was for part 1
67
+ // break;
68
+ // }
32
69
if (inp_file.eof ()){
33
70
34
71
break ;
Original file line number Diff line number Diff line change
1
+ noop
2
+ noop
3
+ noop
4
+ addx 3
5
+ addx 7
6
+ noop
7
+ noop
8
+ noop
9
+ noop
10
+ addx 6
11
+ noop
12
+ addx -1
13
+ noop
14
+ addx 5
15
+ addx 1
16
+ noop
17
+ addx 4
18
+ noop
19
+ noop
20
+ noop
21
+ noop
22
+ addx 6
23
+ addx -1
24
+ noop
25
+ addx 3
26
+ addx -13
27
+ addx -22
28
+ noop
29
+ noop
30
+ addx 3
31
+ addx 2
32
+ addx 11
33
+ addx -4
34
+ addx 11
35
+ addx -10
36
+ addx 2
37
+ addx 5
38
+ addx 2
39
+ addx -2
40
+ noop
41
+ addx 7
42
+ addx 3
43
+ addx -2
44
+ addx 2
45
+ addx 5
46
+ addx 2
47
+ addx -2
48
+ addx -8
49
+ addx -27
50
+ addx 5
51
+ addx 2
52
+ addx 21
53
+ addx -21
54
+ addx 3
55
+ addx 5
56
+ addx 2
57
+ addx -3
58
+ addx 4
59
+ addx 3
60
+ addx 1
61
+ addx 5
62
+ noop
63
+ noop
64
+ noop
65
+ noop
66
+ addx 3
67
+ addx 1
68
+ addx 6
69
+ addx -31
70
+ noop
71
+ addx -4
72
+ noop
73
+ noop
74
+ noop
75
+ noop
76
+ addx 3
77
+ addx 7
78
+ noop
79
+ addx -1
80
+ addx 1
81
+ addx 5
82
+ noop
83
+ addx 1
84
+ noop
85
+ addx 2
86
+ addx -8
87
+ addx 15
88
+ addx 3
89
+ noop
90
+ addx 2
91
+ addx 5
92
+ noop
93
+ noop
94
+ noop
95
+ addx -28
96
+ addx 11
97
+ addx -20
98
+ noop
99
+ addx 7
100
+ addx -2
101
+ addx 7
102
+ noop
103
+ addx -2
104
+ noop
105
+ addx -6
106
+ addx 11
107
+ noop
108
+ addx 3
109
+ addx 2
110
+ noop
111
+ noop
112
+ addx 7
113
+ addx 3
114
+ addx -2
115
+ addx 2
116
+ addx 5
117
+ addx 2
118
+ addx -16
119
+ addx -10
120
+ addx -11
121
+ addx 27
122
+ addx -20
123
+ noop
124
+ addx 2
125
+ addx 3
126
+ addx 5
127
+ noop
128
+ noop
129
+ noop
130
+ addx 3
131
+ addx -2
132
+ addx 2
133
+ noop
134
+ addx -14
135
+ addx 21
136
+ noop
137
+ addx -6
138
+ addx 12
139
+ noop
140
+ addx -21
141
+ addx 24
142
+ addx 2
143
+ noop
144
+ noop
145
+ noop
You can’t perform that action at this time.
0 commit comments