From a11230372ef7f2d6a338db5c60536bb5da49a9fe Mon Sep 17 00:00:00 2001 From: "R. Tyler Croy" Date: Sun, 13 Mar 2011 20:04:54 -0700 Subject: [PATCH] Simply the solution for four with the reverse keyword Can't believe I forgot about it --- four.adb | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/four.adb b/four.adb index 83aa21c..ae99aa6 100644 --- a/four.adb +++ b/four.adb @@ -49,24 +49,19 @@ procedure Four is Highest_Palindrome : Natural := 0; begin - for Offset in 0 .. Ceiling loop - declare - N : constant Natural := Ceiling - Offset; - begin - for Sub_Offset in 0 .. Ceiling loop - declare - J : constant Natural := Ceiling - Sub_Offset; - Product : constant Natural := J * N; - Bailout : constant Boolean := Is_Palindrome (Product); - begin - if Bailout then - if Product > Highest_Palindrome then - Highest_Palindrome := Product; - end if; + for N in reverse 1 .. Ceiling loop + for J in reverse 1 .. Ceiling loop + declare + Product : constant Natural := J * N; + Bailout : constant Boolean := Is_Palindrome (Product); + begin + if Bailout then + if Product > Highest_Palindrome then + Highest_Palindrome := Product; end if; - end; - end loop; - end; + end if; + end; + end loop; end loop; New_Line;