https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
advent-of-code
  • a

    adamratzman

    12/06/2020, 5:32 AM
    Please tell me there isn’t a String.toList
    b
    k
    i
    • 4
    • 10
  • m

    Michael de Kaste

    12/06/2020, 10:31 AM
    I posted this in the solution thread, but since it's actually a question, I'll post it here too ⚠️ SPOILERS ⚠️
    • 1
    • 2
  • j

    Joris PZ

    12/06/2020, 12:20 PM
    For the last three years I have used Kotlin MPP to do AoC. One thing that always slightly bothered me was that, because there is no common File api, I had to resort to putting the input directly in the source code. Today I finally took some time to attempt to read my input from a file instead. My needs are simple: I want to put a file with inputs in a shared resources directory, say
    src\commonMain\resources\day01.txt
    and read its contents as text in my solutions. This isn't trivial in Kotlin multi-platform, as a.) there isn't a common file API, and b.) only the JVM provides standardized access to the resources directory. To deal with this platform-dependent stuff, Kotlin MPP offers the `expect`/`actual` mechanism. In common code, I declare that each target platform (JVM, Node and native) should offer a
    readInput
    function:
    expect fun readInput(name: String): String
    The, each platform can implement this in a platform-specific way: JVM:
    actual fun readInput(name: String) = {}::class.java.getResource(name).readText()
    Since Node and native don't get access to the resources directory, I use an enviroment variable
    AOC_INPUT_DIR
    to define the directory where they should look for the input files. Their implementations then become: Node:
    external fun require(name: String): dynamic
    val fs = require("fs")
    val path = require("path")
    
    actual fun readInput(name: String): String {
        val path = path.join(process.env.AOC_INPUT_DIR, name)
        return fs.readFileSync(path, "utf8") as String
    }
    Native:
    actual fun readInput(name: String): String {
        val returnBuffer = StringBuilder()
        val inputDir = getenv("AOC_INPUT_DIR")?.toKString() ?: ""
        val file = fopen("""$inputDir\$name""", "r") ?: throw IllegalArgumentException("Cannot open input file $name")
    
        try {
            memScoped {
                val readBufferLength = 64 * 1024
                val buffer = allocArray<ByteVar>(readBufferLength)
                var line = fgets(buffer, readBufferLength, file)?.toKString()
                while (line != null) {
                    returnBuffer.append(line)
                    line = fgets(buffer, readBufferLength, file)?.toKString()
                }
            }
        } finally {
            fclose(file)
        }
    
        return returnBuffer.toString()
    }
    I'm not sure I'm actually going to use this, I don't really mind having the input in the source, but at least I know how to do it now 🙂
    👏🏻 2
    e
    t
    b
    • 4
    • 7
  • a

    adamratzman

    12/07/2020, 2:54 AM
    ⚠️ Day 7 Solution Thread  ⚠️
    b
    k
    +9
    • 12
    • 40
  • k

    Kroppeb

    12/07/2020, 5:25 AM
    It says my answer for part 1 is wrong but I just don't see my mistake
    a
    • 2
    • 7
  • d

    Draget

    12/07/2020, 6:30 AM
    I have been discussing with a friend and I wonder what your views are: He uses extension-functions more often than me. E.g. on Day03 (Slopes/Trees), he used an extension function on 'String' to check a coordinate (including the 'wrapping') if it is a tree or not. I used a regular function. On Day01 we both used extension-functions e.g. on Pair to to define a .sum(). So when is it a good idea to use extension functions and when not?
    a
    e
    +3
    • 6
    • 14
  • n

    Nir

    12/07/2020, 3:52 PM
    Mild spoilers in thread; mutable vs functional style for a non-trivial data transformation, curious to see which people think is more readable
    j
    • 2
    • 5
  • m

    mickeelm

    12/07/2020, 6:52 PM
    [not really a spoiler, but not fun until you're on day 7 either]
    j
    b
    • 3
    • 9
  • b

    bjonnh

    12/07/2020, 9:18 PM
    Spoil alert in that thread. (graphical depiction of part of the data structure)
    n
    e
    m
    • 4
    • 51
  • a

    adamratzman

    12/08/2020, 4:41 AM
    ⚠️ Day 8 Solution Thread  ⚠️
    d
    n
    +6
    • 9
    • 124
  • b

    bjonnh

    12/08/2020, 5:10 AM
    I'll do that tomorrow I was writting a travelling salesman for day 9 of 2015…
    😄 1
    • 1
    • 1
  • d

    David Whittaker

    12/08/2020, 5:18 AM
    I saw the input for today before I read the problem and I went OH NO! Not IntCode again!! And then I saw it was a lot simpler. (for now)
    😂 4
    b
    • 2
    • 1
  • n

    Nir

    12/08/2020, 5:41 AM
    For a moment I didn't comprehend that the you can only change the kind of instruction, not the argument. I thought you could change both
    a
    b
    • 3
    • 3
  • n

    Nir

    12/08/2020, 5:41 AM
    and i was just like wtf, how on earth would you do that
    😂 1
    j
    • 2
    • 2
  • n

    Nir

    12/08/2020, 3:08 PM
    For those curious, a better algorithmic solution for day 8 part b, way too lazy to implement, see thread
    • 1
    • 5
  • a

    asad.awadia

    12/08/2020, 5:30 PM
    graph based maybe?
    e
    b
    • 3
    • 2
  • a

    asad.awadia

    12/08/2020, 7:38 PM
    Question for the channel: Do you time-box the question before calling it quits? or do you spend as much time as needed to get to the answer? specially around the latter more difficult questions
    b
    e
    n
    • 4
    • 8
  • n

    Nir

    12/08/2020, 8:01 PM
    semi related, for those who want to see an O(N) solution for part b), see thread
    b
    • 2
    • 16
  • j

    Jérôme Gully

    12/08/2020, 9:07 PM
    Hi, I'm in Day7 part 1. I have the right algo for the example input, but not with the real input, I didn't see how to investigate that, other people having the same issue ? What I have missed ?
    b
    a
    • 3
    • 40
  • a

    adamratzman

    12/09/2020, 4:38 AM
    ⚠️ Day 9 Solution Thread  ⚠️
    d
    p
    +10
    • 13
    • 70
  • a

    asad.awadia

    12/09/2020, 4:40 PM
    Do you get a star for solving after 24hrs?
    e
    b
    a
    • 4
    • 4
  • b

    bjonnh

    12/10/2020, 3:54 AM
    ‼️*Day 10 Solution Thread* ⁉️
    a
    a
    +9
    • 12
    • 63
  • a

    adamratzman

    12/10/2020, 5:32 AM
    ok that was… wow (spoilers)
    • 1
    • 2
  • b

    bjonnh

    12/11/2020, 12:06 AM
    Conway would have liked it
    d
    • 2
    • 4
  • b

    bjonnh

    12/11/2020, 4:48 AM
    ❕Day 11 Solution Thread❣️
    d
    e
    +3
    • 6
    • 13
  • n

    Nir

    12/11/2020, 5:21 AM
    Man people are fast. This si the only day I'v emade a half legitimate attempt at starting right at midnight
    d
    a
    • 3
    • 2
  • e

    Edgars

    12/11/2020, 8:44 AM
    Took me about 15-20 minutes all in all, but the solution is not efficient at all, 700ms for the whole thing.
    e
    j
    +2
    • 5
    • 14
  • d

    Draget

    12/11/2020, 2:25 PM
    Hey everyone. I have not yet solved Day7 yet. I want to bang my head against it for a little longer before I look up other solutions. But so far I am building Regex, nested with Regex, which match stuff split with more Regex… and so on. xD At the end, I am building BagRule objects that I can then traverse and check. But I belive there must be a more elegant way to parse the string into one of the objects I defined. Like specifying a grammar in a more elegant form than just Regex. With named elements that are easier to put into an object. Is there some library or something you could suggest? Other than that, I could express everything in one Regex. But the matching groups would be nested, I have no idea how to work with that. My mind was already blown 2-3 days before Day 7 when I found
    destructed
    😛
    j
    • 2
    • 8
  • a

    adamratzman

    12/12/2020, 5:54 AM
    Day 12 solution thread
    a
    e
    +5
    • 8
    • 25
  • k

    kartikpatodi

    12/12/2020, 10:41 AM
    Is there a way to retrieve input files directly from cURL or from openConnection ? I want to try previous years AOC and copying the input is kind of tedious. 😅 Just curious!
    a
    j
    e
    • 4
    • 9
Powered by Linen
Title
k

kartikpatodi

12/12/2020, 10:41 AM
Is there a way to retrieve input files directly from cURL or from openConnection ? I want to try previous years AOC and copying the input is kind of tedious. 😅 Just curious!
a

andyb

12/12/2020, 10:44 AM
You need to be authenticated to get your specific input so that could make it difficult
k

kartikpatodi

12/12/2020, 10:47 AM
is there a way to use the browser's cookie or session data?
j

Jakub Gwóźdź

12/12/2020, 11:55 AM
sure
cookie string like
session=53616c74.....
🥇 1
👍🏻 3
(this is JVM but you'll get the idea how to make it in curl. header is named
Cookie
)
e

ephemient

12/12/2020, 12:37 PM
this is what I do: https://github.com/ephemient/aoc2020/blob/main/Makefile
😮 1
(only works on linux, not macos) assuming cookie value is in ~/.aocrc file or SESSION=,
make
downloads all available inputs for the given YEAR=. skips any inputs that already exist or future inputs
if you explicitly ask for
make day25.txt
it'll wait until then
k

kartikpatodi

12/12/2020, 12:55 PM
Nice @ephemient. But I have a Mac. Also @Jakub Gwóźdź answer works fine.
View count: 8