first
This commit is contained in:
commit
d72a5b20fc
11 changed files with 1106 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
11
.idea/advent_of_code.iml
generated
Normal file
11
.idea/advent_of_code.iml
generated
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="EMPTY_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/advent_of_code.iml" filepath="$PROJECT_DIR$/.idea/advent_of_code.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal file
|
@ -0,0 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "advent_of_code"
|
||||
version = "0.1.0"
|
8
Cargo.toml
Normal file
8
Cargo.toml
Normal file
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "advent_of_code"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
26
src/day_1_1.rs
Normal file
26
src/day_1_1.rs
Normal file
|
@ -0,0 +1,26 @@
|
|||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Iter;
|
||||
|
||||
pub fn solve_day_1_1() {
|
||||
// --snip--
|
||||
let file_path = "/home/clement/RustroverProjects/advent_of_code/src/inputs/input_1.txt";
|
||||
println!("In file {file_path}");
|
||||
|
||||
let (mut l_list, mut r_list) : (Vec<i32>, Vec<i32>) = fs::read_to_string(file_path)
|
||||
.expect("Should have been able to read the file")
|
||||
.split('\n')
|
||||
.map(|s|{
|
||||
let mut splited = s.split_whitespace();
|
||||
(
|
||||
splited.next().unwrap().parse::<i32>().unwrap(),
|
||||
splited.next().unwrap().parse::<i32>().unwrap()
|
||||
)
|
||||
}).unzip();
|
||||
|
||||
l_list.sort();
|
||||
r_list.sort();
|
||||
let ans = l_list.iter().zip(r_list.iter()).map(|(l, r)| (l - r).abs()).sum::<i32>();
|
||||
println!("{}", ans);
|
||||
|
||||
}
|
22
src/day_1_2.rs
Normal file
22
src/day_1_2.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Iter;
|
||||
|
||||
pub fn solve_day_1_2() {
|
||||
// --snip--
|
||||
let file_path = "/home/clement/RustroverProjects/advent_of_code/src/inputs/input_1.txt";
|
||||
println!("In file {file_path}");
|
||||
|
||||
let (mut l_list, mut r_list) : (Vec<i32>, Vec<i32>) = fs::read_to_string(file_path)
|
||||
.expect("Should have been able to read the file")
|
||||
.split('\n')
|
||||
.map(|s|{
|
||||
let mut splited = s.split_whitespace();
|
||||
(
|
||||
splited.next().unwrap().parse::<i32>().unwrap(),
|
||||
splited.next().unwrap().parse::<i32>().unwrap()
|
||||
)
|
||||
}).unzip();
|
||||
|
||||
l_list.sort();
|
||||
}
|
1000
src/inputs/input_1.txt
Normal file
1000
src/inputs/input_1.txt
Normal file
File diff suppressed because it is too large
Load diff
9
src/main.rs
Normal file
9
src/main.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
mod day_1_1;
|
||||
mod day_1_2;
|
||||
|
||||
use crate::day_1_1::solve_day_1_1;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
// solve_day_1_1();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue