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
  • e

    Edgars

    12/09/2019, 2:05 PM
    I'm thinking about making
    IntCode<T : Number>
    . Need to refactor it for Day 7 anyway.
    b
    k
    • 3
    • 3
  • t

    todd.ginsberg

    12/09/2019, 2:14 PM
    Now with Long support!
    😎 1
    e
    • 2
    • 2
  • t

    todd.ginsberg

    12/09/2019, 5:31 PM
    Turns out I think my Mark 1 computer was calculating write positions wrong this whole time.
    b
    • 2
    • 2
  • t

    todd.ginsberg

    12/09/2019, 11:44 PM
    OK, solve and wrote day 9. I ended up implementing a new computer that's much simpler than the old one I had.
    • 1
    • 3
  • t

    todd.ginsberg

    12/10/2019, 12:42 AM
    Just got called out publicly on twitter for including the puzzle text on my blog. They don't like that. Bah
    😞 1
    s
    • 2
    • 3
  • k

    Kroppeb

    12/10/2019, 10:07 AM
    While converting my IntComputer to use coroutines. I finally located the bug
    j
    • 2
    • 2
  • c

    Christoph Baudson

    12/10/2019, 11:48 AM
    My solution for day 10 https://github.com/sustainablepace/Advent-of-Code-2019/blob/master/src/main/kotlin/advent_of_code/Day10.kt :kotlin-flag:
    j
    • 2
    • 2
  • t

    todd.ginsberg

    12/10/2019, 6:03 PM
    I'll post my code later (after work, when I can clean it up) but I'm pretty happy with it. I found a nice way to turn a
    Collection<List<T>>
    into a
    List<T>
    by doing round-robin (so,
    [ [A, D], [B, E], [C] ]
    becomes
    [A, B, C, D, E]
    ) and used that for part 2.
    😉 1
    c
    • 2
    • 1
  • r

    Rostyslav

    12/10/2019, 6:39 PM
    My solution for Day 10. Still needs some polishing but works well 🙂 https://github.com/Rtchaik/AoC2019/blob/master/src/advent2019/day10/solution10.kt
    👍 2
    c
    t
    • 3
    • 4
  • t

    todd.ginsberg

    12/10/2019, 11:43 PM
    Day 10. I'm pretty happy with how this turned out.
    s
    j
    • 3
    • 6
  • t

    todd.ginsberg

    12/11/2019, 2:30 PM
    I've solved it, but man is it ugly.
    😂 1
    r
    s
    +2
    • 5
    • 7
  • j

    Joris PZ

    12/11/2019, 6:50 PM
    I'm reasonably happy with my solution, took me a while to figure out why my letters were upside down. In my coordinate system positive Y is upwards, which is the reverse of what the IntCode computer uses. Also, I need to find a more elegant way than closing stdout to signal end of execution, the try-catch is an eyesore. Code is https://github.com/jorispz/aoc-2019/blob/master/src/commonMain/kotlin/day11/p11.kt
    m
    t
    k
    • 4
    • 7
  • t

    todd.ginsberg

    12/11/2019, 8:21 PM
    [Day 11]
    s
    • 2
    • 6
  • e

    Evan R.

    12/11/2019, 8:55 PM
    So my solution came from the realization that if two asteroids supposedly visible from your origin asteroid occluded each other, the coordinate difference from the origin to these asteroids would just be a multiple of the other. For instance, if you have an asteroid 1 spot down and 2 spots over from the origin, it will occlude a point at 3 spots down and 6 spots over (because 1 * 3 = 3 and 2 * 3 = 6). Given this realization, you can effectively reduce all the differences in coordinates down to the smallest “multiple” or in linear algebra terms effectively an identity vector. You take the greatest common factor of the coordinate difference, then divide the x and y value of the difference by the GCF to get your “identity vector”. At that point all you need to do is come up with the distinct set of identity vectors!
    k
    s
    d
    • 4
    • 12
  • m

    marstran

    12/12/2019, 2:42 PM
    Today’s part 2 is really hard. Anyone here managed to solve it yet? 🙂
    k
    • 2
    • 2
  • t

    todd.ginsberg

    12/12/2019, 4:40 PM
    I’ll admit going to reddit for hints on part 2. I’ve written a solution but I want to think about it some more because I’m not sure I’m happy with it.
    👍 1
    k
    • 2
    • 3
  • e

    Edgars

    12/12/2019, 6:04 PM
    Could I get some coroutine help, please? (sort of spoilers for part 2?)
    k
    m
    • 3
    • 8
  • j

    Joris PZ

    12/12/2019, 9:28 PM
    Here's mine: https://github.com/jorispz/aoc-2019/blob/master/src/commonMain/kotlin/day12/p12.kt Needed a small nudge for part 2. It was obvious we needed to look for cycles (the hints in the text were strong, and we have a few of these every year unfortunately), but it didn't occur to me to look the dimensions independently. The code is OK but nothing special.
    👍 2
    t
    • 2
    • 2
  • t

    todd.ginsberg

    12/13/2019, 12:13 AM
    Here's mine for the day. Kinda not great, but my head is killing me so I'm going to lie down. https://todd.ginsberg.com/post/advent-of-code/2019/day12/
    j
    • 2
    • 1
  • j

    Jakub Gwóźdź

    12/13/2019, 11:28 AM
    Ok so I did the game, https://github.com/jakubgwozdz/AdventOfCode/blob/master/src/advent2019/day13/Day13.kt and it works, but I still have this feeling that I don't really understand channels in coroutines. main problem is that I wanted to create the lazy producer (ReceiveChannel) that is called a) only when it's
    .receive()
    is explicitly called and b) only after another channel (output from the Intcode) has been completely processed. I failed to do it, so instead I created a wrapper that does something like
    override suspend fun receive(): BigInteger {
        while (!output.isEmpty) {
            val x = output.receive()
            // ... process x
        }
        return something
    }
    But I think I'm missing some point here and it could be more elegant
    j
    k
    • 3
    • 5
  • e

    Edgars

    12/13/2019, 2:06 PM
    https://github.com/edgars-supe/advent-of-code/blob/master/src/main/kotlin/lv/esupe/aoc/year2019/Day13.kt That was fun.
    j
    • 2
    • 2
  • j

    Joris PZ

    12/13/2019, 2:13 PM
    My Day13, my coroutine/Channel IntCode implementation is holding up fairly well, though it requires a bit too much boilerplate right now to setup the channels etc. https://github.com/jorispz/aoc-2019/blob/master/src/commonMain/kotlin/day13/p13.kt I have somewhat lost interest in doing the performance measurements for JS and native, I'll do them at some point and update the README in Github then.
    t
    k
    • 3
    • 8
  • c

    Christoph Baudson

    12/13/2019, 5:31 PM
    Does anyone here have an implementation for day 13 with graphical output? I was wondering how this could be done on the command line...
    j
    • 2
    • 1
  • t

    todd.ginsberg

    12/13/2019, 10:42 PM
    Day 13
    e
    • 2
    • 8
  • r

    Rostyslav

    12/14/2019, 12:08 PM
    My Day14: https://github.com/Rtchaik/AoC2019/blob/master/src/advent2019/day14/solution14.kt
    👍 2
    t
    • 2
    • 1
  • k

    karelpeeters

    12/14/2019, 6:16 PM
    Hey! I'm back after a while of having too much work and then being sick, so I have some catching up to do as well 🙂 Both of todays parts were begging to be solved with integer linear programming, but I managed to ignore that and bruteforce my way trough everything instead:
    e
    • 2
    • 4
  • k

    Kroppeb

    12/15/2019, 6:26 AM
    I got 27/8 today. Very happy about it.
    👍 4
    r
    • 2
    • 2
  • r

    Rostyslav

    12/15/2019, 12:05 PM
    My solution for Day15: https://github.com/Rtchaik/AoC2019/blob/master/src/advent2019/day15/solution15.kt
    😮 2
    j
    • 2
    • 1
  • r

    Rostyslav

    12/16/2019, 11:55 AM
    Day16: https://github.com/Rtchaik/AoC2019/blob/master/src/advent2019/day16/solution16.kt
    👏 1
    j
    • 2
    • 3
  • k

    Kroppeb

    12/17/2019, 5:41 AM
    Lost quite some time today in part 1
    r
    e
    +2
    • 5
    • 7
Powered by Linen
Title
k

Kroppeb

12/17/2019, 5:41 AM
Lost quite some time today in part 1
How did you guys convert the output to a grid? I noticed lists don't have a
split()
so I decided to convert to an actual string which took quite some time to get right.
output.toList().joinToString(separator = "") { it.toChar().toString() }.split("\n").map{it.map{it}}
r

Rostyslav

12/17/2019, 7:30 AM
output.map { it.toChar()}.joinToString("").split("\n").map { it.toList() }
👍 1
e

Edgars

12/17/2019, 9:04 AM
I have it like this: https://github.com/edgars-supe/advent-of-code/blob/master/src/main/kotlin/lv/esupe/aoc/year2019/Day17.kt#L36-L45
j

Joris PZ

12/17/2019, 12:19 PM
Same, just used
.lines()
instead of .
split("\n")
:
.map { it.toChar() }.toList().joinToString("").lines()
k

Kroppeb

12/17/2019, 12:23 PM
I knew there was such a function, just forgot the name. I though it was
splitLines
or something
j

Jakub Gwóźdź

12/17/2019, 2:56 PM
my Intcode works on
Channel
s for I/O, so I added a
Flow
for it and transform it like this:
@Suppress("BlockingMethodInNonBlockingContext")
private fun Flow<Char>.fullLines(): Flow<String> = flow {
    val builder = StringBuilder()
    collect {
        when (it) {
            '\n' -> emit(builder.toString()).also { builder.clear() }
            else -> builder.append(it)
        }
    }
}
this approach has some flaws (e.g. just forgets last line without any
\n
at the end) but is good enough for day17 🙂
j

Joris PZ

12/17/2019, 3:46 PM
I also have a coroutine-based Intcode computer with Channels, for part 2 I turned my output Channel into a teletype by launching this:
launch {
   while (!stdout.isClosedForReceive) {
      stdout.receive().also { print(if (it < 255) it.toChar() else "Part 2: $it") }
   }
}
View count: 2