Skip to content

Commit

Permalink
update (math): process and vector transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
lumbrjx committed Jan 21, 2024
1 parent b6b200f commit 8815cd5
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/encpt/mapping/construct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// cyph
1 change: 0 additions & 1 deletion src/encpt/math/derive.rs

This file was deleted.

24 changes: 24 additions & 0 deletions src/encpt/math/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,30 @@ pub fn fill_mtrx_gaps(n: usize, orgnl_mtrx: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
filled_mtrx
}

pub fn mtrx_to_vecs(mtrx: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
let mut blue: Vec<i32> = vec![];
let mut green: Vec<i32> = vec![];
let mut red: Vec<i32> = vec![];
let mut res: Vec<Vec<i32>> = vec![];

for (i, element) in mtrx.iter().enumerate() {
for (j, sub) in element.iter().enumerate() {
if i > j {
blue.push(*sub);
} else if j > i {
green.push(*sub);
} else {
red.push(*sub);
}
}
}
res.push(green);
res.push(red);
res.push(blue);

res
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
6 changes: 6 additions & 0 deletions src/encpt/math/process.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub fn add_to_vec(a: i32, chunk: Vec<i32>) -> Vec<i32> {
chunk
.iter()
.map(|&c| if c == 0 { c } else { c + a })
.collect()
}
36 changes: 23 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ use crate::{
encpt::{mapping::mapper::*, math::matrix::fill_mtrx_gaps},
shared::parse::str2_string_vec,
};
use encpt::{mapping::switcher::switch_chars, math::matrix::char_to_mtrx};
use encpt::{
mapping::switcher::switch_chars,
math::matrix::{char_to_mtrx, mtrx_to_vecs},
};
pub mod maps {
pub mod chars;
pub mod nums;
pub mod salt;
}
mod shared {
Expand All @@ -13,6 +17,7 @@ mod shared {
mod encpt {
pub mod math {
pub mod matrix;
pub mod process;
}
pub mod mapping {
pub mod mapper;
Expand Down Expand Up @@ -43,16 +48,21 @@ fn main() {
// let res = char_to_mtrx(vecs.iter().map(|c| str2_string_vec(c.to_vec())).collect());
// println!("{:?}", res);

let vecs1 = vec![
vec![785, 535, 789, 987, 123, 789],
vec![785, 535, 789, 987, 123, 787],
vec![785, 535, 789, 987, 123, 456],
vec![543, 528, 693, 285, 147, 556],
vec![753, 456, 456, 564],
vec![],
];
let res1 = fill_mtrx_gaps(6, vecs1);
for a in res1 {
println!("{:?}", a);
}
// let vecs1 = vec![
// vec![785, 535, 789, 987, 123, 789],
// vec![785, 535, 789, 987, 123, 787],
// vec![785, 535, 789, 987, 123, 456],
// vec![543, 528, 693, 285, 147, 556],
// vec![753, 456, 456, 564, 0, 0],
// vec![0, 0, 0, 0, 0, 0],
// ];
// // let res1 = fill_mtrx_gaps(6, vecs1);
// // for a in res1 {
// // println!("{:?}", a);
// // }
// //
// let s = mtrx_to_vecs(vecs1);
// for d in s {
// println!("{:?}", d);
// }
}
12 changes: 12 additions & 0 deletions src/maps/nums.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pub const NUM_MAP: [[&'static str; 2]; 10] = [
["0", "H*d"],
["1", "4(g"],
["2", "p:5"],
["3", "ddc"],
["4", "mmH"],
["5", "*d/"],
["6", "mkl"],
["7", "65d"],
["8", "II-"],
["9", "mp*"],
];
6 changes: 5 additions & 1 deletion src/shared/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub fn str2_string_vec(nsrd: Vec<&str>) -> Vec<String> {
nsrd_as_strings
}

// need to change
pub fn split_by_n(n: usize, chunk: Vec<String>) -> Vec<Vec<String>> {
let mut split_vectors: Vec<Vec<String>> = chunk.chunks(n).map(|chunk| chunk.to_vec()).collect();
if split_vectors.len() < n {
Expand All @@ -30,6 +29,11 @@ pub fn split_by_n(n: usize, chunk: Vec<String>) -> Vec<Vec<String>> {
split_vectors
}

pub fn rem_zeros(chunk: Vec<i32>) -> (Vec<i32>, usize) {
let count_zeros = chunk.iter().filter(|&&c| c == 0).count();
let filtered_chunk: Vec<i32> = chunk.into_iter().filter(|&c| c != 0).collect();
(filtered_chunk, count_zeros)
}
#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 8815cd5

Please sign in to comment.