Skip to content

Instantly share code, notes, and snippets.

View K-C-DaCosta's full-sized avatar
🎯
Focusing

K-C-DaCosta

🎯
Focusing
View GitHub Profile
@K-C-DaCosta
K-C-DaCosta / lib.rs
Last active August 28, 2022 18:11
Stateless traversal of matrix in ZigZag fashion
#[test]
fn tests() {
#[rustfmt::skip]
let matrix = vec![
vec![1 , 2 , 3, 4 , 5],
vec![6 , 7 , 8, 9 , 10],
vec![11 , 12 , 13, 14 , 15],
vec![16 , 17 , 18, 19 , 20],
];
let res = zigzag(&matrix);
@K-C-DaCosta
K-C-DaCosta / lib.rs
Last active August 26, 2022 02:39
cycle triangle solution
#[test]
fn triangle_test() {
cycle_triangle(10);
}
fn cycle_triangle(base: i32) {
// if base even we know final column is 2 so -> (base -2*k) = 2
// if base odd we know final column is 1 so -> (base -2*k) = 1
@K-C-DaCosta
K-C-DaCosta / hex_codec.rs
Last active August 21, 2022 21:22
Encode/Decode Hex
#[test]
pub fn decode_test() {
let decoded = decode_hex("EF1C9D9E");
print!("decoded = {:?} = ",decoded);
print_hex(&decoded);
let decoded = encode_hex(decoded);
println!("encoded = '{}'", decoded);
}