Skip to content

Commit e3081dd

Browse files
committed
Added solution for part 1
1 parent 2f9e268 commit e3081dd

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

Day-06/kotlin/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.txt

Day-06/kotlin/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Kotlin Solution
2+
I recommend to use [kscript](https://github.com/holgerbrandl/kscript) by [@holgerbrandl](https://github.com/holgerbrandl) to execute the script file.

Day-06/kotlin/solution.kts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import java.nio.file.Files
2+
import java.nio.file.Paths
3+
4+
val answers = ArrayList<Answer>()
5+
6+
var answer = Answer()
7+
val lines = Files.readAllLines(Paths.get("input.txt"))
8+
9+
var index = 0
10+
var lastLineCount = 0
11+
12+
while (index < lines.size) {
13+
val line = lines[index]
14+
15+
if (line.isBlank()) {
16+
index++
17+
continue
18+
}
19+
20+
answer.people = ++lastLineCount
21+
answer.questions.addAll(line.toCharArray().toList())
22+
23+
if (++index < lines.size) {
24+
if (lines[index].isBlank()) {
25+
answers.add(answer)
26+
answer = Answer()
27+
lastLineCount = 0
28+
}
29+
} else {
30+
answers.add(answer)
31+
answer = Answer()
32+
lastLineCount = 0
33+
}
34+
}
35+
36+
println(answers.map { it.questions.size }.sum())
37+
38+
data class Answer(val questions: MutableSet<Char> = HashSet<Char>(), var people: Int = 0)

0 commit comments

Comments
 (0)