« first day (2391 days earlier)      last day (270 days later) » 

10:22 AM
Any good solution to leetcode.com/problems/two-sum?
 
 
4 hours later…
2:15 PM
Subtract and compare?
 
@LdBeth Problem is to avoid using the same element twice.
 
The numbers are guaranteed unique?
 
no.
But there's a guarantee that there's only one answer.
 
2:30 PM
(n e. targt-n)#n NB. n numbers targt target value
 
you're supposed to return the indices, so I. instead of #n but this fails on e.g. targt=:6 and n=:3 2 4
 
⊃⍸(∘.<⍨⍳≢nums)∧target=∘.+⍨nums ?
 
Yes, that can work.
 
I tried starting with target-nums but couldn't get anywhere...
 
So you have {⊃⍸(∘.<⍨⍳≢⍵)∧⍺=∘.+⍨⍵}
I had {⊃(⍸⍺=∘.+⍨⍵)~2⍴¨⍋⍵}
I think you can write ∘.<⍨⍳≢⍵ as ∘.=⍨⍋⍵
No, that doesn't work.
 
2:46 PM
instead of ⍳≢ to save a character?
 
Yes. But also makes the code very obscure and less efficient.
With under, we could write {⍸0⍢(1 1∘⍉)⍺=∘.+⍨⍵}
 
Under can take an array left operand?
 
Under doesn't exist :-)
 
imo, @ should have been structural under, an it certainly does take an array operand as constant function.
 
3:01 PM
Would things like 0@(2∘|)⍳5 still work?
 
No. Current @ has implicit / or (Select), but you'd need to do that yourself with Under, so it'd be 0@(2∘|⍛/)⍳5
 
3:24 PM
That seems very powerful, but I also like the simplicity of things like '-'@(=∘' ')
Speaking of which, how would you do '-'@(=∘' ') without @? I guess {(⍵,'-')[(⍳≢⍵)⌈(1+≢⍵)×' '=⍵]} works...
If you were going in the other direction, {⍵/⍨¯1*'-'=⍵} works :)
 
@Adám I.(d e. n)*.(d e. n#~ -. ~: n)+.(d ~: n) were t is target n is numbers and d is t-n
I tried to avoid outer product because that caps the complexity to O(n*2)
 
4:20 PM
@rabbitgrowth {r←⍵ ⋄ ((r=' ')/r)←'-' ⋄ r}
 
 
2 hours later…
5:58 PM
And in APL:
      9(-⍸⍤(∊∧≠∨⊣∊~⍤≠⍤⊢⊢⍤/⊢)⊢)2 7 11 15
1 2
I suppose the complexity is O(n×⍟n)?
 

« first day (2391 days earlier)      last day (270 days later) »