import math
import functools
import operator
import sys
import os

if len(sys.argv) < 2:
	print(f'usage: {os.path.basename(sys.argv[1])} <input.txt>')
	exit(1)

def fuel_for_mass(mass):
	fuel_req = math.floor(mass / 3) - 2
	if fuel_req < 0:
		return 0
	return fuel_req + fuel_for_mass(fuel_req)

with open(sys.argv[1], 'r') as f:
	masses = f.readlines()

print(functools.reduce(operator.add, map(lambda mass: fuel_for_mass(int(mass)), masses)))
import math
import functools
import operator
import sys
import os

if len(sys.argv) < 2:
	print(f'usage: {os.path.basename(sys.argv[1])} <input.txt>')
	exit(1)

def fuel_for_mass(mass):
	fuel_req = math.floor(mass / 3) - 2
	if fuel_req < 0:
		return 0
	return fuel_req + fuel_for_mass(fuel_req)

with open(sys.argv[1], 'r') as f:
	masses = f.readlines()

print(functools.reduce(operator.add, map(lambda mass: fuel_for_mass(int(mass)), masses)))