Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 20335a5

Browse filesBrowse files
committed
Final configuration, code, and solution to Advent of Code 2024 Day 3, Part 2.
1 parent 9e4aa14 commit 20335a5
Copy full SHA for 20335a5

File tree

8 files changed

+113
-0
lines changed
Filter options

8 files changed

+113
-0
lines changed

‎2024/day03_2/.idea/inspectionProfiles/Project_Default.xml

Copy file name to clipboardExpand all lines: 2024/day03_2/.idea/inspectionProfiles/Project_Default.xml
+6Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎2024/day03_2/.idea/kotlinc.xml

Copy file name to clipboardExpand all lines: 2024/day03_2/.idea/kotlinc.xml
+10Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎2024/day03_2/.idea/libraries/KotlinJavaRuntime.xml

Copy file name to clipboardExpand all lines: 2024/day03_2/.idea/libraries/KotlinJavaRuntime.xml
+17Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎2024/day03_2/.idea/misc.xml

Copy file name to clipboardExpand all lines: 2024/day03_2/.idea/misc.xml
+6Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎2024/day03_2/.idea/modules.xml

Copy file name to clipboardExpand all lines: 2024/day03_2/.idea/modules.xml
+8Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎2024/day03_2/.idea/vcs.xml

Copy file name to clipboardExpand all lines: 2024/day03_2/.idea/vcs.xml
+6Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎2024/day03_2/day03_2.iml

Copy file name to clipboard
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
7+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
8+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
9+
<sourceFolder url="file://$MODULE_DIR$/testResources" type="java-test-resource" />
10+
</content>
11+
<orderEntry type="inheritedJdk" />
12+
<orderEntry type="sourceFolder" forTests="false" />
13+
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
14+
</component>
15+
</module>

‎2024/day03_2/src/Main.kt

Copy file name to clipboard
+45Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import java.io.File
2+
3+
// important note: RegEx that handles the problem: mul\(\d{1,3},\d{1,3}\)
4+
// mul\(\d{1,3},\d{1,3}\)|do\(\)|don\'t\(\)
5+
fun main(args: Array<String>) {
6+
println("AOC 2024, Day 3, Part 2 starting!!!!")
7+
8+
val theOperations = MulOperations()
9+
val theRegex = "mul\\(\\d{1,3},\\d{1,3}\\)|do\\(\\)|don\'t\\(\\)".toRegex()
10+
var enableMul = true
11+
File(args[0]).forEachLine {
12+
val theMatches = theRegex.findAll(it)
13+
for(match in theMatches) {
14+
if(match.value == "don't()") {
15+
enableMul = false
16+
continue
17+
}
18+
if(match.value == "do()") {
19+
enableMul = true
20+
continue
21+
}
22+
if(enableMul) {
23+
theOperations.dataList.add(match.value)
24+
}
25+
}
26+
}
27+
28+
println("The answer: ${theOperations.results()}")
29+
30+
println("AOC 2024, Day 3, Part 2 completed!!!")
31+
}
32+
33+
class MulOperations {
34+
val dataList = ArrayList<String>()
35+
36+
fun results():Long {
37+
var theResult = 0L
38+
val regex = "(\\d{1,3})".toRegex()
39+
for(d in dataList) {
40+
val theMatches = regex.findAll(d)
41+
theResult += (theMatches.first().value.toLong() * theMatches.last().value.toLong())
42+
}
43+
return theResult
44+
}
45+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.