Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
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].
g 7
[-3,-2,-1,0,1,2,3]
@xnor found 35 bytes. Thanks!
g n=[1|odd n]>>take n[-div n 2..]
@xnor found 3 bytes. Thanks!
g n=take(n*mod n 2)[-div n 2..]
@xnor found 5 bytes. Thanks!
g n|oddn=[1|odd n=[n]>>take n[-div n 2..div n 2]|1<2=[]]
Alternatives with the same length are:@xnor found 3 bytes. Thanks!
g n=[x|x<-[-div n 2..(n+1)/2],odd n]
g n=cycle[[],[-div n 2..div n 2]]!!n
g n|odd n=[-div n 2..div n 2]|1<2=[]
Alternatives with the same length are: