From 19df3cce1108830ddaf9e9d9f21d01a94b5ed70c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= <henrik@tjaders.com> Date: Sun, 5 Nov 2017 18:35:07 +0100 Subject: [PATCH] Print the last 3 attempts backwards --- src/main.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1861c88..d8dc771 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,13 +39,15 @@ fn main() { Ordering::Equal => { println!("You win!"); println!("Total number of attempts: {}", tries_counter); - println!("First print:"); - for x in attempt_history.iter() { - println!("{:?}", x); - } - println!("\nSecond print:"); - for x in attempt_history.iter() { + println!("Last entry first, maximum 3:"); + for (i, x) in attempt_history.iter().rev().enumerate() { println!("{:?}", x); + // Only print the 3 last (see .rev() above) + if i >= 2 { + break; + } + + } break; } -- GitLab