summary refs log tree commit diff stats
path: root/rust/format/src/format_layer/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/format/src/format_layer/mod.rs')
-rw-r--r--rust/format/src/format_layer/mod.rs209
1 files changed, 209 insertions, 0 deletions
diff --git a/rust/format/src/format_layer/mod.rs b/rust/format/src/format_layer/mod.rs
new file mode 100644
index 0000000..1b93c97
--- /dev/null
+++ b/rust/format/src/format_layer/mod.rs
@@ -0,0 +1,209 @@
+use std::fmt::{Display, Write};
+
+include!("output_def.fs");
+
+macro_rules! check {
+    ($c1:expr, $cf:expr, $ind:expr, $ma:expr) => {
+        if ($cf[$ind] >= $ma) {
+            $c1[$ind] = $cf[$ind];
+        } else {
+            // eprintln!("Changed {} from {} -> {}", stringify!($cf), $cf[$ind], $ma);
+            $c1[$ind] = $ma;
+            $cf[$ind] = $ma;
+        }
+    };
+}
+
+macro_rules! get {
+    ($val:expr, $column:tt, $key:tt) => {
+        [
+            $val.row1.$key.$column.to_string(),
+            $val.row2.$key.$column.to_string(),
+            $val.row3.$key.$column.to_string(),
+            $val.row4.$key.$column.to_string(),
+            $val.row5.$key.$column.to_string(),
+            $val.row6.$key.$column.to_string(),
+        ]
+        .iter()
+        .map(|val| val.chars().count())
+        .max()
+        .expect("Works")
+    };
+}
+
+impl Output {
+    fn format(&self, c_column_max: &mut [usize; 14]) -> String {
+        let mut columns_max = [0; 14];
+
+        check!(columns_max, c_column_max, 0, get! {self, 0, 0});
+        check!(columns_max, c_column_max, 1, get! {self, 1, 0});
+        check!(columns_max, c_column_max, 2, get! {self, 2, 0});
+        check!(columns_max, c_column_max, 3, get! {self, 3, 0});
+        check!(columns_max, c_column_max, 4, get! {self, 4, 0});
+        check!(columns_max, c_column_max, 5, get! {self, 5, 0});
+        check!(columns_max, c_column_max, 6, get! {self, 6, 0});
+        check!(columns_max, c_column_max, 7, get! {self, 0, 0});
+        check!(columns_max, c_column_max, 8, get! {self, 1, 1});
+        check!(columns_max, c_column_max, 9, get! {self, 2, 1});
+        check!(columns_max, c_column_max, 10, get! {self, 3, 1});
+        check!(columns_max, c_column_max, 11, get! {self, 4, 1});
+        check!(columns_max, c_column_max, 12, get! {self, 5, 1});
+        check!(columns_max, c_column_max, 13, get! {self, 6, 1});
+
+        let mut f = String::new();
+        write!(
+            f,
+            include_str!("prints.txt"),
+            // row 1
+            self.row1.0 .0,
+            self.row1.0 .1,
+            self.row1.0 .2,
+            self.row1.0 .3,
+            self.row1.0 .4,
+            self.row1.0 .5,
+            self.row1.0 .6,
+            self.row1.1 .0,
+            self.row1.1 .1,
+            self.row1.1 .2,
+            self.row1.1 .3,
+            self.row1.1 .4,
+            self.row1.1 .5,
+            self.row1.1 .6,
+            // row 2
+            self.row2.0 .0,
+            self.row2.0 .1,
+            self.row2.0 .2,
+            self.row2.0 .3,
+            self.row2.0 .4,
+            self.row2.0 .5,
+            self.row2.0 .6,
+            self.row2.1 .0,
+            self.row2.1 .1,
+            self.row2.1 .2,
+            self.row2.1 .3,
+            self.row2.1 .4,
+            self.row2.1 .5,
+            self.row2.1 .6,
+            // row 3
+            self.row3.0 .0,
+            self.row3.0 .1,
+            self.row3.0 .2,
+            self.row3.0 .3,
+            self.row3.0 .4,
+            self.row3.0 .5,
+            self.row3.0 .6,
+            self.row3.1 .0,
+            self.row3.1 .1,
+            self.row3.1 .2,
+            self.row3.1 .3,
+            self.row3.1 .4,
+            self.row3.1 .5,
+            self.row3.1 .6,
+            // row 4
+            self.row4.0 .0.to_string(),
+            self.row4.0 .1.to_string(),
+            self.row4.0 .2.to_string(),
+            self.row4.0 .3.to_string(),
+            self.row4.0 .4.to_string(),
+            self.row4.0 .5.to_string(),
+            self.row4.0 .6.to_string(),
+            self.row4.1 .0.to_string(),
+            self.row4.1 .1.to_string(),
+            self.row4.1 .2.to_string(),
+            self.row4.1 .3.to_string(),
+            self.row4.1 .4.to_string(),
+            self.row4.1 .5.to_string(),
+            self.row4.1 .6.to_string(),
+            // row 5
+            self.row5.0 .0.to_string(),
+            self.row5.0 .1.to_string(),
+            self.row5.0 .2.to_string(),
+            self.row5.0 .3.to_string(),
+            self.row5.0 .4.to_string(),
+            self.row5.0 .5.to_string(),
+            self.row5.0 .6.to_string(),
+            self.row5.1 .0.to_string(),
+            self.row5.1 .1.to_string(),
+            self.row5.1 .2.to_string(),
+            self.row5.1 .3.to_string(),
+            self.row5.1 .4.to_string(),
+            self.row5.1 .5.to_string(),
+            self.row4.1 .6.to_string(),
+            // thumbs
+            self.row6.0 .0.to_string(),
+            self.row6.0 .1.to_string(),
+            self.row6.0 .2.to_string(),
+            self.row6.0 .3.to_string(),
+            self.row6.0 .4.to_string(),
+            self.row6.0 .5.to_string(),
+            self.row6.0 .6.to_string(),
+            self.row6.1 .0.to_string(),
+            self.row6.1 .1.to_string(),
+            self.row6.1 .2.to_string(),
+            self.row6.1 .3.to_string(),
+            self.row6.1 .4.to_string(),
+            self.row6.1 .5.to_string(),
+            self.row6.1 .6.to_string(),
+            col0 = columns_max[0],
+            col1 = columns_max[1],
+            col2 = columns_max[2],
+            col3 = columns_max[3],
+            col4 = columns_max[4],
+            col5 = columns_max[5],
+            col6 = columns_max[6],
+            col7 = columns_max[7],
+            col8 = columns_max[8],
+            col9 = columns_max[9],
+            col10 = columns_max[10],
+            col11 = columns_max[11],
+            col12 = columns_max[12],
+            col13 = columns_max[13],
+        )
+        .expect("Works");
+        f
+    }
+}
+
+#[must_use]
+pub fn format_layer(input: String, c_column_max: &mut [usize; 14]) -> String {
+    let mut a = input
+        .lines()
+        .map(|val| val.to_owned())
+        .collect::<Vec<String>>()
+        .join(" ")
+        .split_whitespace()
+        .map(|val| val.to_owned())
+        .rev()
+        .collect::<Vec<String>>();
+    let mut n = || a.pop().expect("This should exist");
+    let e = || Emt();
+
+    let out = Output {
+        row1: (
+            (n(), n(), n(), n(), n(), n(), n()),
+            (n(), n(), n(), n(), n(), n(), n()),
+        ),
+        row2: (
+            (n(), n(), n(), n(), n(), n(), n()),
+            (n(), n(), n(), n(), n(), n(), n()),
+        ),
+        row3: (
+            (n(), n(), n(), n(), n(), n(), n()),
+            (n(), n(), n(), n(), n(), n(), n()),
+        ),
+        row4: (
+            (n(), n(), n(), n(), n(), n(), e()),
+            (e(), n(), n(), n(), n(), n(), n()),
+        ),
+        row5: (
+            (n(), n(), n(), n(), n(), n(), e()),
+            (e(), n(), n(), n(), n(), n(), n()),
+        ),
+        row6: (
+            (e(), e(), e(), n(), n(), n(), e()),
+            (e(), n(), n(), n(), e(), e(), e()),
+        ),
+    };
+
+    out.format(c_column_max)
+}