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

    Nir

    12/02/2020, 3:55 PM
    kinda surprised so many people say the regex was the most natural, anytime a problem is trivially solvable using string split I'd always consider that the easiest solution
    👆 1
    a
    1 reply · 2 participants
  • a

    asad.awadia

    12/02/2020, 4:01 PM
    regex is the git of string manipulation
    j
    n
    +1
    3 replies · 4 participants
  • n

    Nir

    12/02/2020, 4:26 PM
    🤷 prefer the principle of least power. I also prefer to avoid regex for code whose performance I may care about; i guess right now the AOC challenges are very small anyway but it won't stay that way
    j
    t
    3 replies · 3 participants
  • n

    Nir

    12/02/2020, 5:04 PM
    In the python slack, they setup a thread for people to post their solutions (they actually have multiple threads, part1 and part2, and potentially a third thread for people who want to post both together), could have something like that here
    ➕ 1
    p
    m
    2 replies · 3 participants
  • n

    Nir

    12/02/2020, 5:24 PM
    ⚠️ Day 2 Solution Thread - here be spoilers ⚠️
    a
    j
    +2
    25 replies · 5 participants
  • j

    Jérôme Gully

    12/02/2020, 6:22 PM
    Day2 solution here: https://github.com/Nutriz/AdventOfCode2020/blob/master/src/test/kotlin/Day2.kt This year I try to use the Unit Test approach, I never really used it. But it's a lot of code compared to yours solutions 🙃. Solution code after all tests.
    👌 1
    p
    2 replies · 2 participants
  • b

    bjonnh

    12/03/2020, 3:00 AM
    I'm playing with the advent from 2015 ((I never did one before).
    t
    1 reply · 2 participants
  • j

    Jakub Gwóźdź

    12/03/2020, 8:25 AM
    ⚠️ Day 3 Solution Thread - here be spoilers ⚠️
    a
    j
    +6
    96 replies · 9 participants
  • n

    Nir

    12/03/2020, 3:35 PM
    It's not really a matrix of strings, is it?
    a
    a
    +1
    19 replies · 4 participants
  • b

    bjonnh

    12/03/2020, 3:36 PM
    yes
    n
    1 reply · 2 participants
  • a

    adamratzman

    12/04/2020, 4:58 AM
    ⚠️ Day 4 Solution Thread - here be spoilers ⚠️
    b
    j
    +3
    41 replies · 6 participants
  • d

    David Whittaker

    12/04/2020, 5:25 AM
    That was crazy - but gotta love me that
    when
    statement!!
    😂 1
    a
    3 replies · 2 participants
  • d

    David Whittaker

    12/04/2020, 5:32 AM
    I messed up the first part since my logic didn't include the last line (it calc'd on a newline) so I had an off-by-one error. So I just added an arbitrary newline to the file. 😎
    1 reply · 1 participant
  • a

    adamratzman

    12/04/2020, 5:33 AM
    You just have to split the input by \n\n, and split each of those by space or newline
    d
    7 replies · 2 participants
  • a

    adamratzman

    12/04/2020, 5:36 AM
    As well as range checks with chars
    💯 2
    d
    9 replies · 2 participants
  • t

    todd.ginsberg

    12/04/2020, 3:18 PM
    I did mine entirely with regular expressions.
    j
    b
    +1
    12 replies · 4 participants
  • n

    Nir

    12/04/2020, 3:37 PM
    Today's AOC inspired idea for a utility function:
    fun String.popSuffix(suffix: String) = if (endsWith(suffix)) removeSuffix(suffix) else null
    e
    4 replies · 2 participants
  • a

    adamratzman

    12/04/2020, 3:57 PM
    I was also thinking extension function String.isInt
    e
    2 replies · 2 participants
  • n

    Nir

    12/04/2020, 4:29 PM
    They can't really have things like ':' in the string without additional conditional constraints
    e
    2 replies · 2 participants
  • p

    pavi2410

    12/04/2020, 6:05 PM
    Any idea why the output is 1? (The output is definitely not 1; it's 267 or so) Is it an issue with
    *.ws.kts
    files? Any limitations I'm not aware of?
    a
    5 replies · 2 participants
  • e

    Edgars

    12/04/2020, 6:52 PM
    What did you guys do with regards to parsing multiple lines as one passport, what with the blank line?
    a
    n
    +1
    57 replies · 4 participants
  • b

    bjonnh

    12/04/2020, 6:53 PM
    (please try to keep the discussions in the thread to not spoil)
    a
    1 reply · 2 participants
  • a

    adamratzman

    12/04/2020, 7:19 PM
    I wrote a
    List<T>.chunkedBy
    function that some people might find useful
    b
    4 replies · 2 participants
  • a

    adamratzman

    12/04/2020, 7:20 PM
    Example (contains spoilers)
    1 reply · 1 participant
  • a

    adamratzman

    12/05/2020, 4:26 AM
    ⚠️ Day 5 Solution Thread  ⚠️
    k
    d
    +9
    64 replies · 12 participants
  • d

    David Whittaker

    12/05/2020, 5:41 AM
    What in the world do you think this is going to be?
    🤷‍♂️ 2
    a
    k
    3 replies · 3 participants
  • a

    adamratzman

    12/06/2020, 4:51 AM
    ⚠️ Day 6 Solution Thread  ⚠️
    b
    k
    +9
    88 replies · 12 participants
  • b

    bjonnh

    12/06/2020, 4:57 AM
    🕙
    a
    3 replies · 2 participants
  • k

    Kroppeb

    12/06/2020, 5:12 AM
    I accidentally misread part 1 and solved part 2 instead. Which makes part 2 more hillarious
    😂 4
    a
    1 reply · 2 participants
  • k

    Kroppeb

    12/06/2020, 5:20 AM
    I didn't expect there to be another puzzle where we had to split on emptylines agian. I guess I should have made that
    SplitOn{}
    I was thinking about
    a
    b
    +1
    33 replies · 4 participants
Powered by Linen
Title
k

Kroppeb

12/06/2020, 5:20 AM
I didn't expect there to be another puzzle where we had to split on emptylines agian. I guess I should have made that
SplitOn{}
I was thinking about
a

adamratzman

12/06/2020, 5:20 AM
I just used \n\n again 😄
b

bjonnh

12/06/2020, 5:21 AM
I mean that's fast and you don't have to remember what you named your function
k

Kroppeb

12/06/2020, 5:22 AM
Yeah but I get my input as a list of strings
I guess I have a function that returns a string
But using
\n\n
wont work on windows, so idk
b

bjonnh

12/06/2020, 5:23 AM
why do you get your input as a list of strings?
k

Kroppeb

12/06/2020, 5:24 AM
a

adamratzman

12/06/2020, 5:24 AM
\r\n\r\n @Kroppeb
k

Kroppeb

12/06/2020, 5:25 AM
because I have a bunch of functions that parse the inputs
b

bjonnh

12/06/2020, 5:25 AM
I have two helper functions textFile(filename) and linesFile(filename) that give me either the file as a full text, or lines
k

Kroppeb

12/06/2020, 5:25 AM
well my solution is shorter
b

bjonnh

12/06/2020, 5:26 AM
you can probably tell intelliJ or whatever your editor is to use \n for line returns
so when you make the file you get \n
k

Kroppeb

12/06/2020, 5:26 AM
although i use curl to download my input
b

bjonnh

12/06/2020, 5:26 AM
so you should have \n then
k

Kroppeb

12/06/2020, 5:27 AM
Lost about 30 points a year ago because intellij droped the ending whitespace
See i don't want to have to think about line endings
And split on might be useful for other things too
b

bjonnh

12/06/2020, 5:28 AM
sure sure
I'm not a windows person so that's not something I really care about
but I should keep that in mind with windows users sending files around
a

adamratzman

12/06/2020, 5:30 AM
good points
k

Kroppeb

12/06/2020, 5:30 AM
anyway, with reduce and splitOn, i now have a "oneliner" for each day
part 2 uses
*
instead
.e()
converts to a
List<Char>
b

bjonnh

12/06/2020, 5:32 AM
oh I was going to ask
why do you need that?
k

Kroppeb

12/06/2020, 5:32 AM
you can't convert a string to a set
oh
ok, intellij was autocompleting too slow so i thought you couldn't
b

bjonnh

12/06/2020, 5:33 AM
great I'm stealing your sumby
👆 1
never think about that one
j

Jakub Gwóźdź

12/06/2020, 5:52 AM
Go with sequences my friends 🙂
View count: 5