digitalmars.D - Advent of Code 2019
- mipri (64/64) Nov 22 2019 Hello all,
- Sergei Nosov (12/19) Nov 25 2019 I've only made it halfway through last year.
- Uknown (4/17) Nov 25 2019 Use `std.string.representation` to bypass autodecoding. It just
- Sergei Nosov (5/9) Nov 25 2019 Yeah, that's what I did.
- Steven Schveighoffer (5/30) Nov 25 2019 https://dlang.org/phobos/std_ascii.html#toLower
- Sergei Nosov (7/11) Nov 26 2019 Thanks!
- Steven Schveighoffer (10/24) Nov 26 2019 Yeah, byCodeUnit basically tells Phobos to ignore autodecoding, and
- mipri (9/15) Dec 01 2019 This year might have a space theme.
- Ben Jones (3/19) Dec 03 2019 Mine here:
- Johannes Loher (5/24) Dec 04 2019 Here is mine: https://github.com/ghost91-/aoc2019
- Paul Backus (3/19) Dec 04 2019 I'm a little behind, but my solutions so far are here:
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.
Nov 22 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/aboutI'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)
Nov 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: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`.[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)
Nov 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.
Nov 25 2019
On 11/25/19 6:32 AM, Sergei Nosov wrote:On Saturday, 23 November 2019 at 04:38:14 UTC, mipri 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 -SteveHello 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/aboutI'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)
Nov 25 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 -SteveThanks! 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`).
Nov 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: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. -Stevehttps://dlang.org/phobos/std_ascii.html#toLower https://dlang.org/phobos/std_ascii.html#toUpper https://dlang.org/phobos/std_utf.html#byCodeUnitThanks! 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`).
Nov 26 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/aboutThis 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.
Dec 01 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:Mine here: https://github.com/benjones/adventOfCode2019.gitThere'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/aboutThis 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.
Dec 03 2019
Am 02.12.19 um 03:10 schrieb mipri:On Saturday, 23 November 2019 at 04:38:14 UTC, mipri wrote: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.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/aboutThis 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.
Dec 04 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:I'm a little behind, but my solutions so far are here: https://github.com/pbackus/advent19There'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/aboutThis 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.
Dec 04 2019