Ryan is an engineer in the Sacramento Area with a focus in Python, Ruby, and Rust. Bash/Python Exercism mentor. Coding, physics, calculus, music, woodworking. Looking for work!
This was a good ramp into the month! Here's my Rust solution. :)
/// Day 1: The Tyranny of the Rocket Equation/// /// Calculate the amount of fuel required to launch your spaceship!usestd::fs::File;usestd::io::prelude::*;usestd::io::BufReader;/// Calculate the fuel required to lift one module, based on its massfnfuel_required(mass:&usize)->usize{(mass/3)-2}/// Calculates the fuel required to lift one module, but factors in the/// weight of the fuel as wellfnrecursive_fuel_required(mass:&usize)->usize{if*mass<=6{0}else{letnext_mass=(mass/3)-2;next_mass+recursive_fuel_required(&next_mass)}}/// Calculate the total fuel requirements for the launchfnfuel_requirements(module_masses:Vec<usize>)->usize{module_masses.iter().map(recursive_fuel_required).sum()}/// Parses the input file, which is a bunch of numbers, one per linefnparse_input()->Vec<usize>{letbuf=BufReader::new(File::open("data/day1.txt").unwrap());buf.lines().map(|result|result.unwrap()).map(|line|line.parse::<usize>().unwrap()).collect()}/// Main day 1 codepubfnrun(){letdata=parse_input();lettotal_requirements=fuel_requirements(data);println!("Total fuel required: {}",total_requirements);}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This was a good ramp into the month! Here's my Rust solution. :)