File tree 3 files changed +70
-0
lines changed
3 files changed +70
-0
lines changed Original file line number Diff line number Diff line change
1
+ def fetch_input (input_file ):
2
+ with open (input_file , 'r' ) as f :
3
+ commands = f .readlines ()
4
+
5
+ commands = [command .strip () for command in commands ]
6
+ return commands
7
+
8
+
9
+ def main ():
10
+ commands = fetch_input ('input_files/2.txt' )
11
+ destination = {
12
+ 'horizontal' : 0 ,
13
+ 'vertical' : 0 ,
14
+ }
15
+ for command in commands :
16
+ direction , increment = command .split (' ' )
17
+ increment = int (increment )
18
+
19
+ if (direction == 'forward' ):
20
+ destination ['horizontal' ] += increment
21
+ elif (direction == 'up' ):
22
+ destination ['vertical' ] -= increment
23
+ elif (direction == 'down' ):
24
+ destination ['vertical' ] += increment
25
+
26
+ print (destination )
27
+ print (destination ['horizontal' ] * destination ['vertical' ])
28
+
29
+
30
+ if __name__ == "__main__" :
31
+ main ()
Original file line number Diff line number Diff line change
1
+ def fetch_input (input_file ):
2
+ with open (input_file , 'r' ) as f :
3
+ commands = f .readlines ()
4
+
5
+ commands = [command .strip () for command in commands ]
6
+ return commands
7
+
8
+
9
+ def main ():
10
+ commands = fetch_input ('input_files/2.txt' )
11
+ destination = {
12
+ 'horizontal' : 0 ,
13
+ 'vertical' : 0 ,
14
+ 'aim' : 0 ,
15
+ }
16
+ for command in commands :
17
+ direction , increment = command .split (' ' )
18
+ increment = int (increment )
19
+
20
+ if (direction == 'forward' ):
21
+ destination ['horizontal' ] += increment
22
+ destination ['vertical' ] += (destination ['aim' ] * increment )
23
+ elif (direction == 'up' ):
24
+ destination ['aim' ] -= increment
25
+ elif (direction == 'down' ):
26
+ destination ['aim' ] += increment
27
+
28
+ print (destination )
29
+ print (destination ['horizontal' ] * destination ['vertical' ])
30
+
31
+
32
+ if __name__ == "__main__" :
33
+ main ()
Original file line number Diff line number Diff line change
1
+ forward 5
2
+ down 5
3
+ forward 8
4
+ up 3
5
+ down 8
6
+ forward 2
You can’t perform that action at this time.
0 commit comments