for part2 you could use `flatMap` to cut down code...
# advent-of-code
h
for part2 you could use
flatMap
to cut down code. And it would also fail (same as mine, but not in @karelpeeters solution) if there would be number duplicates in a row.
a
Again, I wanted to be able to handle duplicates & so solution is a bit wordy.
Having issues loading the input file as a resource, even if the file exists in a resources dir I don't seem to be able to load it. Sure I've done this before but can't see what I am missing
s
I'm using
val input = File(Main::class.java.getResource("input.txt").file).readLines()
if that helps
k
For these challenges I think it's easier to just paste the input in source:
val input = """ ... """
.
a
Thanks @stkent, tried that but the call to getResource("input.txt") just returns null even if the file is in the src/main/resources or src/test/resources & these are configured in the IDEA project.
h
+1 for the triple quoted input. Simple and sufficient.
a
Are you guys using Kotlin 1.2? I'm still trying to fix the issue with reading my resource files and gone back to a project which uses it & worked in 1.1 but no longer works in 1.2. Very puzzled
k
I'll try it, one minute.
@stkent's line just works for me on a fresh IDEA 2017.3 Kotlin/JVM project.
a
I'll try a new project & see if that works. Very confused as I have been using that method to read files from the classpath for ages
That even fails in a new project. Get the same error which indicates that the resource can't be found. Exception in thread "main" java.lang.IllegalStateException: Main::class.java.getResource("input.txt") must not be null Too late to investiage further, will retry tomorrow
k
Yikes, good luck anayway!