File tree 3 files changed +68
-2
lines changed
2021/day2-2/src/main/kotlin
3 files changed +68
-2
lines changed Original file line number Diff line number Diff line change 2
2
/2021 /day2-1 /.gradle /
3
3
/2021 /day2-1 /.idea /
4
4
/2021 /day2-2 /build /
5
- /2021 /day2-2 /.gradle /
6
- /2021 /day2-2 /.idea /
Original file line number Diff line number Diff line change
1
+ import java.io.File
2
+
3
+ fun main (args : Array <String >) {
4
+ println (" AOC 2021, Day 2.2 starting!!!!" )
5
+
6
+ val mySub = TheSub ()
7
+ File (args[0 ]).forEachLine {
8
+ mySub.processLine(it)
9
+ }
10
+
11
+ mySub.answer()
12
+
13
+ println (" AOC 2021, Day 2.2 complete!!!!" )
14
+ }
15
+
16
+ class TheSub {
17
+ private var aim : Long = 0
18
+ private var depth : Long = 0
19
+ private var horizontal : Long = 0
20
+
21
+ fun move (direction : String , steps : Long ) {
22
+ if (direction.compareTo(" forward" ) == 0 ) {
23
+ horizontal + = steps
24
+ depth + = aim * steps
25
+ }
26
+ if (direction.compareTo(" down" ) == 0 ) {
27
+ aim + = steps
28
+ }
29
+ if (direction.compareTo(" up" ) == 0 ) {
30
+ aim - = steps
31
+ }
32
+ }
33
+
34
+ fun processLine (line : String ) {
35
+ val theSplitString = line.split(" \\ s+" .toRegex())
36
+ val direction = theSplitString[0 ]
37
+ val steps = theSplitString[1 ].toLong()
38
+
39
+ move(direction, steps)
40
+ }
41
+
42
+
43
+ fun answer () {
44
+ println (" latest aim = $aim " )
45
+ println (" latest depth = $depth " )
46
+ println (" latest horizontal = $horizontal " )
47
+ println (" my answer = " + (depth * horizontal))
48
+ }
49
+ }
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <module type =" JAVA_MODULE" version =" 4" >
3
+ <component name =" FacetManager" >
4
+ <facet type =" Python" name =" Python" >
5
+ <configuration sdkName =" Python 2.7 (adventofcode)" />
6
+ </facet >
7
+ </component >
8
+ <component name =" NewModuleRootManager" inherit-compiler-output =" true" >
9
+ <exclude-output />
10
+ <content url =" file://$MODULE_DIR$" >
11
+ <sourceFolder url =" file://$MODULE_DIR$/src" isTestSource =" false" />
12
+ <excludeFolder url =" file://$MODULE_DIR$/venv" />
13
+ </content >
14
+ <orderEntry type =" inheritedJdk" />
15
+ <orderEntry type =" sourceFolder" forTests =" false" />
16
+ <orderEntry type =" library" name =" Python 2.7 (adventofcode) interpreter library" level =" application" />
17
+ <orderEntry type =" library" name =" KotlinJavaRuntime" level =" project" />
18
+ </component >
19
+ </module >
You can’t perform that action at this time.
0 commit comments