Live data from Hacker News

Designing a programming language to speedrun Advent of Code

blog.vero.site

71–80 of 101 posts

Re: Designing a programming language to speedrun Advent of Code

#71
post #15
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…

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.

I'll often commit 'useless use of cat' there for three reasons:

1) Muscle memory

2) Often when I don't I end up needing two files later

3) It annoys merlyn (Randal Schwartz)

Re: Designing a programming language to speedrun Advent of Code

#72

> 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 ex…

How does that do the fiddly bit "contain each of the letters A, B, and C exactly once" ?

Shoot, I totally overlooked that part. Here's the proper version:

  :load wordlist wordlist.txt
  =hasABC { all (count _ x == 1) "abc" }
  words wordlist | filter -:(len == 10 and hasABC and .8 == "k")
Notes:

{ } defines a lambda with parameters named x,y,z,a,b,c...

_ is the same as in noulith -- it turns any expression into a lambda. Values can also be omitted from most expressions (e.g. len == 10) for the same effect.

-: takes a lambda with n parameters and turns it into a lambda that takes 1 parameter and replicates it n times.

Re: Designing a programming language to speedrun Advent of Code

#73
I'm not a competitive Advent of Coder, but as a corporate trainer, I appreciate it for giving me insights into my coding style. Hopefully, I can use those insights for my students.

The last time I did AOC, I tracked every error I made to reflect on my mistakes when coding.

I think this year I will do "Advent of AI" and see how far AI tooling can get me.

Re: Designing a programming language to speedrun Advent of Code

#74
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…

> 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 most of the dictionary, so there isn't a lot of I/O through the pipes.

The IO doesn’t matter so much because they’re done in parallel. Whereas the other examples have to filter each word throw the entirety of their steps before they can proceed onto the next word.

Re: Designing a programming language to speedrun Advent of Code

#75

> 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 ex…

> words wordlist | filter -:(len == 10 and .8 == "k")

This feels very similar to an APL or K solution.

Are those languages you're aware of?

Re: Designing a programming language to speedrun Advent of Code

#76

I think it’s interesting how similar a lot of this stuff is to what I do, except I’m not very good at Advent of Code and also I decided to hack Python to do this instead of writing my own language. For example: * I couldn’t really make operators first class functions, but I just autoimported operator which has this but in words * I wanted partial application and hated lambda syntax, so I hacked it together with some…

I think Ruby might be your next language :)

But I do do the following sort of thing in Python: ``` from chainzzz import C

C(some_list).group_by(lambda x: x + 1).map(lambda key: key % 2).size() ```

Where C(...) gives us the same object but with some methods added to it as you can see

Re: Designing a programming language to speedrun Advent of Code

#77

Earlier quoted context omitted.

How does that do the fiddly bit "contain each of the letters A, B, and C exactly once" ?

Shoot, I totally overlooked that part. Here's the proper version: :load wordlist wordlist.txt =hasABC { all (count _ x == 1) "abc" } words wordlist | filter -:(len == 10 and hasABC and .8 == "k") Notes: { } defines a lambda with parameters named x,y,z,a,b,c... _ is the same as in noulith -- it turns any expression into a lambda. Values can also be omitted from most expressions (e.g. len == 10) for the same effect. -:…

That is neat!

Re: Designing a programming language to speedrun Advent of Code

#78
post #7

> I solve and write a lot of puzzlehunts, and I wanted a better programming language to use to search word lists for words satisfying unusual constraints, such as, “Find all ten-letter words that contain each of the letters A, B, and C exactly once and that have the ninth letter K.” So... Perl?

    words←⊃⎕nget 'wordlist.txt' 1        ⍝ read lines
    tenK←'^........k.$' ⎕S '&' ⊢ words   ⍝ regex filter
    ↑tenK/⍨{∧/1='abc'(+/∘.∊)⍵}¨tenK      ⍝ count abc and filter
Dyalog APL, but it's still kinda ... heavy.

Re: Designing a programming language to speedrun Advent of Code

#79

> 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 ex…

> words wordlist | filter -:(len == 10 and .8 == "k") This feels very similar to an APL or K solution. Are those languages you're aware of?

Oh yes -- I've never developed serious competency in them, but Arthur Whitney and Aaron Hsu are among my programming heroes :)

Re: Designing a programming language to speedrun Advent of Code

#80

> 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 ex…

It definitely has a kind of "I have something I want to do, let me hack at it" feel. Love anything that helps with that. :)

The lambda formation is something that will have to be gnawed at though.

Post reply on HN