Preskoči na glavno vsebino

Objave

Prikaz objav, dodanih na december, 2022

Advent of Code 2022 - Day 3 - reduce, fold, add-up

This is the Day 3 puzzle for #AoC2022 with Rye. Rye has reduce and fold functions. The difference is, that reduce doesn't accept initial value, so it can be less verbose in some situations, but you need an initial value many times, like when you are adding things up. Initial solution used fold to sum the priorities up, hence it needed initial zero and also an accumulator word (priority, priority1). You don't need to define a word for current value as usually with reduce/fold, because it's injected into code block.     I don't particularly like fold name, because it sounds like CS (computer science) "speak", not something that a person would intuitively name this functionality.  I'm not sure I will find any better name thou, but I thought today it would make sense to make a specialized function for summing/joining things up. That way I can get rid of the initial value (it can be inferred from the type of first returned value) and the accumulator word as

Advent of Code 2022 - Day 1 & 2 with Rye

Yesterday @pkese and @otobrglez from Twitter made me aware of the Advent of Code 2022 . Oto made his solution in Scala and ZIO and Peter used F#. Both looked cool. I had very little time last two weeks, so almost none for Rye. I was planning for a blogpost about failure handling next.  Well today I couldn't help myself and made a solution for Day 1: "Calorie Counting":     It's really fun, try for yourself: https:// adventofcode.com/2022/day/1   If you just want to watch and compare the languages, there is this reddit megathread for Day 1. I also added my Rye solution :). Update I also solved Day 2. challenge "Rock Paper Scissors". I added two functions to Rye: reverse! and read\lines, others were already there. Star an follow Rye/me on Github .