aboutsummaryrefslogtreecommitdiff
path: root/src/Utils.kt
diff options
context:
space:
mode:
authortchojnacki <tomaszchojnacki2001@gmail.com>2021-12-03 14:47:43 +0100
committertchojnacki <tomaszchojnacki2001@gmail.com>2021-12-03 14:47:43 +0100
commitd5057fc4d578fba728a3ee70d9ba73e84a8a6772 (patch)
treeb10e717c4b4e610d6317e9e0307b3f9839552726 /src/Utils.kt
parente422b972d872b05ea6c8f7f62680ac483ba107a4 (diff)
downloadgleam_aoc2020-d5057fc4d578fba728a3ee70d9ba73e84a8a6772.tar.gz
gleam_aoc2020-d5057fc4d578fba728a3ee70d9ba73e84a8a6772.zip
Improve documentation
Diffstat (limited to 'src/Utils.kt')
-rw-r--r--src/Utils.kt14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/Utils.kt b/src/Utils.kt
index 23eacb9..27b88b5 100644
--- a/src/Utils.kt
+++ b/src/Utils.kt
@@ -4,16 +4,30 @@ import java.security.MessageDigest
/**
* Reads lines from the given input txt file.
+ * @param name name of the file
+ * @return list of strings containing line contents
*/
fun readInputAsLines(name: String): List<String> = File("src", "$name.txt").readLines()
+/**
+ * Read lines from the given input txt file and convert them to decimal numbers.
+ * @param name name of the file
+ * @return list of ints containing numbers from each of file's lines
+ */
fun readInputAsNumbers(name: String): List<Int> = readInputAsLines(name).map { it.toInt() }
+/**
+ * Read lines from the given input txt file containing binary numbers and convert them to lists of bits.
+ * @param name name of the file
+ * @return list of lists of ints, where each inner list represents bits of one line of input
+ */
fun readInputAsBitLists(name: String): List<List<Int>> =
readInputAsLines(name)
.map { binaryString -> binaryString.toList().map { bit -> bit.toString().toInt() } }
/**
* Converts string to md5 hash.
+ * @receiver a string
+ * @return md5 hash of receiver
*/
fun String.md5(): String = BigInteger(1, MessageDigest.getInstance("MD5").digest(toByteArray())).toString(16)