Ad

Since I have to work on an Android project which doesn't use Gradle as a build tool, so I always have to find the aar library and extract the classes.jar file from it. Doing it manually was very boring. So I decided to write my own Python (because it's interpreted) script to do this task. The code I have written works very well, but it can be improved by making it cross-platform, efficient, etc.

So let's start to improve it.

Gist: https://gist.github.com/pavi2410/b1ba0ae03e4b459846c72453204394a6

Note that you have to run this script on your PC, unfortunately.

import zipfile, os

cd = os.getcwd()
for file in os.listdir(cd):
	if file.endswith(".aar"):
		print("Got aar: " + file)
		with zipfile.ZipFile(cd + "\\" + file) as aar:
			aar.extract("classes.jar", cd)
			print("Extracted aar")
		os.rename("classes.jar", os.path.splitext(file)[0] + ".jar")

Shortest code possible

Code
Diff
  • def euler(num):
        sum = 0
        for x in range(num):
            if x%3==0 or x%5==0:
                sum += x
        return sum
    • def euler(num):
    • #0 3 6 9 12 15
    • #0 5 10 15
    • #0 3 2 1 3 1 2 3
    • inc = [3, 2, 1, 3, 1, 2, 3]
    • x = 0
    • sum = 0
    • i = 0
    • while x < num:
    • sum += x
    • x += inc[i]
    • i += 1
    • if i == 7:
    • i = 0
    • for x in range(num):
    • if x%3==0 or x%5==0:
    • sum += x
    • return sum