this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Invert triangle

+16 -3
+16 -3
sierpinski
··· 60 60 #[derive(FromArgs)] 61 61 #[argh(description = "Prints a Sierpinski triangle.")] 62 62 struct App { 63 + #[argh(switch, description = "inverts the triangle.")] 64 + invert: bool, 65 + 63 66 #[argh( 64 67 option, 65 68 description = "triangle type to use.", ··· 72 75 } 73 76 74 77 fn main() { 75 - let App { size, triangle } = argh::from_env(); 78 + let App { 79 + size, 80 + triangle, 81 + invert, 82 + } = argh::from_env(); 76 83 let size = size.unwrap_or(1); 77 84 78 85 let height = 2_usize.pow(size as u32); ··· 82 89 bounding_box[0][height - 1] = 1; 83 90 84 91 let mut last_row = bounding_box[0].clone(); 85 - for (i, row) in bounding_box.iter_mut().skip(1).enumerate() { 92 + for row in bounding_box.iter_mut().skip(1) { 86 93 for (j, cell) in row.iter_mut().enumerate() { 87 94 let top_left = last_row.get(j - 1).unwrap_or(&0); 88 95 let top_right = last_row.get(j + 1).unwrap_or(&0); ··· 92 99 last_row = row.clone(); 93 100 } 94 101 95 - for row in bounding_box { 102 + let rows: Box<dyn Iterator<Item = Vec<u16>>> = if invert { 103 + Box::new(bounding_box.into_iter().rev()) 104 + } else { 105 + Box::new(bounding_box.into_iter()) 106 + }; 107 + 108 + for row in rows { 96 109 for cell in row { 97 110 if cell == 0 || cell % 2 == 0 { 98 111 print!(" ");