diff --git a/2019/1/day1.go b/2019/1/day1.go index ddc6588..5a3f015 100644 --- a/2019/1/day1.go +++ b/2019/1/day1.go @@ -11,26 +11,20 @@ func main() { inFile, _ := ioutil.ReadFile("input") lines := strings.Split(string(inFile), "\n") - fmt.Printf("Part 1: %d\n", part1(lines)) - fmt.Printf("Part 2: %d\n", part2(lines)) + part1, part2 := solve(lines) + fmt.Printf("Part 1: %d\n", part1) + fmt.Printf("Part 2: %d\n", part2) } -func part1(lines []string) int { +func solve(lines []string) (int, int) { fuel := 0 + fuelRec := 0 for _, line := range lines { mass, _ := strconv.Atoi(line) fuel += cost(mass) + fuelRec += costRec(mass, 0) } - return fuel -} - -func part2(lines []string) int { - fuel := 0 - for _, line := range lines { - mass, _ := strconv.Atoi(line) - fuel += costRec(mass, 0) - } - return fuel + return fuel, fuelRec } func cost(mass int) int { diff --git a/2019/1/day1.rs b/2019/1/day1.rs index 70f4d6d..ebcc36b 100644 --- a/2019/1/day1.rs +++ b/2019/1/day1.rs @@ -24,9 +24,8 @@ fn cost(mass: u32) -> u32 { } fn cost_rec(mass: u32, acc: u32) -> u32 { - let c = cost(mass); - match c { + match cost(mass) { 0 => acc, - _ => cost_rec(c, acc + c) + c => cost_rec(c, acc + c) } }