« first day (1708 days earlier)      last day (936 days later) » 

9:18 AM
hi
 
@Razetime thanks
 
 
5 hours later…
1:57 PM
Hi everyone! It's my first time here - I am a beginner in APL.

I answered a question on Code Golf Stack Exchange in Dyalog APL. I am posting the link to my answer below - please comment on my answer if you have any suggestions for improving it / reducing character count.

My answer link : https://codegolf.stackexchange.com/a/235768/107187
 
@SohangChopra Can you explain how you run your code, or perhaps post a TIO link? tio.run/#
You can also run one-liners right here in the chat: ⎕←⌽'Hello world'
 
@xpqz dlrow olleH
 
@SohangChopra {⍺[⍵]} can be better written as ⌷⍨
That'll save you 4 chars.
 
2:32 PM
@xpqz I am running the code on tryapl.org.
 
@SohangChopra and (?2⍴⍨≢) can be (?2⍨¨), new feature in Dyalog 18
 
@LdBeth I tried your code, and it works - but I don't understand how it works. Can you please explain?
@EliasMårtenson Thanks for your suggestion, I'll edit my answer accordingly.
 
3:00 PM
@SohangChopra in 18 dyadic function is just a short hand for {⍺}
and seems they also have optimization so N⍨¨ is as fast as N⍴⍨≢
 
@LdBeth {⍺⍺} you mean
 
3:43 PM
Sorry if this is a dumb question, but I found this expression from https://www.jsoftware.com/papers/50/50_36.htm which calculates the first ten Fibonacci numbers:

fib2←{⊃+\∘⌽⍣⍵⍳2}

fib2¨ ⍳10
0 1 1 2 3 5 8 13 21 34

Am I correct to assume that this is not very efficient, since the `+\∘⌽` operation is run `+/⍳10` or 45 times?
Oops, looks like I messed up the formatting there...
 
SE chat doesn't allow markdown in multiline messages
but yeah, fib2¨⍳n is O(n^2)
 
Ah I see
Is there a better way to do this?
 
you can go all iterative, but it's not too pretty
 
3:58 PM
In f@g⊢A can g be applied to A to obtain just a boolean or can it return a vector of indices?
 
@MasterQuiz if g is a function, it must return a boolean vector
 
@SohangChopra I've quickly wrote a 17 character solution: 1∘⎕C@((⍳∊?↑?⍨)∘≢) (I think it should be correct). Is it true that you can't erase the parentheses after @?
 
4:16 PM
@Adám Why did you use I-beam instead of {?2:⍵⋄1⎕C⍵}¨
@MasterQuiz 16 characters: 1∘⎕C@((⍳∊?∘?)∘≢)
 
I think 1∘⎕C@(?2⍴⍨≢) works too?
 
@rabbitgrowth Here's one:
Fib ← { ⍝ Tail-recursive Fibonacci.
    ⍺ ← 0 1
    ⍵=0: ⊃⍺
    (1↓⍺,+/⍺)∇⍵-1
}
 
@xpqz the point was to calculate the first n fibonacci numbers. The original is O(n) for only one too.
 
4:34 PM
@dzaima Right. I offer {r←⍬⋄_←{{p←+\⌽⍵⋄r,←⊃p⋄p}⍣⍵⊢0 1}⍵⋄r}
⎕←{r←⍬⋄_←{{p←+\⌽⍵⋄r,←⊃p⋄p}⍣⍵⊢0 1}⍵⋄r}10
 
@xpqz 1 1 2 3 5 8 13 21 34 55
 
and that's what I meant with not too pretty all iterative
 
You're basically describing all APL code I compose :)
 
@rabbitgrowth I prefer to work with IO set to 1, so it would be 1∘⎕C@(1-⍨(?2⍴⍨≢)), but yes
 
5:01 PM
Ah right, I shouldn't have assumed ⎕IO←0. Sorry!
Thanks @xpqz! For some reason it didn't occur to me that you could use with a function with side effects. It appears that your solution is about twice as fast. This is really interesting.
 
There is a lot of detailed fib-stuff in dfns, which you may have seen already.
 
@SohangChopra ⊢⎕C¨⍨¯1*∘?2-∊∘⎕A is 16
⎕IO←0 of course
ah missed the @ stuff above
oh they don't work anyway with keeping capitalised letters the same nvm it does you can just uppercase random letters and it'll work, clever
 
 
1 hour later…
6:19 PM
@rak1507 Isn't this same as ⊢⎕C¨⍨¯1*∘?2⍨¨
 
7:05 PM
No, it doesn't keep capitals capitalised
 
Leo
7:26 PM
@xpqz Thanks, I'll have a look.
 
@rak1507 {⍺⍴,⌿1+(,⍵)⊤⍺?⍥(×/)⍵} then. (⎕IO←1 for APLcart.)
 
fair enough...
I feel like it should probably be ⎕IO independent if possible but sticking with one makes sense too
 
@MasterQuiz Where?
@rak1507 One feature I'd like would be a checkbox/switch/parameter/whatever to flip all entries between ⎕IO←0 and ⎕IO←1, but obviously, that is a major job, and makes the ongoing job of maintenance/additions harder.
 
yeah that's overkill probably, lot of effort for not much gain, normally pretty easy to adapt something to be ⎕IO independent unless it uses particular tricks
 
… which one or two entries do; something like getting indices and padding with zeros.
 
7:41 PM
yep
 
@Adám Here but I just realised that this answer is 4 years old... Also there's a typo in "Rquires".
 
@SohangChopra If you see lots of ¨ then there's a good chance you can "factor them out": {(?2)⌷⍵,1⎕C⍵}¨
 
@Adám It becomes also a lot more readable
 
@MasterQuiz Yeah, ⎕C wasn't around yet. Fixed the typo.
 

« first day (1708 days earlier)      last day (936 days later) »