Comment by sannysanoff

4 months ago

while both versions are O(N^2), your version is slower because comparison operation, which affects execution speed. This is suboptimal.

  q)x:1000
  q)\t:1000 sum (til x)=/:(til x)
  889
  q)\t:1000 sum (til x)=/:(til x)
  871
  q)\t:1000 sum (2#x)#1,x#0
  602
  q)\t:1000 sum (2#x)#1,x#0
  599

upd: in ngn/k, situation is opposite ;-o