Skip to main content
deleted 2 characters in body
Source Link
nimi
  • 35.9k
  • 4
  • 34
  • 99

Haskell, 37 36 3331 bytes

g n=[1|oddn=take(n*mod n]>>taken n[2)[-div n 2..]

Unbalanced is indicated by the empty list. Usage example: g 7 -> [-3,-2,-1,0,1,2,3].

@xnor found 35 bytes. Thanks!

Haskell, 37 36 33 bytes

g n=[1|odd n]>>take n[-div n 2..]

Unbalanced is indicated by the empty list. Usage example: g 7 -> [-3,-2,-1,0,1,2,3].

@xnor found 3 bytes. Thanks!

Haskell, 37 36 31 bytes

g n=take(n*mod n 2)[-div n 2..]

Unbalanced is indicated by the empty list. Usage example: g 7 -> [-3,-2,-1,0,1,2,3].

@xnor found 5 bytes. Thanks!

added 113 characters in body
Source Link
nimi
  • 35.9k
  • 4
  • 34
  • 99

Haskell, 37 3636 33 bytes

g n|oddn=[1|odd n=[n]>>take n[-div n 2..div n 2]|1<2=[]]

Unbalanced is indicated by the empty list. Usage example: g 7 -> [-3,-2,-1,0,1,2,3].

Alternatives with the same length are:@xnor found 3 bytes. Thanks!

  • g n=[x|x<-[-div n 2..(n+1)/2],odd n] as suggested by @xnor
  • g n=cycle[[],[-div n 2..div n 2]]!!n

Haskell, 37 36 bytes

g n|odd n=[-div n 2..div n 2]|1<2=[]

Unbalanced is indicated by the empty list. Usage example: g 7 -> [-3,-2,-1,0,1,2,3].

Alternatives with the same length are:

  • g n=[x|x<-[-div n 2..(n+1)/2],odd n] as suggested by @xnor
  • g n=cycle[[],[-div n 2..div n 2]]!!n

Haskell, 37 36 33 bytes

g n=[1|odd n]>>take n[-div n 2..]

Unbalanced is indicated by the empty list. Usage example: g 7 -> [-3,-2,-1,0,1,2,3].

@xnor found 3 bytes. Thanks!

added 150 characters in body
Source Link
nimi
  • 35.9k
  • 4
  • 34
  • 99

Haskell, 37 36 bytes

g n|odd n=[-div n 2..div n 2]|1<2=[]

Unbalanced is indicated by the empty list. Usage example: g 7 -> [-3,-2,-1,0,1,2,3].

Alternatives with the same length are:

  • g n=[x|x<-[-div n 2..(n+1)/2],odd n] as suggested by @xnor
  • g n=cycle[[],[-div n 2..div n 2]]!!n

Haskell, 37 36 bytes

g n|odd n=[-div n 2..div n 2]|1<2=[]

Unbalanced is indicated by the empty list. Usage example: g 7 -> [-3,-2,-1,0,1,2,3].

Haskell, 37 36 bytes

g n|odd n=[-div n 2..div n 2]|1<2=[]

Unbalanced is indicated by the empty list. Usage example: g 7 -> [-3,-2,-1,0,1,2,3].

Alternatives with the same length are:

  • g n=[x|x<-[-div n 2..(n+1)/2],odd n] as suggested by @xnor
  • g n=cycle[[],[-div n 2..div n 2]]!!n
Source Link
nimi
  • 35.9k
  • 4
  • 34
  • 99
Loading