Skip to main content
Commonmark migration
Source Link

#Pyth, 11 bytes

Pyth, 11 bytes

Ms+Gm_+GdSH 

A function g that takes input of n and p via argument and prints the result. It can be called in the form gn p.

Try it online

How it works

Ms+Gm_+GdSH Function g. Inputs: G, H M g=lambda G,H: SH 1-indexed range, yielding [1, 2, 3, ..., H] m_+Gd Map lambda d:-(G+d) over the above, yielding [-(G+1), -(G+2), -(G+3), ..., -(G+H)] +G Add G to the above, yielding [G, -(G+1), -(G+2), -(G+3), ..., -(G+H)] s Reduce on addition with base case 0, yielding G-(G+1)-(G+2)-(G+3)... -(G+H) Implicitly print 

#Pyth, 11 bytes

Ms+Gm_+GdSH 

A function g that takes input of n and p via argument and prints the result. It can be called in the form gn p.

Try it online

How it works

Ms+Gm_+GdSH Function g. Inputs: G, H M g=lambda G,H: SH 1-indexed range, yielding [1, 2, 3, ..., H] m_+Gd Map lambda d:-(G+d) over the above, yielding [-(G+1), -(G+2), -(G+3), ..., -(G+H)] +G Add G to the above, yielding [G, -(G+1), -(G+2), -(G+3), ..., -(G+H)] s Reduce on addition with base case 0, yielding G-(G+1)-(G+2)-(G+3)... -(G+H) Implicitly print 

Pyth, 11 bytes

Ms+Gm_+GdSH 

A function g that takes input of n and p via argument and prints the result. It can be called in the form gn p.

Try it online

How it works

Ms+Gm_+GdSH Function g. Inputs: G, H M g=lambda G,H: SH 1-indexed range, yielding [1, 2, 3, ..., H] m_+Gd Map lambda d:-(G+d) over the above, yielding [-(G+1), -(G+2), -(G+3), ..., -(G+H)] +G Add G to the above, yielding [G, -(G+1), -(G+2), -(G+3), ..., -(G+H)] s Reduce on addition with base case 0, yielding G-(G+1)-(G+2)-(G+3)... -(G+H) Implicitly print 
Explanation added
Source Link

#Pyth, 11 bytes

Ms+Gm_+GdSH 

A function g that takes input of n and p via argument and prints the result. It can be called in the form gn p.

Try it online

[Explanation coming later]How it works

Ms+Gm_+GdSH Function g. Inputs: G, H M g=lambda G,H: SH 1-indexed range, yielding [1, 2, 3, ..., H] m_+Gd Map lambda d:-(G+d) over the above, yielding [-(G+1), -(G+2), -(G+3), ..., -(G+H)] +G Add G to the above, yielding [G, -(G+1), -(G+2), -(G+3), ..., -(G+H)] s Reduce on addition with base case 0, yielding G-(G+1)-(G+2)-(G+3)... -(G+H) Implicitly print 

#Pyth, 11 bytes

Ms+Gm_+GdSH 

A function g that takes input of n and p via argument and prints the result. It can be called in the form gn p.

Try it online

[Explanation coming later]

#Pyth, 11 bytes

Ms+Gm_+GdSH 

A function g that takes input of n and p via argument and prints the result. It can be called in the form gn p.

Try it online

How it works

Ms+Gm_+GdSH Function g. Inputs: G, H M g=lambda G,H: SH 1-indexed range, yielding [1, 2, 3, ..., H] m_+Gd Map lambda d:-(G+d) over the above, yielding [-(G+1), -(G+2), -(G+3), ..., -(G+H)] +G Add G to the above, yielding [G, -(G+1), -(G+2), -(G+3), ..., -(G+H)] s Reduce on addition with base case 0, yielding G-(G+1)-(G+2)-(G+3)... -(G+H) Implicitly print 
Source Link

#Pyth, 11 bytes

Ms+Gm_+GdSH 

A function g that takes input of n and p via argument and prints the result. It can be called in the form gn p.

Try it online

[Explanation coming later]