« first day (1418 days earlier)      last day (1237 days later) » 

3:31 AM
@ngn nice
 
 
6 hours later…
9:52 AM
Today's challenge was such a pain to do in APL lol
 
ngn
@rak1507 it's easy if you've got a handy crt impl to copy from :)
 
I rewrote a python one in numpy, wrote it in APL, wondered why I was getting the wrong answer for about 20 minutes and then realised I had to set ⎕FR to 1287
 
ngn
@rak1507 same here! :)
except i was translating python -> k -> apl
 
Oh well, got there in the end
I pulled a modinv off of APLcart, did you do it a cleverer way?
 
ngn
@rak1507 i copied from rosettacode.org :) and translated to k
 
9:55 AM
Haha fair enough
I was too lazy to do my own modular inverse
 
ngn
@rak1507 i can't remember how to do this extended euclidean thing..
so when i need modular inverse, i usually do it through exponentiation using fermat's little, but this time rosettacode had a proper modular inverse
 
ngn
@rak1507 click on avatar to see mine
 
Oh great thanks
I reckon crt would be a pretty helpful addition to aplcart
 
@rak1507 ?
 
10:02 AM
Chinese remainder theorem
 
ngn
@rak1507 i don't know, it seems to be targetting more noobish questions
 
True, wouldn't hurt to have it though
 
Anyone has specific code with description and example runs?
 
ngn
i wouldn't be surprised if there's something in dfns
 
I can't locate anything.
 
10:16 AM
@ngn @rak1507 OK, I've got (1+⊢-⊢⌿⍤⊣≡⊣⌿⍤⊣|⊢)⍣≡∘0↑⍤,⍥⊂ but I can't say I understand…
 
ngn
10:27 AM
@Adám what is that?
 
@ngn Supposedly CRT: ⋄ 3 5 7 (1+⊢-⊢⌿⍤⊣≡⊣⌿⍤⊣|⊢)⍣≡∘0⍤↑⍤,⍥⊂ 2 3 2
 
@Adám 23
 
ngn
@Adám this is crap, it iterates through the integers one by one and tests at every step if it's the answer
it's ok for small inputs, but not for solving today's problem
 
OK, well, I didn't really write it ― just picked it up from RosettaCode.
 
ngn
@Adám yeah, i figured that out from the test numbers :)
 
10:34 AM
tbf, it did come with a warning and a link to a proper impl. but that one looks a tad too verbose to fit on APLcart.
 
ngn
@Adám what's the char limit there?
 
Could you put something like {p←⍺÷⍨×/⍺ ⋄ (×/⍺)|+/⍵×p×m/¨↓⍉↑⍺p} and say m is the modular inverse? seeing as that can also be APLcart'ed
 
I've not yet introduced any dependencies on APLcart. (I don't like dependencies.)
@ngn No hard limit, but current longest entry is 75 chars.
@rak1507 Hey, that, with modinv replacing m is still less than 75.
 
idk if that solution is any good though, it's a port of a port of a port
 
Can certainly be golfed/simplified a bit.
@rak1507 What does p stand for?
 
10:41 AM
{(×/⍺)|+/⍵×p×m/¨↓⍉↑⍺p←⍺÷⍨×/⍺} is an obvious simplification
product
also the variable name used in the rosetta code implementation I copied from
 
But it isn't the product, it is some sort of normalisation.
 
ngn
@rak1507 did you test it?
 
@rak1507 Won't work, methinks, but I already have a few steps further.
{(×/⍺)|+/⍵×p×⍺(⊣|∘⊃{0=⍵:1 0 ⋄ (⍵∇⍵|⍺)+.×0 1,⍪1,-⌊⍺÷⍵}⍨)¨p←⍺÷⍨×/⍺}
 
@ngn no
 
ngn
@Adám that one works (for my input, at least)
 
10:43 AM
{(×/⍺)|+/⍵×⍺(⊢×⊣|∘⊃{0=⍵:1 0 ⋄ (⍵∇⍵|⍺)+.×0 1,⍪1,-⌊⍺÷⍵}⍨)¨⍺÷⍨×/⍺}
{m|⍵+.×⍺(⊣×⊢|∘⊃{0=⍵:1 0 ⋄ (⍵∇⍵|⍺)+.×0 1,⍪1,-⌊⍺÷⍵})¨⍨⍺÷⍨m←×/⍺}
 
11:00 AM
@rak1507 OK, I think ^ is about as good as it gets without more understanding. How do I describe the arguments?
 
ngn
@Adám moduli (⍺) and desired remainders (⍵)
 
> Chinese Remainder Theorem for moduli Iv and desired remainders Jv ?
 
ngn
@Adám i think so
 
OK. Any keywords (search terms) I need to add?
 
ngn
@Adám i don't know what keywords you already use. number theory, primality.. ?
 
11:06 AM
Usually more specific ones like terms one might use to find it. I'll include it in the Mathematical category.
 
ngn
@Adám did you take the modular inverse from dfns.dws? this trick with the matrix is clever. the recursion can probably be replaced with ⍣
 
I don't remember. Have a vague recollection that someone clever like dzaima or RGS contributed it.
Feel free to contribute a better/shorter version based on .
 
11:34 AM
Today is too hard for me in APL. Made a py version of @rak1507's solution using the Rosetta code snippet.
 
12:00 PM
if you port python to numpy it translates reasonably ok to APL
 
Hello folks, is there a way to get rid of the parentheses in ⊃(//⎕VFI'1 2 3 4') ? I tried various combinations with ∘ ⍤ ⍨ but no luck, seems like I can't make APL think of the // as one unit and the things to the left of that as a separate unit
 
@MartinJaniczek ⊃⊢⍤//
 
Thanks, that's very helpful. I'll defer trying to parse the order of execution of that until after watching the video :)
 
APL's order of execution is very simple: Operators bind first (from the left), then functions are applied (from the right).
So, since is a dyadic operator, it binds and (the closest) / as its operands, yielding a new function equivalent to {⍺/⍵} which then becomes the operand of the rightmost /
 
@Adám is this answer elgible for the bounty? codegolf.stackexchange.com/a/216304/61379
 
12:16 PM
@KamilaSzewczyk Yes, for sure. Just note that it can be golfed a bit: ≢⍸1=∘.∨⍨⍳100
 
oh yeah, four bytes down, I missed it
 
35:27 - `⊢⍤/` - "this construct tells APL that you want the _function_ `/` and not the operator `/`"
That cleared it up a bunch, thanks!
 
incorrectly :p
but now it's fine
 
@MartinJaniczek (I wonder why markdown failed there. Do you have a trailing line break?)
 
Wonderful
 
12:19 PM
the tally + interval index thing seems clever
 
@Adám Unsure. That message had two lines
 
@KamilaSzewczyk Also, I'd avoid Classic unless you have to. I know it is a bit awkward to adjust byte counts to char counts, but you'll avoid garbage on stdout, and byte-counting pitfalls.
@MartinJaniczek Aha, markdown is not active in multi-line messages, but you can use two consecutive messages, and it'll look pretty much the same.
 
so, which one should I use? I know there's extended and it sometimes helps out
the unicode one seems to inflate the byte count by a lot so I'm not using it
 
@KamilaSzewczyk Unicode. You can reference github.com/abrudz/SBCS if you want to justify 1 byte per char.
 
Why not say it's extended just for ease?
 
12:22 PM
@MartinJaniczek You may also like ]box -t=tree
@rak1507 Sure, when Extended works. But it has quirks and is very slow.
 
12:50 PM
I finally fixed it so that it's possible to redefine a function without having to reparse all the code that uses it.
 
 
2 hours later…
2:47 PM
@Adám It's not an APL tutorial in the sense that I introduce primitives as the application needs them, rather than following a systematic plan of instruction for an APL novice.
 
2:57 PM
@RomillyCocking I think that is an excellent way to tutor APL, though :-D Plenty of these do that.
 
hmm this part 2 is a bit huge
 
3:42 PM
part 2 for todays AOC?
 
yeah
kinda annoying
just read a bunch of chinese remainder theorem articles
barely makes sense to me
 
lmao
 
4:03 PM
hmm there's a crt snippet
 
@Razetime Heh, yes, as of today.
 
Oh yeah, cool!
 
4:28 PM
well that's pretty convenient
 
4:49 PM
@KamilaSzewczyk Why 200, though? It isn't a new winner, afaict.
 
5:03 PM
well explained + first answer?
 
^
I deleted my first first answer
 
@KamilaSzewczyk Isn't this one older?
Also, welcome to the club!
 
hmm, this one doesn't qualify for the bounty
so I thought it's exempt from the first answer condition
but yeah, sure, then I'll change it to 100 soon-ish
 
I need to get back into code golfing, not done any problems in a while
 
@KamilaSzewczyk Ah, so you should have simply posted them in reverse order. No worries. I'll grant you an exception for that.
 
5:08 PM
I got reminded about the bounty after I posted a few initial answers in APL I did :p
oh also, would you like to take a look at a few snippets I wrote for projecteuler
 
@KamilaSzewczyk For sure.
 
github.com/kspalaiologos/euler-apl - I wasn't really interested at golfiness here, rather general code style and performance maybe
@Razetime suggested me an embarrassingly short golf to task 8 which I merged :p
 
@KamilaSzewczyk Btw, posting APL on CR.SE is perfectly alright (and the feed bot here will notice).
 
Why upload a dws and an apl file?
 
@rak1507 so you can conveniently run it using /usr/bin/dyalog, and inspect the code if you're just lurking
 
5:11 PM
hmm
fair enough I guess
 
ngn
.dws sucks
 
@KamilaSzewczyk Ah, but as of Dyalog 18.0, you can run code in a text file straight from the commandline.
 
I read your answer on stackoverflow(?)
which advocated .dws files, so I decided on using these
 
I would make my proj euler stuff public but it has some solutions after 100 which I think is not allowed to be shared :(
 
damn 100 programs :p I may or may not have the patience to reach it
for task 11 I thought for a while about using stencil + some possibly smart algorithm for multiplying in diagonals and rows
 
5:12 PM
I don't have over 100 programs, I have just solved a few problems over 100
I used stencil for that one
 
ah, fair then
 
At first I put each solution in its own file but now I just stick them all in one big file
I should probably sed it at some point so that `⍝ Problem 76
⍝ Counting summations` becomes `⍝ Problem 76 Counting summations` to avoid the extra line per problem
 
ngn
@rak1507 ⍝76 would do :) everyone knows how to look up the description.
 
Of course you'd say that ;)
I like having the title as well
 
I kinda wish APL had increment/decrement operators like J, they're quite handy for golf
obviously >: and <: are two bytes each so no difference in 1+, but decrement makes it a bit messier
because it's either ¯1+ or 1-⍨ both three bytes long
 
5:31 PM
I think ? might work sometimes.
 
@user What do you mean?
 
It was a joke.
By the way, does anyone know if there exists a 16-character Game of Life (non-toroidal)?
 
@user I think 17 is the minimum.
 
Oh, that's too bad.
Actually, it doesn't matter, the solution I'm thinking of would be shortest with the life function in dfns, a non-toroidal solution wouldn't change anything.
 
Why?
 
5:40 PM
Well, I was originally thinking of removing the 0-padding necessary to make the life function work, but if that's removed, then it won't be treated as an infinite grid.
 
Now I wish I had all those 17-byters from the APL CodeGolf Autumn Tournament as maybe one of them could be shortened using new 18.0 features…
 
This question is what I needed it for.
 
Yeah, I wish ⌺ had some options.
 
It's still pretty cool, though.
 
5:49 PM
GNU APL recently introduced something called "structured variables". It actually looks a bit like the similar concept in COBOL of all languages. Is this something that exists in other APL's? gnu.org/software/apl/apl.html#Structured-Variables
 
ngn
@EliasMårtenson k dicts maybe
 
@EliasMårtenson Looks like limited namespaces to me. Are they pass-by-value or pass-by-reference?
 
ngn
@Adám but in dyalog a.b.c←1 doesn't create namespaces a and b
in k a.b.c:1 does
 
@ngn True, but that's just a syntactic convenience thing/sugar. Also 'a.b.c'⎕NS⍬ does create a and b. Dyalog could easily add that.
 
6:11 PM
@Adám I don't know. I haven't built the latest version to test yet.
 
6:50 PM
<phantomics> Hell of a departure from APL style
 
7:10 PM
phantomics: Namespaces? Yeah. GNU-APL? Yup.
 
 
2 hours later…
8:45 PM
I wonder if that still life challenge could be done in Stencil
 
Maybe. Let me know if you need help.
 
I'm probably not going to attempt it, it was just an idea
 
9:02 PM
I lied, I am going to try it, tio.run/##Ky5JzUvOzPn/3/hRR1du6v//… I pasted the inputs and stuff, not sure how to go about it though
It looks like you have something about this exact problem (near enough) in the description
 
@rak1507 Problem is that you can't easily detect if the input re-appears or only leads to the cycle.
 
ah well it was worth a shot at least
 
You might have more success using Stencil as a library. Not sure.
If you then get a vector of states, you can check if the initial state ever re-appears.
 
Sounds too complicated considering how lazy I am and how much homework I have due for tomorrow...
 
9:57 PM
Hey folks! I was trying to implement "replace all chars X with char Y in string Z", got {'Y'@(⍸'X'=⍵)⊢⍵} Z, then looked at the APLCart, found 'Y'@(=∘'X')Z which looks awesome but I'm confused by how it works. (I think I get @ when the right arg is list of indices like 2 4. But, how does the binary selection example work? Does @ figure out it has a function instead of a vector on the right side and switches into different mode in that case?
 
ngn
@MartinJaniczek yes
 
<phantomics> The @ operator will place the left argument at every element for which the right function evaluates to 1 (true)
 
@MartinJaniczek Yes, @ looks at the type of its operands. In fact, you can write such operators yourself, by checking ⎕NC'⍵⍵'
 
<phantomics> @ is a complicated one, it has 4 different use cases
 
ooh, reflection
 
9:59 PM
@DyalogAPL Not 6?
 
<phantomics> Depending on whether you have functions or values as the operands
<phantomics> Either function or value at left, either function or value at right makes 4 major modes for it, what else is there?
 
A left function operand can be monadic or dyadic.
 
ngn
@Adám apl functions are always ambivalent
 
<phantomics> Right, I don't consider that a different mode
 
@ngn Yes, but some operators restrict themselves to one type of operand. E.g. and can only take a monadic right operand.
 
10:03 PM
<phantomics> Kind of a sub-mode, since many operators generate monadic and dyadic variations of functions
 
ngn
@Adám they can take a right operand and apply it monadically, and if the operand doesn't like it, it can signal an error
 
True.
Indeed, even array∘array is syntactically acceptable, even if it is difficult to to use.
 
<phantomics> Is array∘array usable? Not afaik
 
That said, as practical as it is, I'm not particularly fond of @ as it was implemented. I would have done it differently.
phantomics: ⋄ ⍬∘⍬/2 3 1⍴0
 
@Adám
0 0 0
0 0 0
 
10:07 PM
One more question. The =∘'X' inside the "replace occurences" example... Does the order matter? As in, the above snippet would apply 'X' as , and 'X'∘= would apply it as instead?
 
Correct. Doesn't matter, since = is commutative.
 
Right, in that example wouldn't matter but with arbitrary fn instead of it it might?
 
Of course. @(>∘0) and @(0∘>) are not the same.
But you're right, that binding (a.k.a. currying) an argument to a dyadic function renders a monadic function where the right (and sole) argument is used in the remaining argument slot of the original function.
 
Right, thanks. A new connection between my FP intuition and APL acquired :)
 
Cool.
 
10:12 PM
<phantomics> @Adám Cool, didn't see that in any docs
 
I'm not even sure where that'd fit into the docs.
 
<phantomics> Dyalog's docs enumerate the arguments and operands, mentioning the left operand may be an array, or the right may be an array, they could have a sentence mentioning the particular case where both may be arrays
 
Well, it isn't particular to but rather falls under a general rule that every operator (except the slashes) can take any (combination of) array(s) and/or function(s) as operand(s), even if no meaning has been given to the derived function.
So really, our docs are all wrong. They claim about operators that they have a specific domain, when the technical reality is that the derived function may or may not have an argument domain.
E.g. any array or function is a valid operand to but only a select few positive integers have meaning.
 
<phantomics> I see
 
In fact, probably most derived functions are meaningless.
 
10:19 PM
<phantomics> What's the difference between operands generating a meaningless derived function and "invalid" operands?
 
Operands cannot be invalid (other than if you attempt to use as operand something that is neither an array nor a function).
E.g. ⊥⍥'a' is a perfectly valid, but meaningless, construct.
 
ngn
one definition of "valid" is "when i type it and press enter, it doesn't error". another is: "when i apply the derived function to a valid argument, it doesn't error".
 
@ngn OK, but then I challenge you to find an invalid derived function (i.e. the function itself does not error if entered by itself) in the sense that there exist no arguments that cause it to not error.
Heh, if you turn boxing on, then you can find the line box←{susp ⍺(⍵⌶Box)⍵} in ⎕SE.Dyalog.Out.Filter where is meaningfully used to construct a meaningless derived function!
 
ngn
@Adám i'm stuck trying to understand the quadruple negative in your message :)
 
@ngn Find me a derived function f such that f returns successfully and f X is an error for all arrays X.
(Look ma, no negatives!)
 
ngn
10:31 PM
@Adám how can f on its own ever be an error?
@Adám "not"
 
@ngn Oh.
@ngn It is meant to exclude faulty constructs like ∘⍣⊢
 
ngn
@Adám ≢⍣¯1 ?
 
@ngn Nice, but you can get way shorter.
 
<moon-chilled> ÷∘0
<moon-chilled> (though depends on ⎕div)
 
@DyalogAPL 0
 
10:37 PM
<moon-chilled> right, I forgot apl does that
<moon-chilled> ''∘⎕signal
 
You guys are forgetting something fundamental.
moon-chilled:
 
ngn
@Adám just ⍬ under a monadic operator then, e.g. ⍬⌸?
⍬ or any other array
 
Yes, any monadic operator except in version 18.0+.
 
ngn
@Adám and except ⌶ (if we allow non-⍬-s)
 
Oh, sure.
 
11:40 PM
Announcement: Ken Iverson centenary panel discussion with Roger Hui, Arthur Whitney, Morten Kromberg, Aaron Hsu, and other influential APL/J/K people.
 

« first day (1418 days earlier)      last day (1237 days later) »