Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regular expressions #107

Open
tluyben opened this issue Dec 3, 2024 · 0 comments
Open

Regular expressions #107

tluyben opened this issue Dec 3, 2024 · 0 comments

Comments

@tluyben
Copy link

tluyben commented Dec 3, 2024

Any idea for adding regular expressions? (given that all implementations of advent of code day #3 where basically just 1 regex :)

J (TIL) has them like this;

F =: +/@([: (3 */@".@}. ])@> 'mul\(\d+,\d+\)' rxall ])

how about

`/mul\((\d+),(\d)+\)`/

which will return a list with matches

so we can do;

+/*/`/mul\((\d+),(\d+)\)`//input

for instance (look ma, no casting; \d already know it's integers obviously)

For ease of implementation, this would obviously also work:

+/*rx["mul\(\(d+),\(d+)\)"]/input

Seems that's the way most other APLs implement it.

I hacked in my own which works well;

https://gist.github.com/tluyben/fc959d7ae821c8864cf13d5af319c81e
https://github.com/tluyben/ok

Makes the solution to day 3 indeed as trivial as:

+/{*/x[2]}'rx["mul\((\d+),(\d+)\)";input]

I couldn't figure out how to make it accept arguments to the left that fast (I didn't spend a lot of time), but it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant