Jump to page: 1 2
Thread overview
Advent of Code 2019
Nov 23, 2019
mipri
Nov 25, 2019
Sergei Nosov
Nov 25, 2019
Uknown
Nov 25, 2019
Sergei Nosov
Nov 26, 2019
Sergei Nosov
Dec 02, 2019
mipri
Dec 03, 2019
Ben Jones
Dec 04, 2019
Johannes Loher
Dec 05, 2019
Paul Backus
November 23, 2019
Hello all,

There's one more week in November, and then Advent of Code'll
start again with Christmas-themed programming puzzles, one
released every midnight US/Eastern, with a second part to each
puzzle unlocked after you complete the first part. You can read
more about it at the website: https://adventofcode.com/2019/about

It's not that serious (when I recommended it last year, to
another community, I was asked if there's a monetary
prize--there isn't one), but it's fun, and it results in lots of
code that's a lot more interesting to compare across languages
and attempts than much else out there. It's not like benchmarks
where the results matter too much to people who have too much
time to put into their work. With Advent of Code you want to
get the answers quickly and, when harder problems can take hours
to complete, people want to go to sleep or get back to other
affairs before the next day's puzzle unlocks. So you get a lot
of relatively honest code, and you can easily talk about the
entries, with everyone still understanding that there's a time
crunch and therefore an amount of sloppiness to be found.

My favorite part of the contest is the two-part format to the
puzzles. You can often cheat a fast solution to the first part,
and then be forced to drastically change your code (or actually
write code this time around) to complete the second part. Which
can mean, again wildly contrary to benchmarks, that you write
code that's a bit generalized or a bit flexible, as you
anticipate the (as yet unknown) hurdle that will come with the
second part of the puzzle.

As a language D has some advantages for this contest:

1. it has some of the 'whipituppitude' characteristic of
scripting languages. You can craft a solution and try it out
relatively quickly with relatively little boilerplate. If the
problem is literally "add up these numbers", you might rdmd
--eval the solution rather than open an editor at all.

2. it can also be very efficient. The puzzle part-twos can be
"take that loop that completed in 100 iterations and change it
so it takes 100 million iterations.", so if you follow the contest
at https://www.reddit.com/r/adventofcode/ or similar places you
might see the occasional lament about some Python performance,
or how much memory some Haskell is needing.

3. it also makes it very convenient to take measures to write
correct code, with contract programming, std.exception.enforce,
and unittest blocks. The puzzles can also be difficult to
understand, and it's often very easy to be foiled by a
microscopic failure to adhere to the spec -- and again, there is
a time crunch.

Incidentally, an advantage D doesn't have for this contest is
that it's not a language that you interact with inside of a
persistent workspace. Which means: if you perform some expensive
computation, and finally get an answer to part 1, and then
discover that part 2 is "what would've been the answer if you'd
stopped *right before* the last step of that computation?" then
in D you'll typically get to run that expensive computation all
over again and you'll lose time.  There aren't many languages
like this though.

I hope I'll see some more D this year. I may be posting mine to
the thread (if there is one) or to the learn forum, since I'm
still learning D myself and hope to use the contest to get a lot
more comfortable with the language.

If anyone does want to get really serious about the contest, you
can get on a streaming platform to review and complete the
puzzles with an audience. People really do this. I haven't
followed any of them, but I've been aware that some of the names
on the public leaderboard are streamers.

Cheers.
November 25, 2019
On Saturday, 23 November 2019 at 04:38:14 UTC, mipri wrote:
> Hello all,
>
> There's one more week in November, and then Advent of Code'll
> start again with Christmas-themed programming puzzles, one
> released every midnight US/Eastern, with a second part to each
> puzzle unlocked after you complete the first part. You can read
> more about it at the website: https://adventofcode.com/2019/about

I've only made it halfway through last year.

One of the unexpected difficulties for me was, actually, working with strings. The problems involve only ASCII characters, so you don't care about the UTF stuff at all. Yet, D always tries to be cautious of it and you have to workaround it all the time which leads to ugly-looking hacks, like https://github.com/snosov1/adventofcode.com/blob/master/2018/day05/day05_2.d

What would be a recommended way to handle such cases? (i.e. when you know for sure that your characters are always 8-bit, so it's safe to call `sort`, `toUpper` and all the other std functions without ever trying to decode)


November 25, 2019
On Monday, 25 November 2019 at 11:32:38 UTC, Sergei Nosov wrote:
> On Saturday, 23 November 2019 at 04:38:14 UTC, mipri wrote:
>> [snip]
> I've only made it halfway through last year.
>
> One of the unexpected difficulties for me was, actually, working with strings. The problems involve only ASCII characters, so you don't care about the UTF stuff at all. Yet, D always tries to be cautious of it and you have to workaround it all the time which leads to ugly-looking hacks, like https://github.com/snosov1/adventofcode.com/blob/master/2018/day05/day05_2.d
>
> What would be a recommended way to handle such cases? (i.e. when you know for sure that your characters are always 8-bit, so it's safe to call `sort`, `toUpper` and all the other std functions without ever trying to decode)

Use `std.string.representation` to bypass autodecoding. It just casts the string to `ubyte[]` which is what you need most of the time. Then case back to string as necessary with `assumeUTF`.
November 25, 2019
On Monday, 25 November 2019 at 11:51:41 UTC, Uknown wrote:
> Use `std.string.representation` to bypass autodecoding. It just casts the string to `ubyte[]` which is what you need most of the time. Then case back to string as necessary with `assumeUTF`.

Yeah, that's what I did.

But then I needed to create overloads for functions, like, toUpper, because `ubyte` doesn't implicitly convert to `dchar`. It's not a big deal, but it's kinda messy.
November 25, 2019
On 11/25/19 6:32 AM, Sergei Nosov wrote:
> On Saturday, 23 November 2019 at 04:38:14 UTC, mipri wrote:
>> Hello all,
>>
>> There's one more week in November, and then Advent of Code'll
>> start again with Christmas-themed programming puzzles, one
>> released every midnight US/Eastern, with a second part to each
>> puzzle unlocked after you complete the first part. You can read
>> more about it at the website: https://adventofcode.com/2019/about
> 
> I've only made it halfway through last year.
> 
> One of the unexpected difficulties for me was, actually, working with strings. The problems involve only ASCII characters, so you don't care about the UTF stuff at all. Yet, D always tries to be cautious of it and you have to workaround it all the time which leads to ugly-looking hacks, like https://github.com/snosov1/adventofcode.com/blob/master/2018/day05/day05_2.d 
> 
> 
> What would be a recommended way to handle such cases? (i.e. when you know for sure that your characters are always 8-bit, so it's safe to call `sort`, `toUpper` and all the other std functions without ever trying to decode)
> 
> 

https://dlang.org/phobos/std_ascii.html#toLower
https://dlang.org/phobos/std_ascii.html#toUpper
https://dlang.org/phobos/std_utf.html#byCodeUnit

-Steve
November 26, 2019
On Monday, 25 November 2019 at 15:30:47 UTC, Steven Schveighoffer wrote:
>
> https://dlang.org/phobos/std_ascii.html#toLower
> https://dlang.org/phobos/std_ascii.html#toUpper
> https://dlang.org/phobos/std_utf.html#byCodeUnit
>
> -Steve

Thanks!

byCodeUnit seems to be the working out alright.

I believe, I've tried `byChar` previously and couldn't make it work (because I was under misconception that it has the semantics of `byCodeUnit`).
November 26, 2019
On 11/26/19 7:00 AM, Sergei Nosov wrote:
> On Monday, 25 November 2019 at 15:30:47 UTC, Steven Schveighoffer wrote:
>>
>> https://dlang.org/phobos/std_ascii.html#toLower
>> https://dlang.org/phobos/std_ascii.html#toUpper
>> https://dlang.org/phobos/std_utf.html#byCodeUnit
>>
> 
> Thanks!
> 
> byCodeUnit seems to be the working out alright.
> 
> I believe, I've tried `byChar` previously and couldn't make it work (because I was under misconception that it has the semantics of `byCodeUnit`).

Yeah, byCodeUnit basically tells Phobos to ignore autodecoding, and treats it like the array that it is for the purposes of algorithms and ranges. It should provide all the same underlying mechanisms that the array provides, including random access, at least that's the purpose.

byChar I think is a conversion routine, meant to be used to shoehorn e.g. a wchar[] or dchar[] into a utf8 range. In fact, byChar returns byCodeUnit if the types are equal (or at least it should). If it wasn't working but byCodeUnit is, please file an issue.

-Steve
December 02, 2019
On Saturday, 23 November 2019 at 04:38:14 UTC, mipri wrote:
> There's one more week in November, and then Advent of Code'll
> start again with Christmas-themed programming puzzles, one
> released every midnight US/Eastern, with a second part to each
> puzzle unlocked after you complete the first part. You can read
> more about it at the website: https://adventofcode.com/2019/about
>

This year might have a space theme.

Is anyone doing this? I'm only aware of these repos so far:

https://github.com/hakanaras/aoc_2019
https://github.com/jrfondren/adventofcode
https://github.com/Krid3l/aoc2019

If you're doing it, why not reply with your repo? D's a
flexible language so there are a lot of differences to
find already.
December 03, 2019
On Monday, 2 December 2019 at 02:10:16 UTC, mipri wrote:
> On Saturday, 23 November 2019 at 04:38:14 UTC, mipri wrote:
>> There's one more week in November, and then Advent of Code'll
>> start again with Christmas-themed programming puzzles, one
>> released every midnight US/Eastern, with a second part to each
>> puzzle unlocked after you complete the first part. You can read
>> more about it at the website: https://adventofcode.com/2019/about
>>
>
> This year might have a space theme.
>
> Is anyone doing this? I'm only aware of these repos so far:
>
> https://github.com/hakanaras/aoc_2019
> https://github.com/jrfondren/adventofcode
> https://github.com/Krid3l/aoc2019
>
> If you're doing it, why not reply with your repo? D's a
> flexible language so there are a lot of differences to
> find already.

Mine here:
https://github.com/benjones/adventOfCode2019.git
December 05, 2019
Am 02.12.19 um 03:10 schrieb mipri:
> On Saturday, 23 November 2019 at 04:38:14 UTC, mipri wrote:
>> There's one more week in November, and then Advent of Code'll start again with Christmas-themed programming puzzles, one released every midnight US/Eastern, with a second part to each puzzle unlocked after you complete the first part. You can read more about it at the website: https://adventofcode.com/2019/about
>>
> 
> This year might have a space theme.
> 
> Is anyone doing this? I'm only aware of these repos so far:
> 
> https://github.com/hakanaras/aoc_2019 https://github.com/jrfondren/adventofcode https://github.com/Krid3l/aoc2019
> 
> If you're doing it, why not reply with your repo? D's a
> flexible language so there are a lot of differences to
> find already.

Here is mine: https://github.com/ghost91-/aoc2019

I just completed day 4 and after doing that, I had a quick look at the other repos. hakanaras has a particularly beautiful solution for day 4, I learned about a few additional library functions from it.
« First   ‹ Prev
1 2