Andy

joined 1 year ago
MODERATOR OF
[–] Andy 2 points 1 hour ago

Factor

: get-input ( -- corrupted-input )
  "aoc-2024.03" "input.txt" vocab-file-path 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 ;
[–] Andy 1 points 1 hour ago

Factor

: get-input ( -- reports )
  "aoc-2024.02" "input.txt" vocab-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 ;
[–] Andy 1 points 1 hour ago

Factor

: get-input ( -- left-list right-list )
  "aoc-2024.01" "input.txt" vocab-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 ;

https://github.com/AndydeCleyre/aoc-2024

[–] Andy 1 points 1 hour ago
[–] Andy 1 points 9 hours ago* (last edited 9 hours ago)

Day 3

spoiler

: get-input ( -- corrupted-input )
  "aoc-2024.03" "input.txt" vocab-file-path 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 ;

Image:

spoiler

code above as colorful image

[–] Andy 1 points 1 day ago* (last edited 23 hours ago)

Day 2:

spoiler

: get-input ( -- reports )
  "aoc-2024.02" "input.txt" vocab-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 ;

Image:

spoiler

image of above code

14
submitted 1 day ago* (last edited 1 day ago) by Andy to c/concatenative
 

Alright, show me I'm not the only one in this community, and show off some solutions!

Here's my Day 1 solution in Factor (minus imports):

spoiler

: get-input ( -- left-list right-list )
  "aoc-2024.01" "input.txt" vocab-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 ;

Sadly, Factor doesn't get highlighted here, so here it is again as an image:

spoiler

syntax-highlighted screenshot of the code above

I probably won't last the week, but what solutions I do have will be up on GitHub.

6
NeoHaskell (neohaskell.org)
submitted 1 week ago by Andy to c/concatenative
 

This example is my justification for posting it here:

"NeoHaskell is cool"
  |> Text.toWordList
  |> List.map Text.length
  |> List.map (\x -> x * x)
  |> List.takeIf Int.isEven
[–] Andy 1 points 1 week ago

A lot of Forth discussion in the HN comments:

https://news.ycombinator.com/item?id=42207304

 

I posted this project here before, but it's now reached 1.0.0.

2
submitted 2 weeks ago by Andy to c/concatenative
2
submitted 3 weeks ago by Andy to c/concatenative
 

Hey, it includes Factor!

[–] Andy 1 points 4 weeks ago* (last edited 4 weeks ago)

Sure, but nox is the closer counterpart for in-venv-task definitions. List "sessions" with -l, pick specific sessions to run with -s.

import nox
from nox.sessions import Session

nox.options.reuse_existing_virtualenvs = True
APP_NAME = 'logging_strict'

@nox.session(python='3.12')
def mypy(session: Session):
    """Static type checker (in strict mode)"""
    session.install('-U', 'mypy', '.')
    session.run('mypy',  '-p', APP_NAME, *session.posargs)

Unfortunately it doesn't currently do any parallel runs, but if anyone wants to track/encourage/contribute in that regard, see nox#544.

[–] Andy 2 points 1 month ago

As someone's new comments just brought me back to this post, I'll point out that these days there's another good option: uv run.

[–] Andy 1 points 1 month ago (2 children)

No, I don't use GHA locally, but the actions are defined to run the same things that I do run locally (e.g. invoke nox). I try to keep the GHA-exclusive boilerplate to a minimum. Steps can be like:

- name: fetch code
  uses: actions/checkout@v4

- uses: actions/setup-python@v5
  with:
    allow-prereleases: true
    python-version: |
      3.13
      3.12
      3.11
      3.10
      3.9
      3.8
      3.7

- run: pipx install nox

- name: run ward tests in nox environment
  run: nox -s test test_without_toml combine_coverage --force-color
  env:
    PYTHONIOENCODING: utf-8

- name: upload coverage data
  uses: codecov/codecov-action@v4
  with:
    files: ./coverage.json
    token: ${{ secrets.CODECOV_TOKEN }}

Sometimes if I want a higher level interface to tasks that run nox or other things locally, I use taskipy to define them in my pyproject.toml, like:

[tool.taskipy.tasks]
fmt = "nox -s fmt"
lock = "nox -s lock"
test = "nox -s test test_without_toml typecheck -p 3.12"
docs = "nox -s render_readme render_api_docs"
 

From Enaml's docs:

Enaml brings the declarative UI paradigm to Python in a seamlessly integrated fashion. The grammar of the Enaml language is a strict superset of Python. This means that any valid Python file is also a valid Enaml file, though the converse is not necessary true. The tight integration with Python means that the developer feels at home and uses standard Python syntax when expressing how their data models bind to the visual attributes of the UI.

. . .

Enaml’s declarative widgets provide a layer of abstraction on top of the widgets of a toolkit rendering library. Enaml ships with a backend based on Qt5/6 and third-party projects such as enaml-web and enaml-native provides alternative backends.


A maintainer of Enaml has just opened a brainstorm discussion on the next major development goals.

It's a project I've long admired, though rarely used, and I'd love to see it get some attention and a revamp. I think the bar these days has been raised by projects like QML and Slint, which provide a great context in which to set new goals.

[–] Andy 3 points 1 month ago

If you choose to give Fedora a try, I recommend Ultramarine, which has more set up from the start, including their "Terrs" repository with more updated packages.

4
Constants | Re: Factor (re.factorcode.org)
submitted 1 month ago by Andy to c/concatenative
 
4
submitted 1 month ago by Andy to c/concatenative
 

Animated preview

This is not my own project!

view more: next β€Ί