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 Revisions

1 of 6
ngn
  • 15.6k
  • 2
  • 45
  • 90

#Dyalog APL, 34 bytes

'- |'[2+∘.(≤-(1+=)×ばつ2|⌈)⍨(⌽,0,⊢)⍳⎕]

Right to left:

⍳⎕ is 1 2 ... N

(⌽,0,⊢) is a train that turns it into -N ... -1 0 1 ... N

∘.( )⍨ executes the parentheses for every pair of coordinates ⍺ ⍵

the train (≤-(1+=)×ばつ2|⌈) or its dfn equivalent {(⍺≤⍵)-(1+⍺=⍵)×ばつ2|⍺⌈⍵} produces a matrix like:

 ̄1 ̄1 ̄1 ̄1 ̄1 ̄1 ̄1 ̄1 ̄1 ̄1 ̄1
 0 1 0 0 0 0 0 0 0 1 0
 0 1 ̄1 ̄1 ̄1 ̄1 ̄1 ̄1 ̄1 1 0
 0 1 0 1 0 0 0 1 0 1 0
 0 1 0 1 ̄1 ̄1 ̄1 1 0 1 0
 0 1 0 1 0 1 0 1 0 1 0
 0 1 0 1 ̄1 ̄1 ̄1 1 0 1 0
 0 1 0 1 0 0 0 1 0 1 0
 0 1 ̄1 ̄1 ̄1 ̄1 ̄1 ̄1 ̄1 1 0
 0 1 0 0 0 0 0 0 0 1 0
 ̄1 ̄1 ̄1 ̄1 ̄1 ̄1 ̄1 ̄1 ̄1 ̄1 ̄1

'- |'[2+ ] makes these valid indices in ⎕IO=1 and picks the corresponding characters

ngn
  • 15.6k
  • 2
  • 45
  • 90

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