update
This commit is contained in:
@@ -5,7 +5,7 @@ use std::io::prelude::*;
|
|||||||
|
|
||||||
const RADIX: u32 = 10;
|
const RADIX: u32 = 10;
|
||||||
|
|
||||||
static mut shortest: u32 = 99999;
|
static mut shortest: u32 = 60000;
|
||||||
|
|
||||||
fn main(){
|
fn main(){
|
||||||
let file = File::open("./input.txt").expect("Read failed");
|
let file = File::open("./input.txt").expect("Read failed");
|
||||||
@@ -36,9 +36,9 @@ fn main(){
|
|||||||
|
|
||||||
fn get_shortest_weight(weight_vec: &Vec<Vec<u32>>, x: usize, y: usize, current_weight: u32, width: usize, height: usize, visited: &Vec<(usize, usize)>) {
|
fn get_shortest_weight(weight_vec: &Vec<Vec<u32>>, x: usize, y: usize, current_weight: u32, width: usize, height: usize, visited: &Vec<(usize, usize)>) {
|
||||||
let mut visited_local = visited.to_owned();
|
let mut visited_local = visited.to_owned();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
if current_weight > shortest {
|
if visited_local.contains(&(x,y)) || current_weight > shortest || visited_local.len() > 1000{
|
||||||
|
//println!("Breaking at {}, {}, {}", current_weight, visited_local.len(), shortest);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,10 +47,6 @@ fn get_shortest_weight(weight_vec: &Vec<Vec<u32>>, x: usize, y: usize, current_w
|
|||||||
println!("Current length: {}, shortest now: {}", current_weight, shortest);}
|
println!("Current length: {}, shortest now: {}", current_weight, shortest);}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if visited_local.contains(&(x,y)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
visited_local.push((x,y));
|
visited_local.push((x,y));
|
||||||
|
|
||||||
let temp_weight = current_weight + weight_vec[y][x];
|
let temp_weight = current_weight + weight_vec[y][x];
|
||||||
|
|||||||
9
december_16/Cargo.toml
Normal file
9
december_16/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "december_16"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
hex = "0.4.3"
|
||||||
1
december_16/example.txt
Normal file
1
december_16/example.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
D2FE28
|
||||||
0
december_16/input.txt
Normal file
0
december_16/input.txt
Normal file
25
december_16/src/main.rs
Normal file
25
december_16/src/main.rs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
use std::fs::read_to_string;
|
||||||
|
|
||||||
|
extern crate hex;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let input_char_vec = read_to_string("./example.txt").expect("ERROR reading file");
|
||||||
|
//let split_input: Vec<char> = input_char_vec.chars().collect();
|
||||||
|
let test = hex::decode(input_char_vec).expect("Decoding failed");
|
||||||
|
|
||||||
|
let mut bit_vec: Vec<bool> = Vec::new();
|
||||||
|
|
||||||
|
for t in test{
|
||||||
|
for n in 0..8 {
|
||||||
|
bit_vec.push( (t >> 7-n & 1) == 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
process_packet(bit_vec);
|
||||||
|
println!();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn process_packet(bit_vec: Vec<bool>) {
|
||||||
|
let version = (bit_vec[0] as u32 * 4) + (bit_vec[1] as u32 * 2) + (bit_vec[2] as u32);
|
||||||
|
let packet_type = (bit_vec[3] as u32 * 4) + (bit_vec[4] as u32 * 2) + (bit_vec[5] as u32);
|
||||||
|
println!("Packet Version: {}, Packet type: {}", version, packet_type);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user