Created
December 2, 2019 02:00
-
-
Save timsneath/3db1f9415b9842f47e6e97d8a4aa45fd to your computer and use it in GitHub Desktop.
Advent of Code: Day 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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