Live data from Hacker News

Designing a programming language to speedrun Advent of Code

blog.vero.site

51–60 of 101 posts

Re: Designing a programming language to speedrun Advent of Code

#51
post #34

Earlier quoted context omitted.

Oh it definitely does. The reason I stick with Python is that it has a somewhat decent standard library, and IMO fewer surprises (I don’t know Python or JavaScript all that well, since I basically never use it professionally, so I need to reduce footguns for myself).

Type cohersion and type juggling can bring a few surprises. But usually only when you do something weird to hit those edge cases. Otherwise, it's standard library is actually very decent now. Especially when working with arrays. You have all the nice to have methods, like, split, find, filter, map, reduce, every, some, etc... Which makes it a really nice language for these kind of tasks. The example above would like…

Or if you like to live dangerously:

    str.split(',').filter(n => +n > 5).length

Re: Designing a programming language to speedrun Advent of Code

#52
post #34

Earlier quoted context omitted.

Type cohersion and type juggling can bring a few surprises. But usually only when you do something weird to hit those edge cases. Otherwise, it's standard library is actually very decent now. Especially when working with arrays. You have all the nice to have methods, like, split, find, filter, map, reduce, every, some, etc... Which makes it a really nice language for these kind of tasks. The example above would like…

Or if you like to live dangerously: str.split(',').filter(n => +n > 5).length

Not all that dangerous, tbh. My main concern would be NaN potentially cascading through, but not only is `NaN > 5` false, `!!NaN` is too.

Re: Designing a programming language to speedrun Advent of Code

#53
post #34

Earlier quoted context omitted.

Oh it definitely does. The reason I stick with Python is that it has a somewhat decent standard library, and IMO fewer surprises (I don’t know Python or JavaScript all that well, since I basically never use it professionally, so I need to reduce footguns for myself).

Type cohersion and type juggling can bring a few surprises. But usually only when you do something weird to hit those edge cases. Otherwise, it's standard library is actually very decent now. Especially when working with arrays. You have all the nice to have methods, like, split, find, filter, map, reduce, every, some, etc... Which makes it a really nice language for these kind of tasks. The example above would like…

To be clear by “standard library” I mean that Python has like actual data structures that are useful. Also while not part of the standard library arbitrary precision integers and associated functions (e.g. modular pow) can be quite helpful.

Re: Designing a programming language to speedrun Advent of Code

#54
post #15

Earlier quoted context omitted.

Talking of shell, the preference for left-to-right is often used to justify "useless use of cat", i.e. `cat file | command` instead of `command <file`, but it can just be written `<file command` instead.

Is `<file` shorthand for `cat file`, or is that only true when used in a sub-shell?

No, `< file command` is completely equivalent to `command < file`.

Re: Designing a programming language to speedrun Advent of Code

#55
post #40

Earlier quoted context omitted.

Not sure if it would be considered simpler but lookaheads can be used to express it in a single pattern. ^(?=.{8}k.$)(?=[^a]*a[^a]*$)(?=[^b]*b[^b]*$)(?=[^c]*c[^c]*$)

It does lead to a very concise invocation: $ perl -ne 'print if /^(?=.{8}k.$)(?=[^a]*a[^a]*$)(?=[^b]*b[^b]*$)(?=[^c]*c[^c]*$)/' /usr/share/dict/words

and to squash a little further:

    perl -ne '/^(?=([abc].*){3})(?!.*([abc]).*\2).{8}k.$/&&print' /usr/share/dict/words

Re: Designing a programming language to speedrun Advent of Code

#56
post #5
post #3

> Before we move on, I want to point out that “being able to write code from left to right without backtracking” is a completely bonkers thing to optimize a programming language for. This should not be anywhere in the top hundred priorities for any “serious programming language”! There are plenty of serious languages that are written this way. Most noticeably are shell scripting languages but I’ve seen stack based an…

I don't really even understand what is meant by "being able to write code from left to right without backtracking”, much less why that is bonkers. Scrolling down and seeing the code examples, the language even seems quite conventional, so I'm even more confused.

Here's an example. In SQL the "select" clause comes at the start. In C# LINQ queries, "select" comes at the end. A major resulting difference is autocomplete works in the latter case but not the former.

A more pervasive example is how OOP languages do x.f(...) instead of f(x, ...). This also helps with autocomplete. Also it results in calls chaining like x.y(...).z(...) instead of nesting like z(y(x(...), ...), ...).

These kinds of things have noticeable effects on how easy it is to discover relevant methods and how fast they are to type.

Re: Designing a programming language to speedrun Advent of Code

#57
post #39

Earlier quoted context omitted.

[me@fedora ~]$ time perl -n -e 'length($_) == 10 && /^[^a]*a[^a]*$/i && /^[^b]*b[^b]*$/i && /^[^c]*c[^c]*$/i && /k.$/i && print' /usr/share/dict/words | wc -l 26 real 0m0,168s user 0m0,162s sys 0m0,007s [me@fedora ~]$ time perl -n -e '/^(?=.{8}k.$)(?=[^a]*a[^a]*$)(?=[^b]*b[^b]*$)(?=[^c]*c[^c]*$)/ && print' /usr/share/dict/words | wc -l 17 real 0m0,260s user 0m0,254s sys 0m0,006s [me@fedora ~]$ time perl -n -e '/^.{8}…

You can also do: sed -e '/^........k.$/!d; /a/!d; /b/!d; /c/!d; /a.*a/d; /b.*b/d; /c.*c/d' /usr/share/dict/words I wouldn't expect it to be much faster than AWK, but not much slower either. Interesting that the pipeline is the fastest! I would expect the sheer number of separate processes to slow things down considerably, but apparently it doesn't really matter. Probably because the first `grep` already filters out m…

The pipeline wasn't just the fastest; it left everything else in the proverbial dust!

Re: Designing a programming language to speedrun Advent of Code

#58
post #39

Earlier quoted context omitted.

[me@fedora ~]$ time perl -n -e 'length($_) == 10 && /^[^a]*a[^a]*$/i && /^[^b]*b[^b]*$/i && /^[^c]*c[^c]*$/i && /k.$/i && print' /usr/share/dict/words | wc -l 26 real 0m0,168s user 0m0,162s sys 0m0,007s [me@fedora ~]$ time perl -n -e '/^(?=.{8}k.$)(?=[^a]*a[^a]*$)(?=[^b]*b[^b]*$)(?=[^c]*c[^c]*$)/ && print' /usr/share/dict/words | wc -l 17 real 0m0,260s user 0m0,254s sys 0m0,006s [me@fedora ~]$ time perl -n -e '/^.{8}…

You can also do: sed -e '/^........k.$/!d; /a/!d; /b/!d; /c/!d; /a.*a/d; /b.*b/d; /c.*c/d' /usr/share/dict/words I wouldn't expect it to be much faster than AWK, but not much slower either. Interesting that the pipeline is the fastest! I would expect the sheer number of separate processes to slow things down considerably, but apparently it doesn't really matter. Probably because the first `grep` already filters out m…

  [me@fedora ~]$ time sed -e '/^........k.$/!d; /a/!d; /b/!d; /c/!d; /a.*a/d; /b.*b/d; /c.*c/d' /usr/share/dict/words | wc -l
  17

  real 0m0,075s
  user 0m0,070s
  sys 0m0,006s

Re: Designing a programming language to speedrun Advent of Code

#59
> The title is clickbait. I did not design and implement a programming language for the sole or even primary purpose of leaderboarding on Advent of Code.

I did: https://github.com/lukechampine/slouch

"Find all ten-letter words that contain each of the letters A, B, and C exactly once and that have the ninth letter K"

  :load wordlist wordlist.txt
  words wordlist | filter -:(len == 10 and .8 == "k")
A more interesting example: https://www.youtube.com/watch?v=i_zDbInYOpQ

AoC solutions here: https://github.com/lukechampine/advent/tree/master/2022

(The language has builtin commands for fetching inputs and submitting solutions)

Re: Designing a programming language to speedrun Advent of Code

#60
post #34

Earlier quoted context omitted.

Type cohersion and type juggling can bring a few surprises. But usually only when you do something weird to hit those edge cases. Otherwise, it's standard library is actually very decent now. Especially when working with arrays. You have all the nice to have methods, like, split, find, filter, map, reduce, every, some, etc... Which makes it a really nice language for these kind of tasks. The example above would like…

To be clear by “standard library” I mean that Python has like actual data structures that are useful. Also while not part of the standard library arbitrary precision integers and associated functions (e.g. modular pow) can be quite helpful.

Javascript now has Map, Set, and bigint. But no powmod.
Post reply on HN