Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link

#APL(NARS), chars 49, bytes 98

APL(NARS), chars 49, bytes 98

{0{∧/ ̄1↓⍵≤1⌽⍵:⍺⋄(⍺+1)∇⍵[d],⍵[i∼d←↑ ̈i⊂⍨2∣i←⍳≢⍵]}⍵}

why use in the deepest loop, one algo that should be nlog(n), when we can use one linear n? just for few bytes more? [⍵≡⍵[⍋⍵] O(nlog n) and the confront each element for see are in order using ∧/ ̄1↓⍵≤1⌽⍵ O(n)]test:

 f←{0{∧/ ̄1↓⍵≤1⌽⍵:⍺⋄(⍺+1)∇⍵[d],⍵[i∼d←↑ ̈i⊂⍨2∣i←⍳≢⍵]}⍵}
 f ,1
0
 f 1 2 3
0
 f 1,9,8,7,6,5,4,3,2,10
3
 f 1,3,5,7,9,11,13,15,17,19,2,4,6,8,10,12,14,16,18,20
17

#APL(NARS), chars 49, bytes 98

{0{∧/ ̄1↓⍵≤1⌽⍵:⍺⋄(⍺+1)∇⍵[d],⍵[i∼d←↑ ̈i⊂⍨2∣i←⍳≢⍵]}⍵}

why use in the deepest loop, one algo that should be nlog(n), when we can use one linear n? just for few bytes more? [⍵≡⍵[⍋⍵] O(nlog n) and the confront each element for see are in order using ∧/ ̄1↓⍵≤1⌽⍵ O(n)]test:

 f←{0{∧/ ̄1↓⍵≤1⌽⍵:⍺⋄(⍺+1)∇⍵[d],⍵[i∼d←↑ ̈i⊂⍨2∣i←⍳≢⍵]}⍵}
 f ,1
0
 f 1 2 3
0
 f 1,9,8,7,6,5,4,3,2,10
3
 f 1,3,5,7,9,11,13,15,17,19,2,4,6,8,10,12,14,16,18,20
17

APL(NARS), chars 49, bytes 98

{0{∧/ ̄1↓⍵≤1⌽⍵:⍺⋄(⍺+1)∇⍵[d],⍵[i∼d←↑ ̈i⊂⍨2∣i←⍳≢⍵]}⍵}

why use in the deepest loop, one algo that should be nlog(n), when we can use one linear n? just for few bytes more? [⍵≡⍵[⍋⍵] O(nlog n) and the confront each element for see are in order using ∧/ ̄1↓⍵≤1⌽⍵ O(n)]test:

 f←{0{∧/ ̄1↓⍵≤1⌽⍵:⍺⋄(⍺+1)∇⍵[d],⍵[i∼d←↑ ̈i⊂⍨2∣i←⍳≢⍵]}⍵}
 f ,1
0
 f 1 2 3
0
 f 1,9,8,7,6,5,4,3,2,10
3
 f 1,3,5,7,9,11,13,15,17,19,2,4,6,8,10,12,14,16,18,20
17
added 219 characters in body
Source Link
user58988
user58988

#APL(NARS), chars 4649, bytes 9298

{0{⍵≡⍵[⍋⍵]∧/ ̄1↓⍵≤1⌽⍵:⍺⋄(⍺+1)∇⍵[d],⍵[i∼d←↑ ̈i⊂⍨2∣i←⍳≢⍵]}⍵}

testwhy use in the deepest loop, one algo that should be nlog(n), when we can use one linear n? just for few bytes more? [⍵≡⍵[⍋⍵] O(nlog n) and the confront each element for see are in order using ∧/ ̄1↓⍵≤1⌽⍵ O(n)]test:

 f←{0{⍵≡⍵[⍋⍵]∧/ ̄1↓⍵≤1⌽⍵:⍺⋄(⍺+1)∇⍵[d],⍵[i∼d←↑ ̈i⊂⍨2∣i←⍳≢⍵]}⍵}
 f ,1
0
 f 1 2 3
0
 f 1,9,8,7,6,5,4,3,2,10
3
 f 1,3,5,7,9,11,13,15,17,19,2,4,6,8,10,12,14,16,18,20
17

#APL(NARS), chars 46, bytes 92

{0{⍵≡⍵[⍋⍵]:⍺⋄(⍺+1)∇⍵[d],⍵[i∼d←↑ ̈i⊂⍨2∣i←⍳≢⍵]}⍵}

test:

 f←{0{⍵≡⍵[⍋⍵]:⍺⋄(⍺+1)∇⍵[d],⍵[i∼d←↑ ̈i⊂⍨2∣i←⍳≢⍵]}⍵}
 f ,1
0
 f 1 2 3
0
 f 1,9,8,7,6,5,4,3,2,10
3
 f 1,3,5,7,9,11,13,15,17,19,2,4,6,8,10,12,14,16,18,20
17

#APL(NARS), chars 49, bytes 98

{0{∧/ ̄1↓⍵≤1⌽⍵:⍺⋄(⍺+1)∇⍵[d],⍵[i∼d←↑ ̈i⊂⍨2∣i←⍳≢⍵]}⍵}

why use in the deepest loop, one algo that should be nlog(n), when we can use one linear n? just for few bytes more? [⍵≡⍵[⍋⍵] O(nlog n) and the confront each element for see are in order using ∧/ ̄1↓⍵≤1⌽⍵ O(n)]test:

 f←{0{∧/ ̄1↓⍵≤1⌽⍵:⍺⋄(⍺+1)∇⍵[d],⍵[i∼d←↑ ̈i⊂⍨2∣i←⍳≢⍵]}⍵}
 f ,1
0
 f 1 2 3
0
 f 1,9,8,7,6,5,4,3,2,10
3
 f 1,3,5,7,9,11,13,15,17,19,2,4,6,8,10,12,14,16,18,20
17
Source Link
user58988
user58988

#APL(NARS), chars 46, bytes 92

{0{⍵≡⍵[⍋⍵]:⍺⋄(⍺+1)∇⍵[d],⍵[i∼d←↑ ̈i⊂⍨2∣i←⍳≢⍵]}⍵}

test:

 f←{0{⍵≡⍵[⍋⍵]:⍺⋄(⍺+1)∇⍵[d],⍵[i∼d←↑ ̈i⊂⍨2∣i←⍳≢⍵]}⍵}
 f ,1
0
 f 1 2 3
0
 f 1,9,8,7,6,5,4,3,2,10
3
 f 1,3,5,7,9,11,13,15,17,19,2,4,6,8,10,12,14,16,18,20
17

AltStyle によって変換されたページ (->オリジナル) /