CARVIEW |
Select Language
HTTP/2 200
date: Sat, 11 Oct 2025 14:11:44 GMT
content-type: text/html; charset=UTF-8
server: cloudflare
x-frame-options: DENY
x-content-type-options: nosniff
x-xss-protection: 1;mode=block
vary: accept-encoding
cf-cache-status: DYNAMIC
content-encoding: gzip
set-cookie: _csrf-frontend=52bf8a0d7d1428ba16f568f57d72df385ac8ae82fbccfc863a101f47c34cc7cfa%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%22A-RXDmPrgG_CNhLEFqtpeG4tGgfhIwvB%22%3B%7D; HttpOnly; Path=/
cf-ray: 98cef2c59882a8b0-BLR
aoc_2024_day1_rust - Pastebin.com
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::collections::HashMap;
- use std::fs::File;
- use std::io::{BufRead, BufReader};
- use std::time::Instant;
- fn create_sorted_vectors_from_file(
- file_name: &str,
- ) -> Result<(Vec<i32>, Vec<i32>), std::io::Error> {
- let file = File::open(file_name)?;
- let reader = BufReader::new(file);
- let mut col1 = Vec::new();
- let mut col2 = Vec::new();
- for line in reader.lines() {
- let line = line?;
- let numbers: Vec<i32> = line
- .split_whitespace()
- .map(|s| s.parse().unwrap())
- .collect();
- if numbers.len() == 2 {
- col1.push(numbers[0]);
- col2.push(numbers[1]);
- }
- }
- col1.sort();
- col2.sort();
- Ok((col1, col2))
- }
- fn calculate_l1_distance(vec1: &[i32], vec2: &[i32]) -> i64 {
- vec1.iter()
- .zip(vec2.iter())
- .map(|(a, b)| (a - b).abs() as i64)
- .sum()
- }
- fn find_similarity_score(vec1: &[i32], vec2: &[i32]) -> i64 {
- let mut vec2_counter: HashMap<i32, u32> = HashMap::new();
- for &el in vec2 {
- *vec2_counter.entry(el).or_insert(0) += 1;
- }
- let mut score = 0i64;
- for el in vec1 {
- if let Some(&count) = vec2_counter.get(el) {
- score += (el.clone() as i64) * (count as i64)
- }
- }
- score
- }
- fn main() {
- let start = Instant::now();
- match create_sorted_vectors_from_file("input.txt") {
- Ok((col1, col2)) => {
- if col1.len() == col2.len() {
- let l1_distance = calculate_l1_distance(&col1, &col2);
- let similarity_score = find_similarity_score(&col1, &col2);
- println!("L1 distance between the two vectors: {}", l1_distance);
- println!(
- "similarity score between the two vectors: {}",
- similarity_score
- );
- } else {
- println!("Error: Vectors have different lengths");
- }
- }
- Err(e) => println!("Error reading file: {}", e),
- }
- let duration = start.elapsed();
- println!("Time elapsed: {:?}", duration);
- }
Advertisement
Add Comment
Please, Sign In to add comment
-
⭐⭐⭐ChangeNOW Exploit⭐⭐
Java | 1 sec ago | 0.10 KB
-
Free Crypto Method (NEVER SEEN BEFORE)⭐⭐ 4
JavaScript | 5 sec ago | 0.24 KB
-
⭐⭐⭐ G2A Payment Exploit ✅ NEVER SEEN BEFORE ⭐...
JavaScript | 11 sec ago | 0.24 KB
-
⭐⭐⭐MAKE $1000 INSTANTLY⭐⭐
Java | 12 sec ago | 0.10 KB
-
⭐✅ Swapzone Glitch ✅ Working⭐⭐⭐ Y
JavaScript | 17 sec ago | 0.24 KB
-
⭐✅ MAKE $2500 IN 15 MIN ✅ NEVER SEEN BEFORE ⭐...
JavaScript | 21 sec ago | 0.24 KB
-
⭐⭐⭐GMAIL Logs (2FA disabled)⭐⭐
Java | 23 sec ago | 0.10 KB
-
✅ Make $2500 in 20 minutes⭐⭐⭐ P
JavaScript | 27 sec ago | 0.24 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand