<commit_before>use std::fmt;
use std::fmt::Display;
use std::iter;

struct Tower {
    weight : usize,
}

impl Display for Tower {
    fn fmt(&self, f : &mut fmt::Formatter) -> fmt::Result {
        f.write_fmt(format_args!("[{0}]", iter::repeat("#").take(self.weight).collect::<String>()))
    }
}

struct Rod {
    stack : Vec<Tower>,
}

struct Desk {
    rods : Vec<Rod>,
}

impl Display for Desk {
    fn fmt(&self, f : &mut fmt::Formatter) -> fmt::Result {
        let max_weight : usize = 
            self.rods.iter()
                .map(|r| r.stack.iter().map(|s| s.weight).max().unwrap_or(0))
                .max().unwrap_or(0);
        let height = max_weight + 1;

        let dup = |s: &str, n: usize| iter::repeat(s).take(n).collect::<String>();
        let mut display : Vec<String> = Vec::new();

        for i in 0..height {
            let mut s : String = "  ".to_string();

            for rod in &self.rods {
                let stower: Option<&Tower> = rod.stack.get(i);
                let tmp = match stower {
                    None => format!("{0}|{0}", dup(" ", max_weight + 1)),
                    Some(tower) => format!("{1}[{0}|{0}]{1}", dup("#", tower.weight), dup(" ", max_weight - tower.weight)),
                };
                s.push_str(" ");
                s.push_str(&tmp);
            }

            s.push_str("  ");
            s.push_str("\n");
            display.push(s);
        }

        display.reverse();
        f.write_fmt(format_args!("{0}", display.connect("")))
    }
}

fn main() {
    let desk1 = Desk {
        rods : vec![
            Rod { stack:  vec![ Tower {weight: 4, }, Tower {weight: 3, }, ], },
            Rod { stack:  vec![ Tower {weight: 2, }, ], },
            Rod { stack:  vec![ Tower {weight: 1, }, ], },
        ],
    };
    println!("{0}", desk1);

    let desk2 = Desk {
        rods : vec![
            Rod { stack:  vec![ Tower {weight: 4, }, Tower {weight: 2, }, ], },
            Rod { stack:  vec![ Tower {weight: 3, }, ], },
            Rod { stack:  vec![ Tower {weight: 1, }, ], },
        ],
    };
    println!("{0}", desk2);

    let desk3 = Desk {
        rods : vec![
            Rod { stack:  vec![ Tower {weight: 4, }, Tower {weight: 2, }, ], },
            Rod { stack:  vec![ Tower {weight: 3, }, Tower {weight: 1 }, ], },
        ],
    };
    println!("{0}", desk3);
}<commit_msg>Add constructors and come skeletons<commit_after>use std::fmt;
use std::fmt::Display;
use std::iter;

struct Tower {
    weight : usize,
}

impl Tower {
    pub fn new(weight: usize) -> Tower {
        Tower { weight : weight }
    }

    pub fn weight(&self) -> usize {
        self.weight
    }
}

impl Display for Tower {
    fn fmt(&self, f : &mut fmt::Formatter) -> fmt::Result {
        f.write_fmt(format_args!("[{0}]", iter::repeat("#").take(self.weight()).collect::<String>()))
    }
}

struct Rod {
    stack : Vec<Tower>,
}

impl Rod {
    pub fn new(sizes : &[usize]) -> Rod {
        Rod { stack : sizes.iter().map(|x| Tower::new(*x) ).collect::<Vec<_>>() }
    }

    fn can_take_tower(&self, tower : &Tower) -> bool {
        match self.stack.last() {
            None => true,
            Some(t) => t.weight() > tower.weight(),
        }
    }

    pub fn can_take(&self, other: &Rod) -> bool {
        false // self.can_take_tower(&other.stack.last())
    }

    pub fn swap(& mut self, other: &mut Rod) -> &mut Self {
        self
    }

}

struct Desk {
    rods : Vec<Rod>,
}

impl Desk {
    pub fn new(rods: &[&[usize]]) -> Desk {
        Desk { rods : rods.iter().map(|x| Rod::new(*x) ).collect::<Vec<_>>() }
    }
}

impl Display for Desk {
    fn fmt(&self, f : &mut fmt::Formatter) -> fmt::Result {
        let max_weight : usize =
            self.rods.iter()
                .map(|r| r.stack.iter().map(|s| s.weight()).max().unwrap_or(0))
                .max().unwrap_or(0);
        let height = max_weight + 1;

        let dup = |s: &str, n: usize| iter::repeat(s).take(n).collect::<String>();
        let mut display : Vec<String> = Vec::new();

        for i in 0..height {
            let mut s : String = "  ".to_string();

            for rod in &self.rods {
                let stower: Option<&Tower> = rod.stack.get(i);
                let tmp = match stower {
                    None => format!("{0}|{0}", dup(" ", max_weight + 1)),
                    Some(tower) => format!("{1}[{0}|{0}]{1}", dup("#", tower.weight()), dup(" ", max_weight - tower.weight())),
                };
                s.push_str(" ");
                s.push_str(&tmp);
            }

            s.push_str("  ");
            s.push_str("\n");
            display.push(s);
        }

        display.reverse();
        f.write_fmt(format_args!("{0}", display.connect("")))
    }
}

fn main() {
    let desk1 = Desk::new(&[
        &[4, 3],
        &[2, 1]
    ]);
    println!("{0}", desk1);

}
{'fraction_non_alphanumeric': 0.19828466408004902, 'fraction_numerical': 0.011027159485399224, 'mean_word_length': 1.816561242093157, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4570734', 'n_tokens_mistral': 1677, 'n_tokens_neox': 1638, 'n_words': 378}