commit e709c369c5d8031d10656e6e25d29d77d3a38d0d
Author: WanCW <contact@wancw.idv.tw>
Date:   Mon Dec 2 11:41:49 2024 +0800

    complete day 1

diff --git a/01-a.kts b/01-a.kts
new file mode 100644
index 0000000..1d9fbe7
--- /dev/null
+++ b/01-a.kts
@@ -0,0 +1,22 @@
+import java.util.Scanner
+import kotlin.math.abs
+
+val scanner = Scanner(System.`in`)
+
+val listLeft = ArrayList<Int>()
+val listRight = ArrayList<Int>()
+
+while (scanner.hasNextInt()) {
+    val num1 = scanner.nextInt()
+    listLeft.add(num1)
+
+    val num2 = scanner.nextInt()
+    listRight.add(num2)
+}
+
+val pairs = listLeft.sorted() zip listRight.sorted()
+
+val result = pairs.fold(0) { acc, (l, r) -> acc + abs(l - r) }
+
+println(result)
+
diff --git a/01-b.kts b/01-b.kts
new file mode 100644
index 0000000..ec62773
--- /dev/null
+++ b/01-b.kts
@@ -0,0 +1,24 @@
+import java.util.Scanner
+
+val scanner = Scanner(System.`in`)
+
+val listLeft = ArrayList<Int>()
+val listRight = ArrayList<Int>()
+
+while (scanner.hasNextInt()) {
+    val num1 = scanner.nextInt()
+    listLeft.add(num1)
+
+    val num2 = scanner.nextInt()
+    listRight.add(num2)
+}
+
+
+val rightFrequencies = listRight.groupingBy { it }.eachCount()
+
+val sum = listLeft.fold(0, { sum, left ->
+    sum + left * (rightFrequencies[left] ?: 0)
+})
+
+println(sum)
+