1
0
mirror of https://github.com/chylex/Advent-of-Code.git synced 2025-05-16 10:34:04 +02:00

Add Rust project for 2020 & update README

This commit is contained in:
chylex 2022-02-22 06:20:01 +01:00
parent dfa6de8405
commit 3d4d46f35e
Signed by: chylex
GPG Key ID: 4DE42C8F19A80548
6 changed files with 38 additions and 5 deletions

1
2020/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target/

7
2020/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "chylex-aoc-2020"
version = "0.1.0"

4
2020/Cargo.toml Normal file
View File

@ -0,0 +1,4 @@
[package]
name = "chylex-aoc-2020"
version = "0.1.0"
edition = "2021"

14
2020/utils/mod.rs Normal file
View File

@ -0,0 +1,14 @@
use std::error::Error;
use std::fs::File;
use std::io;
use std::io::{BufRead, BufReader};
use std::str::FromStr;
pub fn read_input_lines() -> Result<Vec<String>, io::Error> {
let file = File::open("input/1.txt")?;
return BufReader::new(file).lines().collect();
}
pub fn parse_input_lines<T : FromStr>() -> Result<Vec<T>, Box<dyn Error>> where <T as FromStr>::Err : Into<Box<dyn Error>> {
return read_input_lines()?.iter().map(|line| line.parse::<T>()).collect::<Result<Vec<T>, T::Err>>().map_err(Into::into);
}

View File

@ -6,15 +6,21 @@ I have included Run Configurations for JetBrains IDEs, so if you use the appropr
# Languages
## Kotlin
## \[2021\] Kotlin
The repository contains a Gradle project (`build.gradle.kts`) that sets up every day as a module. You should be able to load the Gradle project into [IntelliJ IDEA](https://www.jetbrains.com/idea/).
The source code is in `main.kt`. The run configuration executes the `main()` method in this file.
## NASM x64 Assembly
## \[2020\] Rust
The repository contains a CMake project (`CMakeLists.txt`) in the respective year's folder, which sets up every day as a CMake subproject. You should be able to load the CMake project into [CLion](https://www.jetbrains.com/clion/), as long as you have a toolchain named `Visual Studio x64` set to use the `amd64` architecture.
The repository contains a Cargo project (`2020/Cargo.toml`) that sets up every day as a binary target that can be launched with `cargo run --bin <day>`, for ex. `cargo run --bin 01`. You should be able to load the Cargo project into [CLion](https://www.jetbrains.com/clion/).
The source code is in `main.rs`. The run configuration executes the `main()` function in this file.
## \[2015\] NASM x64 Assembly
The repository contains a CMake project (`2015/CMakeLists.txt`) in the respective year's folder, which sets up every day as a CMake subproject. You should be able to load the CMake project into [CLion](https://www.jetbrains.com/clion/), as long as you have a toolchain named `Visual Studio x64` set to use the `amd64` architecture.
The source code is in `main.c`, which is either in the puzzle's own folder, or in `utils` if no adjustments are needed. By default, `main.c` reads the whole input file into a buffer, and passes it as a parameter to the `entryPoint` function defined in `main.asm` which implements the logic and output of each puzzle.

View File

@ -18,8 +18,9 @@ idea {
module.excludeDirs.addAll(listOf(
file(".gradle"),
file("build"),
file("cmake-build-debug"),
file("gradle")
file("gradle"),
file("2015"),
file("2020")
))
}