My day 3 solution. :big_smile:
Luke Boswell has marked this topic as resolved.
Luke Boswell has marked this topic as unresolved.
Here's my Day 3 . I'm happy with the solution but I found myself wishing Roc had these 3 2 things:
List.chunks
to chunk a list into sub lists of a specified lengthList.reduce
that uses the first element of the list as the initial state Another Day 3 solution. I know there's a way to do some nifty destructuring on the way from lists to function parameters...
Dude, I am learning waayyyyy more than I ever thought possible about basic adding/subtraction against various number types. I thought I was all ballin' when I understood the difference between / and // in Elm, but this U8 vs. U32 insanity is breaking my brain. I didn't realize math with these various number types was so dangerous.
Case in point "List.sum blows up" because U8 maxes at 256... like... man am I spoiled rotten in other languages.
Here's my day 3. I didn't know anything about scalar arithmetic so I went with a much dumber approach :rolling_on_the_floor_laughing:.
I was really surprised that Str.split "abc" ""
returns ["abc"]
and not ["a", "b", "c"]
. I understand the reasoning, but I wish the compiler could blow up if you do Str.split
with an empty separator. I'm not familiar with other languages that have the same behavior as Roc, but plenty (JS, Ruby, Rust) split the string into individual characters.
That's an interesting note on Str.split
. i guess we just have a few other methods that theoretically are for that. Like Str.toUtf8
or one of the methods that walks the code points/graphemes, but yeah...less clear
My solution
ooh I love your recursive grouping strategy @Luke Boswell
my day 3 - definitely looking forward to hash-based set/dict :nerd:
@Ayaz Hafiz the way you formatted that if
was neat. I wonder if we could support that without braces for smaller use cases like this?
(if item >= 'a'
then item - 'a' + 1
else item - 'A' + 27)
|> Num.toU64
I actually want to support Num.toU64 if item >= 'a' then ...
like CoffeeScript does!
it might work without braces or richards way, i just didn’t try it
Oh, I can do 'E' - 'A'
, that is pretty cool
My Day 3 (shrink took wayyy too long)
BTW, I left in all the compiler bugs in separate files in case you're interested in duplication compiler issues.
Last updated: Jul 06 2025 at 12:14 UTC