« first day (990 days earlier)      last day (1654 days later) » 

10:54 AM
@ngn I finally got around to looking at this and I'm confused by the bit in the inner dfn that says (w∘≥∧⍳⍨=⍳∘≢). How does it check for distinct sums?
⎕←3{m←+\+\1,⍵⍴⍺-2 ⋄ w←⍵ ⋄ ⊃a/⍨⍵=+/↑a←{a/⍨(w∘≥∧⍳⍨=⍳∘≢)+/↑a←,m∘.,⍵}⍣⍺,⊂⍬}1
Also this vs
⎕←3{m←+\+\0 1,⍵⍴⍺-2 ⋄ w←⍵ ⋄ ⊃a/⍨⍵=+/↑a←{a/⍨(w∘≥∧⍳⍨=⍳∘≢)+/↑a←,m∘.,⍵}⍣⍺,⊂⍬}1
 
ngn
@Sherlock9 are you familiar with dyadic ⍳?
⍳⍨ returns the index of the first occurrence of each element
 
Welp, the bot hath disappeared and it's Shabbat for another 5 hours or so for Adám
@ngn Ahh
 
ngn
so ⍳⍨=⍳∘≢ or (⍳⍨⍵)=⍳≢⍵ returns 1s for the first occurrences and 0s for all other
(where is the argument of the train in parentheses, not the outer )
 
⎕←{a/⍨(⍳⍨=⍳∘≢){⍵[⍋⍵]}¨a←⍸0=-/¨×⍨⍳3⍴⍵}30
Which if the bot was alive at the moment would return only the one version of each Pythagorean triple!
Hm I should also filter down to primitive triples
 
ngn
11:10 AM
there's a much more efficient way to generate primitive triples
that is, if you care about performance more than about code size
 
I don't know enough k yet to read that easily
 
ngn
@Sherlock9 just read the comment after the `` /``
 
@ngn Ah yes, in that case I'm familiar with that method
I have a version somewhere. One moment
 
Oh man I found the real old version but not the one I did with complex numbers {(-/⍵*2)(2××/⍵)(+/⍵*2)}¨(((2|+/¨)∧(1=∨/¨)∧>/¨){⍺/⍵}⊢),⍳{2⍴⍵}
 
 
2 hours later…
ngn
1:16 PM
@Sherlock9 if z=a+ib, then the real and imaginary parts of z^2 = a^2-b^2 + i2ab are two elements from the triple. the third one could be extracted from z × conj(z)
 
⎕←{|9 11 10∘.○×⍨(⊣+0J1×⊢)/¨b/⍨(1=∨/)¨b←,↓0 ¯1+⍤1↑2×⍳2⍴⍵}6
@ngn Ah right the bot's dead. Well that's the new version
 
ngn
argh, of course, i should have thought of 10○z ←→ |z ←→ sqrt(a^2 + b^2)
@Sherlock9 yep, this expression does look like something to be proud of
hm, let's see what can be simplified there...
 
@ngn :D
@ngn Oh yes please
 
ngn
@Sherlock9 (⊣+¯11○⊢)/¨ -> 0j1∘⊥¨
 
@ngn That version was actually in the original code, but Richard Park suggested (⊣+0J1×⊢) because it is apparently faster. Let me check
 
ngn
1:26 PM
they aren't exactly equivalent, the Re and Im parts are swapped, but here it doesn't matter
 
@ngn Oh wait I misread! One moment
Oh dang it's both faster and fewer bytes
 
ngn
for speed, avoiding ¨ and avoiding nested arrays would help the most
at least usually it does
 
ngn
1:41 PM
@Sherlock9 this should be faster: {⍉↓⍉|9 11 10∘.○×⍨(0j1×i)∘.+¯1+i←2×⍳⍵}
 
@ngn I was trying to create something like that! Amazing!
And we don't even have to have the final transpose
 
ngn
we probably don't need the split () either
 
  {|9 11 10∘.○×⍨(⊣+0J1×⊢)/¨b/⍨(1=∨/)¨b←,↓0 ¯1+⍤1↑2×⍳2⍴⍵}30 → 7.7E¯4 |   0% ⎕⎕⎕⎕
  {|9 11 10∘.○×⍨(⊣+¯11○⊢)/¨b/⍨(1=∨/)¨b←,↓0 ¯1+⍤1↑2×⍳2⍴⍵}30 → 9.2E¯4 | +18% ⎕⎕⎕⎕
  {|9 11 10∘.○×⍨0j1∘⊥¨b/⍨(1=∨/)¨b←,↓0 ¯1+⍤1↑2×⍳2⍴⍵}30      → 5.2E¯4 | -33% ⎕⎕⎕⎕
* {⍉|9 11 10∘.○×⍨(0j1×i)∘.+¯1+i←2×⍳⍵}30                    → 2.1E¯5 | -98% ⎕
Oh my goodness it's so fast
Oh that's right we're not checking for primitives
That is completely fine for such a speed up. I could probably check at the end. One moment
 
2:06 PM
Found it
{|9 11 10∘.○×⍨(⊣+0J1×⊢)/¨b/⍨(1=∨/)¨b←,↓0 ¯1+⍤1↑2×⍳2⍴⍵}30 → 7.7E¯4 |   0% ⎕⎕⎕⎕
  {|9 11 10∘.○×⍨(⊣+¯11○⊢)/¨b/⍨(1=∨/)¨b←,↓0 ¯1+⍤1↑2×⍳2⍴⍵}30 → 9.3E¯4 | +19% ⎕⎕⎕⎕
  {|9 11 10∘.○×⍨0j1∘⊥¨b/⍨(1=∨/)¨b←,↓0 ¯1+⍤1↑2×⍳2⍴⍵}30      → 5.3E¯4 | -32% ⎕⎕⎕⎕
* {m/⍨(1=∨/)↑m←,↓⍉|9 11 10∘.○×⍨(0J1×i)∘.+¯1+i←2×⍳⍵}30      → 1.1E¯4 | -87% ⎕⎕⎕⎕
 
@Sherlock9 vs my solution
 
ngn
      ⎕io←1
      f←{|9 11 10∘.○×⍨(⊣+0J1×⊢)/¨b/⍨(1=∨/)¨b←,↓0 ¯1+⍤1↑2×⍳2⍴⍵}
      g←{m/⍨(1=∨/)↑m←,↓⍉|9 11 10∘.○×⍨(0J1×i)∘.+¯1+i←2×⍳⍵}
      (f 30)≡⍉↑g 30
0
@Sherlock9 shouldn't these ^ match?
 
Ah yeah I'm trying to figure out which of these display formats works best
Sorry for making it harder to compare
 
2:22 PM
 
ngn
@dzaima ah, right... so they were the same set of triples in different order
@Sherlock9 removing the parens around 1=∨/ gives me 2% performance :)
{↓⍉m/⍨1=∨⌿m←|9 11 10∘.○×⍨,(0J1×i)∘.+¯1+i←2×⍳⍵} for another 4% (or 8% without the ↓⍉)
 
@dzaima Wow yours is fast
@ngn Duly noted
  {↓⍉m/⍨1=∨⌿m←|9 11 10∘.○×⍨,(0J1×i)∘.+¯1+i←2×⍳⍵}1000        → 1.3E¯1 |   0% ⎕⎕⎕
* {|9 11 10∘.○×⍨0J1⊥↑(1=∨/b)/¨b←(⍵⌿t)((⍵×⍵)⍴¯1+t←2×⍳⍵)}1000 → 4.7E¯2 | -65% ⎕⎕⎕
 
ngn
@dzaima hehe, i was working on the same but i'm too slow :)
 
 
4 hours later…
6:56 PM
I appear to have made it slower even with avoiding ¨
  {(|⊃-/s)(2×⊃×/d)(⊃+/s←×⍨d←(1=∨/b)/¨b←(⍵⌿t)((⍵×⍵)⍴¯1+t←2×⍳⍵))}1000 → 3.1E¯2 | 0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  {(|-⌿s)(2××⌿d)(+⌿s←×⍨d←(1=∨⌿b)/b←↑(⍵⌿t)((⍵×⍵)⍴¯1+t←2×⍳⍵))}1000    → 3.9E¯2 | +23% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
 
@Sherlock9 ¨ is only bad when it's used on an array with many items. Here it's used on just 2 items, in which case ¨ itself doesn't cost pretty much anything, and you're losing performance with having to copy items around
 
ngn
a little faster: {d←(1=∨/b)/¨b←(⍵⌿t)((⍵×⍵)⍴¯1+2×t←⍳⍵)⋄d[1]×←2⋄s←×⍨d⋄⊃¨(|-/s)(2××/d)(+/s)}, -6% on my laptop
uh... ignore that, slower on tio
 
 
2 hours later…
8:39 PM
)about
:-(
 
ngn
@Sherlock9 @dzaima ~ -75% using a sieving technique
i'll try to simplify it...
 
ngn
9:05 PM
maybe a little simpler:
r←{⎕io←0⋄a b c←⍵⋄a+c×⍳⌈c÷⍨b-a} ⍝ python range()
h←{⊂,a⊣{d←1+2×⍵⋄a[r d(n+1)d;r(⍵+1)(n+1)d]←0}¨⍳⌊⍵÷2⊣a←1⍴⍨2⍴n←⍵} ⍝ calculate bitmask for /
g←{⊃¨(|-/s)(2××/d)(+/s←×⍨d←(h⍵)/¨(⍵⌿t)((⍵×⍵)⍴¯1+t←2×⍳⍵))}
 

« first day (990 days earlier)      last day (1654 days later) »