https://kotlinlang.org logo
h

holgerbrandl

12/02/2017, 4:33 PM
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

andyb

12/02/2017, 4:35 PM
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

stkent

12/02/2017, 5:12 PM
I'm using
val input = File(Main::class.java.getResource("input.txt").file).readLines()
if that helps
k

karelpeeters

12/02/2017, 5:12 PM
For these challenges I think it's easier to just paste the input in source:
val input = """ ... """
.
a

andyb

12/02/2017, 8:43 PM
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

holgerbrandl

12/02/2017, 9:10 PM
+1 for the triple quoted input. Simple and sufficient.
a

andyb

12/02/2017, 10:17 PM
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

karelpeeters

12/02/2017, 10:17 PM
I'll try it, one minute.
@stkent's line just works for me on a fresh IDEA 2017.3 Kotlin/JVM project.
a

andyb

12/02/2017, 10:23 PM
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

karelpeeters

12/02/2017, 10:34 PM
Yikes, good luck anayway!
6 Views