day 1 full
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/target
|
||||
**/*.rs.bk
|
||||
6
Cargo.lock
generated
Normal file
6
Cargo.lock
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "aoc_2019"
|
||||
version = "0.1.0"
|
||||
|
||||
9
Cargo.toml
Normal file
9
Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "aoc_2019"
|
||||
version = "0.1.0"
|
||||
authors = ["Johannes <jschaef@mail.uni-paderborn.de>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
100
input/day01.txt
Normal file
100
input/day01.txt
Normal file
@@ -0,0 +1,100 @@
|
||||
70102
|
||||
60688
|
||||
105331
|
||||
127196
|
||||
141253
|
||||
118164
|
||||
67481
|
||||
75634
|
||||
60715
|
||||
84116
|
||||
51389
|
||||
52440
|
||||
84992
|
||||
87519
|
||||
85765
|
||||
124479
|
||||
97873
|
||||
85437
|
||||
94902
|
||||
124969
|
||||
70561
|
||||
144601
|
||||
128042
|
||||
67596
|
||||
136905
|
||||
111849
|
||||
100389
|
||||
135608
|
||||
91006
|
||||
77385
|
||||
52100
|
||||
64728
|
||||
127796
|
||||
114893
|
||||
82414
|
||||
66565
|
||||
73704
|
||||
110396
|
||||
142722
|
||||
107813
|
||||
149628
|
||||
131729
|
||||
118421
|
||||
56566
|
||||
84962
|
||||
108120
|
||||
108438
|
||||
81536
|
||||
55238
|
||||
77072
|
||||
132575
|
||||
82716
|
||||
50641
|
||||
57320
|
||||
89661
|
||||
97094
|
||||
134713
|
||||
142451
|
||||
128541
|
||||
53527
|
||||
116088
|
||||
101909
|
||||
124349
|
||||
103812
|
||||
108324
|
||||
72981
|
||||
114488
|
||||
78738
|
||||
78523
|
||||
129146
|
||||
103007
|
||||
68506
|
||||
102227
|
||||
93507
|
||||
94557
|
||||
105867
|
||||
125514
|
||||
109130
|
||||
146102
|
||||
100876
|
||||
143549
|
||||
85753
|
||||
97589
|
||||
90892
|
||||
104287
|
||||
70930
|
||||
53847
|
||||
94687
|
||||
135370
|
||||
76024
|
||||
76156
|
||||
101006
|
||||
128349
|
||||
58134
|
||||
110849
|
||||
149176
|
||||
136728
|
||||
79054
|
||||
136740
|
||||
131081
|
||||
5
src/main.rs
Normal file
5
src/main.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
mod tasks;
|
||||
|
||||
fn main() {
|
||||
tasks::day01::run();
|
||||
}
|
||||
36
src/tasks/day01.rs
Normal file
36
src/tasks/day01.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
use std::fs;
|
||||
|
||||
pub fn run() {
|
||||
let content = fs::read_to_string("input/day01.txt").unwrap();
|
||||
task1(&content);
|
||||
task2(&content);
|
||||
}
|
||||
|
||||
fn task1(content: &String) {
|
||||
let fuel: i32 = content
|
||||
.lines()
|
||||
.map(|line| line.parse::<i32>().unwrap())
|
||||
.map(|mass| mass / 3 - 2)
|
||||
.sum();
|
||||
|
||||
println!("Task 1: {}", fuel);
|
||||
}
|
||||
|
||||
fn task2(content: &String) {
|
||||
fn while_fun(mass: i32) -> i32 {
|
||||
let to_add = mass / 3 - 2;
|
||||
if to_add < 1 {
|
||||
0
|
||||
} else {
|
||||
to_add + while_fun(to_add)
|
||||
}
|
||||
};
|
||||
|
||||
let fuel: i32 = content
|
||||
.lines()
|
||||
.map(|line| line.parse::<i32>().unwrap())
|
||||
.map(while_fun)
|
||||
.sum();
|
||||
|
||||
println!("Task 2: {}", fuel);
|
||||
}
|
||||
1
src/tasks/mod.rs
Normal file
1
src/tasks/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod day01;
|
||||
Reference in New Issue
Block a user