https://kotlinlang.org logo
#getting-started
Title
# getting-started
a

Ayfri

12/05/2021, 2:58 PM
Hi, I'm doing advent of code 2021 and I have a very very very weird bug where my console is broken and only display a fraction of the lines, when I execute this code :
Copy code
val data = readFile("day1.txt")
val pairs = data.trimEnd().split("\n").zipWithNext().toMap()
val result = pairs.count { a ->
	return@count a.key == a.value
}
	
pairs.forEach { println("key=${it.key}, value=${it.value}") }
	
println(result)
I don't get the
key=something
part in my console
I'm using Intellij Idea 2021.3 with Kotlin 1.6.0, Gradle 7.3.1 and here is my repo : https://github.com/Ayfri/advent-of-code-2021
e

ephemient

12/05/2021, 3:06 PM
are you using Windows? whatever you used to save the .txt file added DOS-style newlines (\r\n)
the advent of code site itself only serves \n
a

Ayfri

12/05/2021, 3:08 PM
oh yes, it was Intellij that saved the file using CRLF, thanks !
but in this case I would recommend saving the file directly from a browser (or scripting the HTTP fetch) instead of copy-pasting
a

Ayfri

12/05/2021, 3:31 PM
Yeah I've done that it's simpler, but I have to use
ktor
&
dotenv
libraries (as it requires a
session
cookie and I'm storing the token into a
.env
file as I guess it's important to)
e

ephemient

12/05/2021, 9:41 PM
I'm well aware that a cookie is required, that's why my repo has https://github.com/ephemient/aoc2021/blob/main/get-inputs.main.kts + https://github.com/ephemient/aoc2021/blob/main/.github/workflows/get-inputs.yml and session set in GitHub Actions secret. not sure why you'd have to use ktor or dotenv, but sure those could be made to work as well
a

Ayfri

12/06/2021, 2:18 AM
I use ktor for making the request, I know it is possible using JDK but I'm to lazy to haha
5 Views