My old brain would have gone for something along the lines of {⎕IO←0 ⋄ (⍴a)⊤(,⍵=(⌈/⌈/⍵))⍳1} .. rather more long winded, but for large arrays, potentially rather quicker
also, when you say "the index of the max element in matrix" is it possible that there are more than 1 occurrence of the maximum value, and if so, are you interested in only the first or do you want all of them ?
Of course what you have to remember in all of this is that if you're running this expression lots of times it's worth spending time comparing the performance of different expressions. If you're running it once then the performance improvement may not be worth the time spent on experimentation - your time may be better spent elsewhere in the code !
Sure. Change this definition actually improved the time from 03.53 sec to 02.48 for my blue noise generate function, with a moderate amount of output size specified.
Deciding how big to set MAXWS is always interesting .. if you're the only person on the box and you only ever run 1 APL session in parallel then you can set it big. But in my time I've killed many a box by running too many APL processes in parallel where MAXWS is set too large and I've been close to filling all of them up !
We've done a fair amount of testing with MAXWS=90G, but I know that someone ran a simple addition in a 2T workspace where the addition needed all that space.
.. and that the 2TB was all in memory, no swapping
@LdBeth Well, addition is limited by memory bandwidth, not by the CPU. If the RAM can sustain 10 GB/s then the whole thing should be done in under 4 mins.
]runtime -c "x Red y" "x Rec y" "x Iter y" "x f y"
x Red y → 5.2E¯6 | 0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
x Rec y → 2.7E¯6 | -48% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
x Iter y → 2.6E¯6 | -51% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
x f y → 2.3E¯6 | -56% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
a ← ⎕A[?⍨3]
b ← ⎕A[?1e6⍴26]
]runtime -c "x Red y" "x Rec y" "x Iter y" "x f y"
x Red y → 5.3E¯6 | 0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
x Rec y → 2.8E¯6 | -48% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
x Iter y → 2.5E¯6 | -54% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
x f y → 1.4E¯6 | -75% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
the idea was to divide indices by the length so 0 2 -> 0, 4 5 -> 1, but that doesn't work if the indices are 3 5 for example, they'll go to 0 and 1 and the result will be 2 not 1
Background
This challenge is about the Game of Go. Here are some rules and terminology relevant to this challenge:
Game of Go is a two-player game, played over a square board of size 19x19.
One of the players plays Black, and the other plays White. The game is turn-based, and each player makes ...
I was trying something like this, take the difference bigger than ≢⍺, But doesn't work in case of 'abababab', Cause the pairwise difference would be 2 2 A B←'abab' 'ababcabababcabababab' ⋄ A {⍉(1 1 0 1 0 1),⍨{⍵,⍪4,2-⍨/⍵}⍸⍺⍷⍵} B ⍝ A {2-⍨/⍸⍺⍷⍵} B
Just for information, a French APLer in the early 80s wrote a Computer Go program in APL. That French APLer was also a French Go champion ! That Code-golf problem by Bubbler reminds me of that bit of APL history concerning computer GO that is not mentioned anywhere.
@Adám Have you ever heard of any computer GO program in APL from the 70s or 80s ?
@Adám the recursive version of P5 annihilates the non-recursive one. That surprised me a bit. But my performance intuition is pretty much always wrong.
although because of the square root thing it's definitely going to be easier just going up to the square root and taking the largest divisor 'manually'
but in general a divisors function would be useful
@MasterQuiz Yes. Someone was designing a new language, and I just implemented it. The funny thing was that my implementation was almost identical to his spec doc, only with some APL symbols thrown in here and there.
@rak1507 People might think that they have to "fill in" the dfn, or that the solution has to be an expression in terms of (⍺ and) ⍵. Instead of protesting, I simply parse the input and add braces if necessary. However, these statistics are on the raw submission. Many have unnecessary spaces too, and one even had a comment despite instructions.
@rak1507 The magic of insufficient test cases. Someone found a super-short function that correctly identified the magic squares, without solving the problem at all.