Skip to content

Commit a0d980a

Browse files
committed
Reformat the whole project
1 parent b7a3dde commit a0d980a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+901
-833
lines changed

src/main/java/Exercise1-part2.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ fun main() {
1111
}
1212
}
1313
}
14-
}
14+
}

src/main/java/Exercise1.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,5 @@ fun main() {
22
val input = object {}.javaClass.getResource("input-1.txt").readText().split("\n")
33

44
val numberSet = input.toSet().map { it.toInt() }
5-
numberSet
6-
.first { (2020 - it) in numberSet }
7-
.let { it * (2020 - it) }
8-
.also(::println)
9-
}
5+
numberSet.first { (2020 - it) in numberSet }.let { it * (2020 - it) }.also(::println)
6+
}

src/main/java/Exercise10-part2.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
fun main() {
2-
object {}.javaClass.getResource("input-10.txt").readText().split("\n")
2+
object {}
3+
.javaClass
4+
.getResource("input-10.txt")
5+
.readText()
6+
.split("\n")
37
.map(String::toLong)
4-
.toMutableList().apply {
8+
.toMutableList()
9+
.apply {
510
add(0)
611
sort()
712
add(last() + 3)
@@ -23,6 +28,3 @@ fun countCombinations(list: List<Long>, index: Int): Long {
2328
map[index] = count
2429
return count
2530
}
26-
27-
28-

src/main/java/Exercise10.kt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
fun main() {
2-
val input = object {}.javaClass.getResource("input-10.txt").readText().split("\n")
3-
.map(String::toLong)
4-
.toMutableList().apply {
5-
add(0)
6-
sort()
7-
add(last() + 3)
8-
}
2+
val input =
3+
object {}
4+
.javaClass
5+
.getResource("input-10.txt")
6+
.readText()
7+
.split("\n")
8+
.map(String::toLong)
9+
.toMutableList()
10+
.apply {
11+
add(0)
12+
sort()
13+
add(last() + 3)
14+
}
915
var count1 = 0
1016
var count3 = 0
1117

@@ -21,5 +27,3 @@ fun main() {
2127
}
2228
println(count1 * count3)
2329
}
24-
25-

src/main/java/Exercise11-part2.kt

Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
fun main() {
2-
val input: List<CharArray> = object {}.javaClass.getResource("input-11.txt").readText()
3-
.split("\n")
4-
.map(String::toCharArray)
2+
val input: List<CharArray> =
3+
object {}
4+
.javaClass
5+
.getResource("input-11.txt")
6+
.readText()
7+
.split("\n")
8+
.map(String::toCharArray)
59

6-
var array1 = Array(input.size) { i ->
7-
CharArray(input[i].size) { j ->
8-
input[i][j]
9-
}
10-
}
10+
var array1 = Array(input.size) { i -> CharArray(input[i].size) { j -> input[i][j] } }
1111
var array2 = Array(input.size) { i -> CharArray(input[i].size) { ' ' } }
1212
var occupiedPlaces: Int
1313

@@ -16,27 +16,28 @@ fun main() {
1616
occupiedPlaces = 0
1717
for (i in array1.indices) {
1818
for (j in array1[i].indices) {
19-
array2[i][j] = when (array1[i][j]) {
20-
'.' -> '.'
21-
'#' -> {
22-
if (countVisibleOccupied(array1, i, j, '#') >= 5) {
23-
countedChanges++
24-
'L'
25-
} else {
26-
occupiedPlaces++
27-
'#'
19+
array2[i][j] =
20+
when (array1[i][j]) {
21+
'.' -> '.'
22+
'#' -> {
23+
if (countVisibleOccupied(array1, i, j, '#') >= 5) {
24+
countedChanges++
25+
'L'
26+
} else {
27+
occupiedPlaces++
28+
'#'
29+
}
2830
}
29-
}
30-
else -> { // L
31-
if (countVisibleOccupied(array1, i, j, '#') <= 0) {
32-
countedChanges++
33-
occupiedPlaces++
34-
'#'
35-
} else {
36-
'L'
31+
else -> { // L
32+
if (countVisibleOccupied(array1, i, j, '#') <= 0) {
33+
countedChanges++
34+
occupiedPlaces++
35+
'#'
36+
} else {
37+
'L'
38+
}
3739
}
3840
}
39-
}
4041
}
4142
}
4243
array1 = array2
@@ -45,22 +46,19 @@ fun main() {
4546
println(occupiedPlaces)
4647
}
4748

48-
fun countVisibleOccupied(
49-
array: Array<CharArray>,
50-
i: Int,
51-
j: Int,
52-
target: Char
53-
) = listOf(
54-
-1 to 0,
55-
-1 to -1,
56-
-1 to +1,
57-
0 to -1,
58-
0 to +1,
59-
+1 to 0,
60-
+1 to -1,
61-
+1 to +1,
62-
).map { (dirX, dirY) -> toVisible(array, i, j, dirX, dirY) }
63-
.count { it == target }
49+
fun countVisibleOccupied(array: Array<CharArray>, i: Int, j: Int, target: Char) =
50+
listOf(
51+
-1 to 0,
52+
-1 to -1,
53+
-1 to +1,
54+
0 to -1,
55+
0 to +1,
56+
+1 to 0,
57+
+1 to -1,
58+
+1 to +1,
59+
)
60+
.map { (dirX, dirY) -> toVisible(array, i, j, dirX, dirY) }
61+
.count { it == target }
6462

6563
fun toVisible(array: Array<CharArray>, i: Int, j: Int, dirX: Int, dirY: Int): Char {
6664
var nexti = i + dirX
@@ -72,5 +70,3 @@ fun toVisible(array: Array<CharArray>, i: Int, j: Int, dirX: Int, dirY: Int): Ch
7270
}
7371
return '.'
7472
}
75-
76-

src/main/java/Exercise11.kt

Lines changed: 45 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
fun main() {
2-
val input: List<CharArray> = object {}.javaClass.getResource("input-11.txt").readText()
3-
.split("\n")
4-
.map(String::toCharArray)
2+
val input: List<CharArray> =
3+
object {}
4+
.javaClass
5+
.getResource("input-11.txt")
6+
.readText()
7+
.split("\n")
8+
.map(String::toCharArray)
59

6-
var array1 = Array(input.size) { i ->
7-
CharArray(input[i].size) { j ->
8-
input[i][j]
9-
}
10-
}
10+
var array1 = Array(input.size) { i -> CharArray(input[i].size) { j -> input[i][j] } }
1111
var array2 = Array(input.size) { i -> CharArray(input[i].size) { ' ' } }
1212
var occupiedPlaces: Int
1313

@@ -16,28 +16,29 @@ fun main() {
1616
occupiedPlaces = 0
1717
for (i in array1.indices) {
1818
for (j in array1[i].indices) {
19-
array2[i][j] = when (array1[i][j]) {
20-
'.' -> '.'
21-
'#' -> {
22-
if (countOccupied(array1, i, j, '#') >= 4) {
23-
countedChanges++
24-
'L'
25-
} else {
26-
occupiedPlaces++
27-
'#'
19+
array2[i][j] =
20+
when (array1[i][j]) {
21+
'.' -> '.'
22+
'#' -> {
23+
if (countOccupied(array1, i, j, '#') >= 4) {
24+
countedChanges++
25+
'L'
26+
} else {
27+
occupiedPlaces++
28+
'#'
29+
}
2830
}
29-
}
30-
// L
31-
else -> {
32-
if (countOccupied(array1, i, j, '#') <= 0) {
33-
countedChanges++
34-
occupiedPlaces++
35-
'#'
36-
} else {
37-
'L'
31+
// L
32+
else -> {
33+
if (countOccupied(array1, i, j, '#') <= 0) {
34+
countedChanges++
35+
occupiedPlaces++
36+
'#'
37+
} else {
38+
'L'
39+
}
3840
}
3941
}
40-
}
4142
}
4243
}
4344
array1 = array2
@@ -46,25 +47,20 @@ fun main() {
4647
println(occupiedPlaces)
4748
}
4849

49-
fun countOccupied(
50-
array: Array<CharArray>,
51-
i: Int,
52-
j: Int,
53-
target: Char
54-
) = listOf(
55-
i - 1 to j,
56-
i - 1 to j - 1,
57-
i - 1 to j + 1,
58-
i to j - 1,
59-
i to j + 1,
60-
i + 1 to j,
61-
i + 1 to j - 1,
62-
i + 1 to j + 1,
63-
).asSequence()
64-
.filter { it.first >= 0 }
65-
.filter { it.first < array.size }
66-
.filter { it.second >= 0 }
67-
.filter { it.second < array[0].size }
68-
.count { array[it.first][it.second] == target }
69-
70-
50+
fun countOccupied(array: Array<CharArray>, i: Int, j: Int, target: Char) =
51+
listOf(
52+
i - 1 to j,
53+
i - 1 to j - 1,
54+
i - 1 to j + 1,
55+
i to j - 1,
56+
i to j + 1,
57+
i + 1 to j,
58+
i + 1 to j - 1,
59+
i + 1 to j + 1,
60+
)
61+
.asSequence()
62+
.filter { it.first >= 0 }
63+
.filter { it.first < array.size }
64+
.filter { it.second >= 0 }
65+
.filter { it.second < array[0].size }
66+
.count { array[it.first][it.second] == target }

src/main/java/Exercise12-part2.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import kotlin.math.absoluteValue
22

33
fun main() {
4-
val input = object {}.javaClass.getResource("input-12.txt").readText()
5-
.split("\n")
6-
.map { it.first() to it.drop(1).toInt() }
4+
val input =
5+
object {}.javaClass.getResource("input-12.txt").readText().split("\n").map {
6+
it.first() to it.drop(1).toInt()
7+
}
78
var x = 0
89
var y = 0
910

@@ -34,12 +35,13 @@ fun rotateWaypoint(wayX: Int, wayY: Int, action: Char, value: Int): Pair<Int, In
3435
var degrees = value
3536
var newWay = wayX to wayY
3637
while (degrees != 0) {
37-
newWay = if (action == 'R') {
38-
newWay.second to -1 * newWay.first
39-
} else {
40-
-1 * newWay.second to newWay.first
41-
}
38+
newWay =
39+
if (action == 'R') {
40+
newWay.second to -1 * newWay.first
41+
} else {
42+
-1 * newWay.second to newWay.first
43+
}
4244
degrees -= 90
4345
}
4446
return newWay
45-
}
47+
}

src/main/java/Exercise12.kt

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import kotlin.math.absoluteValue
22

33
fun main() {
4-
val input = object {}.javaClass.getResource("input-12.txt").readText()
5-
.split("\n")
6-
.map { it.first() to it.drop(1).toInt() }
4+
val input =
5+
object {}.javaClass.getResource("input-12.txt").readText().split("\n").map {
6+
it.first() to it.drop(1).toInt()
7+
}
78
var dir = Direction.E
89
var x = 0
910
var y = 0
@@ -14,32 +15,37 @@ fun main() {
1415
'E' -> x += value
1516
'W' -> x -= value
1617
'L', 'R' -> dir = rotate(dir, action, value)
17-
'F' -> when (dir) {
18-
Direction.N -> y += value
19-
Direction.S -> y -= value
20-
Direction.E -> x += value
21-
Direction.W -> x -= value
22-
}
18+
'F' ->
19+
when (dir) {
20+
Direction.N -> y += value
21+
Direction.S -> y -= value
22+
Direction.E -> x += value
23+
Direction.W -> x -= value
24+
}
2325
}
2426
}
2527
println(x.absoluteValue + y.absoluteValue)
2628
}
2729

2830
enum class Direction {
29-
N, E, S, W
31+
N,
32+
E,
33+
S,
34+
W
3035
}
3136

3237
fun rotate(dir: Direction, action: Char, value: Int): Direction {
3338
var degrees = value
3439
var newDir = dir
3540
while (degrees != 0) {
3641
val idx = Direction.values().indexOf(newDir)
37-
newDir = if (action == 'R') {
38-
Direction.values()[(idx + 1) % 4]
39-
} else {
40-
Direction.values()[if (idx - 1 == -1) 3 else idx - 1]
41-
}
42+
newDir =
43+
if (action == 'R') {
44+
Direction.values()[(idx + 1) % 4]
45+
} else {
46+
Direction.values()[if (idx - 1 == -1) 3 else idx - 1]
47+
}
4248
degrees -= 90
4349
}
4450
return newDir
45-
}
51+
}

0 commit comments

Comments
 (0)