https://kotlinlang.org logo
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
  • j

    Joris PZ

    12/01/2018, 6:59 AM
    And we're off! Are there any specific rules in this channel about spoilers? My solutions and performance measurements can be found at https://github.com/jorispz/aoc-2018, and I'll be posting the performance results in a thread from this message for those who are interested
    a
    s
    +4
    • 7
    • 37
  • k

    keturn

    12/02/2018, 7:57 AM
    okay, finished day 2 part 2, my partTwo function takes around 70 ms
    j
    • 2
    • 1
  • j

    Joris PZ

    12/02/2018, 8:49 AM
    Shall we make a thread for discussing
    Day 2 - Inventory Management System
    ?
    k
    g
    +4
    • 7
    • 33
  • t

    todd.ginsberg

    12/02/2018, 3:10 PM
    OK, here's mine. Quite a bit different (probably a lot slower): https://github.com/tginsberg/advent-2018-kotlin/blob/master/src/main/kotlin/com/ginsberg/advent2018/Day02.kt
    k
    w
    • 3
    • 6
  • t

    todd.ginsberg

    12/02/2018, 4:53 PM
    I usually just run them from tests so my times are weird. If I don't do that I get 16/47
    w
    • 2
    • 4
  • k

    keturn

    12/03/2018, 6:09 AM
    No Matter How You Slice It — Day 3, Part 1
    t
    j
    w
    • 4
    • 14
  • k

    karelpeeters

    12/03/2018, 9:39 AM
    Hmm this makes me wonder: does
    groupingBy
    have any use cases other than
    eachCount
    ?
    r
    t
    +2
    • 5
    • 20
  • k

    karelpeeters

    12/03/2018, 9:42 AM
    @robin And I think you can replace
    claims.map { it.cells }.reduce { ... }
    with
    claims.flatMap { }
    .
    r
    • 2
    • 13
  • l

    littlelightcz

    12/03/2018, 7:02 PM
    Finally at the 2nd try 😁
    Day_3__part_A.kt
    r
    k
    t
    • 4
    • 23
  • k

    karelpeeters

    12/03/2018, 7:04 PM
    What is this
    @Regex
    sorcery!?
    r
    l
    • 3
    • 5
  • t

    tipsy

    12/03/2018, 7:45 PM
    in the challenge today i iterated through the claims and their cells twice:
    claims.forEach { claim ->
        for (row in claim.x until claim.x + claim.width) {
            for (col in claim.y until claim.y + claim.height) {
                countArray[row][col] = countArray[row][col] + 1
            }
        }
    }
    
    println("part 1: ${countArray.flatMap { it.asIterable() }.count { it > 1 }}")
    
    claims.forEach { claim ->
        for (row in claim.x until claim.x + claim.width) {
            for (col in claim.y until claim.y + claim.height) {
                if (countArray[row][col] != 1) {
                    return@forEach
                }
            }
        }
        println("part 2: ${claim.id}")
    }
    i don't really want to change the approach, but is there a nicer way of iterating?
    l
    k
    • 3
    • 4
  • d

    devbridie

    12/04/2018, 6:54 AM
    Day four was tough! Here's my solution: https://github.com/devbridie/adventofcode2018/blob/master/src/main/kotlin/com/devbridie/adventofcode2018/solutions/Day4.kt
    • 1
    • 1
  • t

    todd.ginsberg

    12/04/2018, 7:46 AM
    https://github.com/tginsberg/advent-2018-kotlin/blob/master/src/main/kotlin/com/ginsberg/advent2018/Day04.kt
    a
    w
    • 3
    • 3
  • t

    todd.ginsberg

    12/04/2018, 7:02 PM
    Hey, welcome. Can you help me understand a bit more about what you are asking. Are you asking why you would do that or how to do it?
    c
    k
    • 3
    • 23
  • l

    littlelightcz

    12/04/2018, 7:10 PM
    This is my today's attempt, but the web says my answer is wrong. I am pretty confident I should have it right, but I have no idea what is wrong though :-)), so it seems I am stuck for now ...
    -.kt
    j
    t
    +2
    • 5
    • 9
  • o

    orangy

    12/05/2018, 7:37 AM
    Hey, those who are measuring time with native, do you run release bits?
    j
    • 2
    • 2
  • a

    andyb

    12/05/2018, 8:38 AM
    Spoiler Day 5 Solution: https://gitlab.com/abowes/adventofcode2018/blob/master/src/main/kotlin/jfactory/day05/Polymer.kt
    k
    • 2
    • 8
  • t

    todd.ginsberg

    12/05/2018, 1:49 PM
    I'm pretty happy with my solution today. One pass on each polymer string. 🙂 https://github.com/tginsberg/advent-2018-kotlin/blob/master/src/main/kotlin/com/ginsberg/advent2018/Day05.kt
    👍 4
    t
    a
    f
    • 4
    • 3
  • t

    Thomas Legrand

    12/05/2018, 4:42 PM
    Finally came up with a solution, however not really idiomatic (you can tell I come from Python 😉 ) https://github.com/DnzzL/kotlin-advent-2018/blob/master/src/main/kotlin/tech/thomaslegrand/advent2018/Day05.kt
    👍 1
    k
    • 2
    • 2
  • e

    Edgars

    12/05/2018, 8:50 PM
    Part 2 could definitely use some parallelism to speed up destroying the units and what-not, but I can't figure out how to do it. I've never worked with coroutines, and this parallel map function I found and pasted in my code doesn't seem to work, everything still happens sequentially. https://jivimberg.io/blog/2018/05/04/parallel-map-in-kotlin/
    a
    j
    • 3
    • 10
  • k

    kartikpatodi

    12/05/2018, 9:09 PM
    I think we can further reduce the iterations in day 5 part 2 by using the result from part 1 as well as only using the set of alphabets in the polymer instead of going fro A..Z
    a
    • 2
    • 2
  • k

    karelpeeters

    12/05/2018, 11:15 PM
    Use a
    LinkedList
    instead of a
    .toMutableList()
    ArrayList
    .
    s
    h
    p
    • 4
    • 17
  • j

    Joris PZ

    12/06/2018, 4:51 PM
    Today reminded me that I don't care for puzzles involving grids. Ugly datastructures, inefficient loops - bleh. But, this is as good as I can make it: https://github.com/jorispz/aoc-2018/blob/master/src/commonMain/kotlin/P06.kt Performance is quite abysmal (first/best of 25 runs as usual): JVM
    1159/270 ms
    , JS
    3692/3002 ms
    , native
    15513/12944 ms
    w
    • 2
    • 1
  • t

    Thomas Legrand

    12/06/2018, 5:14 PM
    My test pass but not the answer, worst feeling ever 😅 must have a wrong assumption
    j
    • 2
    • 1
  • k

    karelpeeters

    12/06/2018, 8:32 PM
    -.kt
    t
    • 2
    • 15
  • t

    todd.ginsberg

    12/07/2018, 12:24 PM
    My flailing around has yielded a proper solution to the example on step 2, but not for the actual, and I just think maybe I don't get it.
    r
    a
    +3
    • 6
    • 42
  • j

    joelpedraza

    12/07/2018, 1:11 PM
    I’ve been going along in rust this year, but graphs are hard in rust, so I’m considering doing kotlin for day 6.
    a
    g
    • 3
    • 7
  • j

    joelpedraza

    12/07/2018, 1:11 PM
    I think this solution for day 7 part 1 is optimal. SPOILERS INSIDE
    • 1
    • 1
  • l

    littlelightcz

    12/07/2018, 3:02 PM
    Now this one was pretty tough for me. Took me like 4h or more to solve both parts. Good I have vacation until the end of year, so I have time to fiddle with it 😄
    Day_7.kt
    k
    • 2
    • 1
  • t

    todd.ginsberg

    12/07/2018, 5:57 PM
    I still feel like I can get this cleaner. I did try to write one function to do both parts and just change the workers and costing function, but abandoned that because it didn't immediately work, and I'm not convinced I can explain it succinctly when I blog about it later.
    a
    k
    g
    • 4
    • 17
Powered by Linen
Title
t

todd.ginsberg

12/07/2018, 5:57 PM
I still feel like I can get this cleaner. I did try to write one function to do both parts and just change the workers and costing function, but abandoned that because it didn't immediately work, and I'm not convinced I can explain it succinctly when I blog about it later.
a

andyb

12/07/2018, 7:14 PM
Well Done. You should be able to solve Part 1 just by passing a workers = 1 & a cost function which returns zero regardless of the character. You will possibly need to change the return from your function to yield a sequence which returns a Pair containing the character which has been completed and the 'finish' time of the character
Bit confused with the loop in your code as it always seems to take 5 items from the available list. How do you keep track of when the workers have finished?
t

todd.ginsberg

12/07/2018, 7:15 PM
Yeah I tried that and something about the way I schedule work in part 2 didn't work because the order was always different.
Workers finish when their cost gets down to zero.
We are always working at the head of the queue and replacing them with cost-1 items in place.
a

andyb

12/07/2018, 7:18 PM
Ok, so the loop is acting like a 1 second clock?
t

todd.ginsberg

12/07/2018, 7:18 PM
Yes. Probably more work than is really needed, but was easier for me to reason about.
a

andyb

12/07/2018, 7:20 PM
Looking at the way my data acts I don't think that there are ever more than 5 items ready to be processed. This means that there is never an entry waiting for an elf to finish work. If you assume this then the problem is simply a graph algorithm to find the longest path from start to finish.
Probably just as well as I don't think my algorithm would have found the result otherwise 🙂
AoC Day 07 solved using Microsoft Project Manager: https://www.reddit.com/r/adventofcode/comments/a3yaec/2018_day_7_part_2_clearly_what_these_elves_need/
t

todd.ginsberg

12/07/2018, 7:57 PM
Huh. Might go back and re look at part 2 with that graph observation in mind.
k

karelpeeters

12/07/2018, 11:22 PM
For my data the 5th worker never even does any work.
➕ 1
t

todd.ginsberg

12/08/2018, 12:27 AM
Maybe try some personal coaching to see if you can up their performance.
k

karelpeeters

12/08/2018, 12:27 AM
Haha I got that notification and I was really confused until I saw the context.
t

todd.ginsberg

12/08/2018, 12:32 AM
TBH that’s my aim with comments like that. 🙃
g

Gerard Klijs

12/08/2018, 7:23 AM
Lucky I saw this thread, my code was bugged, actually had +1 workers, selved now
In my case only 4 workers are busy most at the same time
👍 2
View count: 5