1
0
Fork 0

Compare commits

...

2 Commits

Author SHA1 Message Date
chylex 065aa6ad45
Add 2020 - Day 1 - Part 1 2022-02-22 14:46:42 +01:00
chylex 3d4d46f35e
Add Rust project for 2020 & update README 2022-02-22 14:23:19 +01:00
9 changed files with 284 additions and 5 deletions

View File

@ -0,0 +1,18 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="2020 - Day 01" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
<option name="command" value="run --bin 01" />
<option name="workingDirectory" value="file://$PROJECT_DIR$/2020/01" />
<option name="channel" value="DEFAULT" />
<option name="requiredFeatures" value="true" />
<option name="allFeatures" value="false" />
<option name="emulateTerminal" value="false" />
<option name="withSudo" value="false" />
<option name="backtrace" value="SHORT" />
<envs />
<option name="isRedirectInput" value="false" />
<option name="redirectInputPath" value="" />
<method v="2">
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
</method>
</configuration>
</component>

1
2020/.gitignore vendored Normal file
View File

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

200
2020/01/input/1.txt Normal file
View File

@ -0,0 +1,200 @@
1941
1887
1851
1874
1612
1960
1971
1983
1406
1966
1554
1892
1898
1926
1081
1992
1073
1603
177
1747
1063
1969
1659
1303
1759
1853
1107
1818
1672
1352
2002
1838
1985
1860
1141
1903
1334
1489
1178
1823
1499
1951
1225
1503
1417
1724
1165
1339
1816
1504
1588
1997
1946
1324
1771
1982
1272
1367
1439
1252
1902
1940
1333
1750
1512
1538
1168
2001
1797
1233
972
1306
1835
1825
1822
1880
1732
1785
1727
1275
1355
1793
1485
1297
1932
1519
1587
1382
1914
1745
1087
1996
1746
1962
1573
2008
1868
1278
1386
1238
1242
1170
1476
1161
1754
1807
1514
1189
1916
1884
1535
1217
1911
1861
1493
1409
1783
1222
1955
1673
1502
607
2010
1846
1819
1500
1799
1475
1146
1608
1806
1660
1618
1904
978
1762
1925
1185
1154
1239
1843
1986
533
1509
1913
287
1707
1115
1699
1859
1077
1915
1412
1360
1646
1973
1627
1755
1748
1769
1886
1422
1686
950
100
1372
1068
1370
1428
1870
1108
190
1891
1794
1228
1128
1365
1740
1888
1460
1758
1906
1917
1989
1251
1866
1560
1921
1777
1102
1850
1498
683
1840
1800
1112
1908
1442
1082
1071

23
2020/01/main.rs Normal file
View File

@ -0,0 +1,23 @@
use std::error::Error;
#[path = "../utils/mod.rs"]
mod utils;
fn main() -> Result<(), Box<dyn Error>> {
let lines = utils::parse_input_lines::<u32>()?;
'outer: for i in 0..lines.len() {
let value1 = lines.get(i).unwrap();
for j in (i + 1)..lines.len() {
let value2 = lines.get(j).unwrap();
if value1 + value2 == 2020 {
println!("Result: {} x {} = {}", value1, value2, value1 * value2);
break 'outer
}
}
}
Ok(())
}

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"

8
2020/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "chylex-aoc-2020"
version = "0.1.0"
edition = "2021"
[[bin]]
name = "01"
path = "01/main.rs"

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.
@ -31,6 +37,7 @@ The versions should not matter, but I used Visual Studio 2019 with `MSVC v142 (1
|-----:|----:|----------|
| 2015 | 01 | NASM x64 |
| 2015 | 02 | NASM x64 |
| 2020 | 01 | Rust |
| 2021 | 01 | Kotlin |
| 2021 | 02 | Kotlin |
| 2021 | 03 | Kotlin |

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")
))
}