--- /dev/null
+[package]
+name = "advent_of_code_2019"
+version = "0.1.0"
+authors = ["Greg Burri <greg.burri@gmail.com>"]
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+itertools = "0.8"
\ No newline at end of file
--- /dev/null
+use std::fs;\r
+use std::path::Path;\r
+\r
+pub fn read_list_of_numbers<P: AsRef<Path>>(file: P) -> Vec<i32> {\r
+ fs::read_to_string(file).unwrap().split("\n").map(|line| line.parse::<i32>().unwrap()).collect()\r
+}
\ No newline at end of file
--- /dev/null
+pub fn sum_mass_to_fuel(masses: &[i32]) -> i32 {\r
+ masses.iter().fold(0, |sum, mass| sum + mass_to_fuel(*mass))\r
+}\r
+\r
+pub fn sum_mass_to_fuel_2(masses: &[i32]) -> i32 {\r
+ masses.iter().fold(0, |sum, mass| sum + mass_to_fuel_2(*mass))\r
+}\r
+\r
+pub fn mass_to_fuel(mass: i32) -> i32 {\r
+ mass / 3 - 2\r
+}\r
+\r
+pub fn mass_to_fuel_2(mass: i32) -> i32 {\r
+ let mut sum = 0;\r
+ let mut current_mass = mass;\r
+ loop {\r
+ let fuel = mass_to_fuel(current_mass);\r
+ if fuel <= 0 { break }\r
+ current_mass = fuel;\r
+ sum += fuel;\r
+ }\r
+ sum\r
+}\r
+\r
+#[cfg(test)]\r
+mod tests {\r
+ use super::*;\r
+\r
+ #[test]\r
+ fn simple_cases() {\r
+ assert_eq!(mass_to_fuel(12), 2);\r
+ assert_eq!(mass_to_fuel(14), 2);\r
+ assert_eq!(mass_to_fuel(1969), 654);\r
+ assert_eq!(mass_to_fuel(100756), 33583);\r
+ }\r
+\r
+ #[test]\r
+ fn simple_cases_2() {\r
+ assert_eq!(mass_to_fuel_2(14), 2);\r
+ assert_eq!(mass_to_fuel_2(1969), 966);\r
+ assert_eq!(mass_to_fuel_2(100756), 50346);\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+use std::env;
+
+mod day01;
+mod common;
+
+fn day01() {
+ let masses = common::read_list_of_numbers("data/day01.input");
+ println!("Day01 part1: {}", day01::sum_mass_to_fuel(&masses));
+ println!(" part2: {}", day01::sum_mass_to_fuel_2(&masses));
+}
+
+fn do_day(n: i32) {
+ match n {
+ 1 => day01 (),
+ _ => panic!("Unknown day: {}", n)
+ }
+}
+
+fn main() {
+ println!("https://adventofcode.com/2019");
+
+ let args: Vec<String> = env::args().skip(1).collect();
+
+ if args.iter().count() == 0 {
+ println!("ASD");
+ } else {
+ for arg in args {
+ do_day(arg.parse::<i32>().unwrap());
+ //println!("{}", arg);
+ }
+ }
+}