Andy @ Andy @programming.dev Posts 130Comments 353Joined 2 yr. ago

Intensional Joy (a concatenative account of internal structure) — Christine's World Wide Web Site
It's been a while, but my clumsy adding of a comment to the buffer is unnecessary, given zle -M
, which will display a message outside of the buffer. So here's an updated version:
bash
# -- Run input if single line, otherwise insert newline -- # Key: enter # Credit: https://programming.dev/comment/2479198 .zle_accept-except-multiline () { if [[ $BUFFER != *$'\n'* ]] { zle .accept-line return } else { zle .self-insert-unmeta zle -M 'Use alt+enter to submit this multiline input' } } zle -N .zle_accept-except-multiline bindkey '^M' .zle_accept-except-multiline # Enter # -- Run input if multiline, otherwise insert newline -- # Key: alt+enter # Credit: https://programming.dev/comment/2479198 .zle_accept-only-multiline () { if [[ $BUFFER == *$'\n'* ]] { zle .accept-line } else { zle .self-insert-unmeta } } zle -N .zle_accept-only-multiline bindkey '^[^M' .zle_accept-only-multiline # Enter
Tacit Talk: a podcast about programming languages, combinators, algorithms and more!
The given Uiua example (mercifully given using words rather than the symbols):
[3 4 5 10 23] divide length on /+
For all the talk about "forward" it's uncomfortable to me how the Uiua evaluation within a line happens backward.
An equivalent in Factor, where keep
is close to on
:
{ 3 4 5 10 23 } [ sum ] keep length /
But this pattern of doing two things in sequence to the same item is common enough that bi
is handy:
{ 3 4 5 10 23 } [ sum ] [ length ] bi /
Slow and dumb gets it done! I may revisit this when I give up on future days.
Factor
Nothing smart to see here. I may revisit this when I give up on future days.
Factor
Factor
: get-input ( -- rules updates ) "vocab:aoc-2024/05/input.txt" utf8 file-lines { "" } split1 "|" "," [ '[ [ _ split ] map ] ] bi@ bi* ; : relevant-rules ( rules update -- rules' ) '[ [ _ in? ] all? ] filter ; : compliant? ( rules update -- ? ) [ relevant-rules ] keep-under [ [ index* ] with map first2 < ] with all? ; : middle-number ( update -- n ) dup length 2 /i nth-of string>number ; : part1 ( -- n ) get-input [ compliant? ] with [ middle-number ] filter-map sum ; : compare-pages ( rules page1 page2 -- <=> ) [ 2array relevant-rules ] keep-under [ drop +eq+ ] [ first index zero? +gt+ +lt+ ? ] if-empty ; : correct-update ( rules update -- update' ) [ swapd compare-pages ] with sort-with ; : part2 ( -- n ) get-input dupd [ compliant? ] with reject [ correct-update middle-number ] with map-sum ;
More Factor solutions for the first 3 days (at time of comment) from okflo, on sourcehut.
Have you had a good look at Factor? FWIW I've got at least the first 3 days with it up here.
Some more Factor solutions for the first 3 days (so far) from soweli Niko, on Codeberg.
Factor
: get-input ( -- corrupted-input ) "vocab:aoc-2024/03/input.txt" utf8 file-contents ; : get-muls ( corrupted-input -- instructions ) R/ mul\(\d+,\d+\)/ all-matching-subseqs ; : process-mul ( instruction -- n ) R/ \d+/ all-matching-subseqs [ string>number ] map-product ; : solve ( corrupted-input -- n ) get-muls [ process-mul ] map-sum ; : part1 ( -- n ) get-input solve ; : part2 ( -- n ) get-input R/ don't\(\)(.|\n)*?do\(\)/ split concat R/ don't\(\)(.|\n)*/ "" re-replace solve ;
Factor
: get-input ( -- reports ) "vocab:aoc-2024/02/input.txt" utf8 file-lines [ split-words [ string>number ] map ] map ; : slanted? ( report -- ? ) { [ [ > ] monotonic? ] [ [ < ] monotonic? ] } || ; : gradual? ( report -- ? ) [ - abs 1 3 between? ] monotonic? ; : safe? ( report -- ? ) { [ slanted? ] [ gradual? ] } && ; : part1 ( -- n ) get-input [ safe? ] count ; : fuzzy-reports ( report -- reports ) dup length <iota> [ remove-nth-of ] with map ; : tolerable? ( report -- ? ) { [ safe? ] [ fuzzy-reports [ safe? ] any? ] } || ; : part2 ( -- n ) get-input [ tolerable? ] count ;
Factor
: get-input ( -- left-list right-list ) "vocab:aoc-2024/01/input.txt" utf8 file-lines [ split-words harvest ] map unzip [ [ string>number ] map ] bi@ ; : part1 ( -- n ) get-input [ sort ] bi@ [ - abs ] 2map-sum ; : part2 ( -- n ) get-input histogram '[ dup _ at 0 or * ] map-sum ;
Day 3
Image:
Day 2:
Image: