Skip to content

Instantly share code, notes, and snippets.

@timsneath
Created December 2, 2019 02:00
Show Gist options
  • Select an option

  • Save timsneath/3db1f9415b9842f47e6e97d8a4aa45fd to your computer and use it in GitHub Desktop.

Select an option

Save timsneath/3db1f9415b9842f47e6e97d8a4aa45fd to your computer and use it in GitHub Desktop.
Advent of Code: Day 1
import 'dart:io';
int fuelMassForModule(int moduleMass, [int massSoFar = 0]) {
var mass = (moduleMass / 3).floor() - 2;
if (mass <= 0) {
return 0;
} else {
return mass + fuelMassForModule(mass, massSoFar);
}
}
void main() async {
final input = File('day1_input.txt');
final lines = await input.readAsLines();
var totalMass = 0;
for (var line in lines) {
var moduleMass = int.parse(line);
totalMass += fuelMassForModule(moduleMass);
}
print('Total mass is: $totalMass');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment