init
This commit is contained in:
1
day1/.gitignore
vendored
Normal file
1
day1/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/target
|
||||||
54
day1/Cargo.lock
generated
Normal file
54
day1/Cargo.lock
generated
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aho-corasick"
|
||||||
|
version = "1.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "day1"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"regex",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memchr"
|
||||||
|
version = "2.6.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex"
|
||||||
|
version = "1.10.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-automata",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-automata"
|
||||||
|
version = "0.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-syntax"
|
||||||
|
version = "0.8.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
|
||||||
9
day1/Cargo.toml
Normal file
9
day1/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "day1"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
regex = "1.10.2"
|
||||||
1000
day1/nyger.txt
Normal file
1000
day1/nyger.txt
Normal file
File diff suppressed because it is too large
Load Diff
45
day1/src/main.rs
Normal file
45
day1/src/main.rs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
use std::fs::File;
|
||||||
|
use std::io::prelude::*;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use regex::Regex;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
// Create a path to the desired file
|
||||||
|
let path = Path::new("nyger.txt");
|
||||||
|
let display = path.display();
|
||||||
|
|
||||||
|
// Open the path in read-only mode, returns `io::Result<File>`
|
||||||
|
let mut file = match File::open(&path) {
|
||||||
|
Err(why) => panic!("couldn't open {}: {}", display, why),
|
||||||
|
Ok(file) => file,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Read the file contents into a string, returns `io::Result<usize>`
|
||||||
|
let mut s = String::new();
|
||||||
|
let re = Regex::new(r"\d").unwrap();
|
||||||
|
|
||||||
|
//file.read_to_string(&mut s);
|
||||||
|
//match file.read_to_string(&mut s) {
|
||||||
|
// Err(why) => panic!("couldn't read {}: {}", display, why),
|
||||||
|
// Ok(_) => match re.captures(&s) {
|
||||||
|
// Some(caps) => println!("{}", caps.get(0).unwrap().as_str()),
|
||||||
|
// None => println!("chuj ci w dupe")
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
file.read_to_string(&mut s);
|
||||||
|
match file.read_to_string(&mut s) {
|
||||||
|
Err(why) => panic!("couldn't read {}: {}", display, why),
|
||||||
|
Ok(_) => for number in re.find_iter(&s) {
|
||||||
|
|
||||||
|
print!("{}", number.as_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
7
day1_alternative/Cargo.lock
generated
Normal file
7
day1_alternative/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 = "day1_alternative"
|
||||||
|
version = "0.1.0"
|
||||||
8
day1_alternative/Cargo.toml
Normal file
8
day1_alternative/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "day1_alternative"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
83
day1_alternative/src/main.rs
Normal file
83
day1_alternative/src/main.rs
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let input = include_str!("nyger.txt");
|
||||||
|
let output = part1(input);
|
||||||
|
println!("Part 1: {}", output);
|
||||||
|
let part2_anwer = part2(input);
|
||||||
|
println!("Part 2: {}", part2_anwer);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn find_digit(line: &str) -> i32 {
|
||||||
|
line.chars()
|
||||||
|
.find(|c| c.is_ascii_digit())
|
||||||
|
.map(|c| c as i32 - 48)
|
||||||
|
.unwrap_or(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn part1(input: &str) -> i32 {
|
||||||
|
let lines: Vec<String> = input.lines().map(String::from).collect();
|
||||||
|
let mut values = Vec::<i32>::new();
|
||||||
|
for line in lines {
|
||||||
|
values.push(find_digit(&line) * 10 + find_digit(&line.chars().rev().collect::<String>()));
|
||||||
|
}
|
||||||
|
return values.iter().sum();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//PART 2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fn create_key_map() -> HashMap<&'static str, i32> {
|
||||||
|
[
|
||||||
|
("zero", 0), ("one", 1), ("two", 2), ("three", 3), ("four", 4),
|
||||||
|
("five", 5), ("six", 6), ("seven", 7), ("eight", 8), ("nine", 9),
|
||||||
|
].iter().cloned().collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn find_first_digit(line: &str) -> i32 {
|
||||||
|
let key_map: HashMap<&str, i32> = create_key_map();
|
||||||
|
let mut searched = String::new();
|
||||||
|
for char in line.chars() {
|
||||||
|
if char.is_ascii_digit() {
|
||||||
|
return char as i32 - 48;
|
||||||
|
}
|
||||||
|
searched.push(char);
|
||||||
|
for key in key_map.keys() {
|
||||||
|
if searched.contains(key) {
|
||||||
|
return key_map[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn find_last_digit(line: &str) -> i32 {
|
||||||
|
let key_map: HashMap<&str, i32> = create_key_map();
|
||||||
|
let mut searched = String::new();
|
||||||
|
for char in line.chars().rev() {
|
||||||
|
if char.is_ascii_digit() {
|
||||||
|
return char as i32 - 48;
|
||||||
|
}
|
||||||
|
searched.insert(0, char);
|
||||||
|
for key in key_map.keys() {
|
||||||
|
if searched.contains(key) {
|
||||||
|
return key_map[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn part2(input: &str) -> i32 {
|
||||||
|
let lines: Vec<String> = input.lines().map(String::from).collect();
|
||||||
|
let mut values = Vec::<i32>::new();
|
||||||
|
for line in lines {
|
||||||
|
values.push(find_first_digit(&line) * 10 + find_last_digit(&line));
|
||||||
|
}
|
||||||
|
return values.iter().sum();
|
||||||
|
}
|
||||||
1000
day1_alternative/src/nyger.txt
Normal file
1000
day1_alternative/src/nyger.txt
Normal file
File diff suppressed because it is too large
Load Diff
1
day1_alternative/target/.rustc_info.json
Normal file
1
day1_alternative/target/.rustc_info.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"rustc_fingerprint":10728484955947285044,"outputs":{"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.74.0 (79e9716c9 2023-11-13)\nbinary: rustc\ncommit-hash: 79e9716c980570bfd1f666e3b16ac583f0168962\ncommit-date: 2023-11-13\nhost: x86_64-unknown-linux-gnu\nrelease: 1.74.0\nLLVM version: 17.0.4\n","stderr":""},"15729799797837862367":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/xd/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n","stderr":""}},"successes":{}}
|
||||||
3
day1_alternative/target/CACHEDIR.TAG
Normal file
3
day1_alternative/target/CACHEDIR.TAG
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
Signature: 8a477f597d28d172789f06886806bc55
|
||||||
|
# This file is a cache directory tag created by cargo.
|
||||||
|
# For information about cache directory tags see https://bford.info/cachedir/
|
||||||
0
day1_alternative/target/debug/.cargo-lock
Normal file
0
day1_alternative/target/debug/.cargo-lock
Normal file
Binary file not shown.
@@ -0,0 +1 @@
|
|||||||
|
This file has an mtime of when this was started.
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
177f163f20582d2e
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{"rustc":174346706036672835,"features":"[]","target":11768347492559044085,"profile":16741232958890476625,"path":1684066648322511884,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/day1_alternative-30bfeeab11a40833/dep-test-bin-day1_alternative"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
|
||||||
Binary file not shown.
@@ -0,0 +1 @@
|
|||||||
|
This file has an mtime of when this was started.
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
dad8a44946af5db9
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{"rustc":174346706036672835,"features":"[]","target":11768347492559044085,"profile":18326522262828315194,"path":1684066648322511884,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/day1_alternative-382dd10d38447d92/dep-test-bin-day1_alternative"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
c720419f623521a3
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{"rustc":174346706036672835,"features":"[]","target":11768347492559044085,"profile":13126374248311259211,"path":1684066648322511884,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/day1_alternative-87afc6c6a423d03a/dep-bin-day1_alternative"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
|
||||||
Binary file not shown.
@@ -0,0 +1 @@
|
|||||||
|
This file has an mtime of when this was started.
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
2c54fa7809bc626e
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{"rustc":174346706036672835,"features":"[]","target":11768347492559044085,"profile":11039742474438789458,"path":1684066648322511884,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/day1_alternative-bbb4b205146a476c/dep-bin-day1_alternative"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
|
||||||
Binary file not shown.
@@ -0,0 +1 @@
|
|||||||
|
This file has an mtime of when this was started.
|
||||||
BIN
day1_alternative/target/debug/day1_alternative
Executable file
BIN
day1_alternative/target/debug/day1_alternative
Executable file
Binary file not shown.
1
day1_alternative/target/debug/day1_alternative.d
Normal file
1
day1_alternative/target/debug/day1_alternative.d
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/home/xd/rust/advent_of_code_2023/day1_alternative/target/debug/day1_alternative: /home/xd/rust/advent_of_code_2023/day1_alternative/src/main.rs /home/xd/rust/advent_of_code_2023/day1_alternative/src/nyger.txt
|
||||||
BIN
day1_alternative/target/debug/deps/day1_alternative-30bfeeab11a40833
Executable file
BIN
day1_alternative/target/debug/deps/day1_alternative-30bfeeab11a40833
Executable file
Binary file not shown.
@@ -0,0 +1,6 @@
|
|||||||
|
/home/xd/rust/advent_of_code_2023/day1_alternative/target/debug/deps/day1_alternative-30bfeeab11a40833: src/main.rs src/nyger.txt
|
||||||
|
|
||||||
|
/home/xd/rust/advent_of_code_2023/day1_alternative/target/debug/deps/day1_alternative-30bfeeab11a40833.d: src/main.rs src/nyger.txt
|
||||||
|
|
||||||
|
src/main.rs:
|
||||||
|
src/nyger.txt:
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
/home/xd/rust/advent_of_code_2023/day1_alternative/target/debug/deps/libday1_alternative-382dd10d38447d92.rmeta: src/main.rs src/nyger.txt
|
||||||
|
|
||||||
|
/home/xd/rust/advent_of_code_2023/day1_alternative/target/debug/deps/day1_alternative-382dd10d38447d92.d: src/main.rs src/nyger.txt
|
||||||
|
|
||||||
|
src/main.rs:
|
||||||
|
src/nyger.txt:
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
/home/xd/rust/advent_of_code_2023/day1_alternative/target/debug/deps/libday1_alternative-87afc6c6a423d03a.rmeta: src/main.rs src/nyger.txt
|
||||||
|
|
||||||
|
/home/xd/rust/advent_of_code_2023/day1_alternative/target/debug/deps/day1_alternative-87afc6c6a423d03a.d: src/main.rs src/nyger.txt
|
||||||
|
|
||||||
|
src/main.rs:
|
||||||
|
src/nyger.txt:
|
||||||
BIN
day1_alternative/target/debug/deps/day1_alternative-bbb4b205146a476c
Executable file
BIN
day1_alternative/target/debug/deps/day1_alternative-bbb4b205146a476c
Executable file
Binary file not shown.
@@ -0,0 +1,6 @@
|
|||||||
|
/home/xd/rust/advent_of_code_2023/day1_alternative/target/debug/deps/day1_alternative-bbb4b205146a476c: src/main.rs src/nyger.txt
|
||||||
|
|
||||||
|
/home/xd/rust/advent_of_code_2023/day1_alternative/target/debug/deps/day1_alternative-bbb4b205146a476c.d: src/main.rs src/nyger.txt
|
||||||
|
|
||||||
|
src/main.rs:
|
||||||
|
src/nyger.txt:
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user