Menu
Newbedev LogoNEWBEDEV Python Javascript Linux Cheat sheet
Newbedev LogoNEWBEDEV
  • Python 1
  • Javascript
  • Linux
  • Cheat sheet
  • Contact

Add an array with itself

Python 3, 67 65 42 bytes

Uses the fact that the sum of an empty array is 0

lambda x,y:[sum(x[i::y])for i in range(y)]

Try it online!


MATL, 4 bytes

e!Xs

Try it online!

First bit of MATL code I've written! Takes two inputs, a as a row vector (comma-separated) and l as a number. Works out to be

e          # reshape `a` into `l` rows (auto pads with 0)
 !         # transpose
  Xs       # sum down the columns

Jelly, 7 6 bytes

1 byte thanks to Dennis.

;0$¡sS

Try it online!

Tags:

Code Golf

Array Manipulation

Related

Approximate floating point number with n-digit precision Calculate the longest series of 1's in an integer's binary value Dizzy integer enumeration Hidden sentences in the license plates Output with the same number of digits of pi as the length of the code Chaos is an ASCII ladder Exponentiation Sequence Generating Word Grids Sort the points by linear distance in a 3D space Somewhere On The Tube ...But On Which Lines? Weird grading system Gimli, make it even shorter?

Recent Posts

Pandas how to find column contains a certain value Recommended way to install multiple Python versions on Ubuntu 20.04 Build super fast web scraper with Python x100 than BeautifulSoup How to convert a SQL query result to a Pandas DataFrame in Python How to write a Pandas DataFrame to a .csv file in Python
© 2021 newbedevPrivacy Policy