From dddad80f0ed6392d2b08251daacc7dea69cf4275 Mon Sep 17 00:00:00 2001 From: "R. Tyler Croy" Date: Sun, 13 Mar 2011 20:25:04 -0700 Subject: [PATCH] Add solution for problem five --- five.adb | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 five.adb diff --git a/five.adb b/five.adb new file mode 100644 index 0000000..9898f69 --- /dev/null +++ b/five.adb @@ -0,0 +1,42 @@ +-- +-- Project Euler problem #5 +-- +-- 2520 is the smallest number that can be divided by each of the numbers from +-- 1 to 10 without any remainder. +-- +-- What is the smallest positive number that is evenly divisible by all of the +-- numbers from 1 to 20? + +with Ada.Text_IO; + +use Ada.Text_IO; + +procedure Five is + Valid_Numbers : array (1 .. 20) of Natural; + -- Stepping up with the highest number we need to be a multiple of + Step : constant Natural := Valid_Numbers'Last; + Should_Continue : Boolean := true; + Value : Natural := 0; + + -- Divisible_By_Set will return early with false as soon as it hits on a + -- number that is not cleanly divisible (i.e. no remainer) + function Divisible_By_Set (Number : in Natural) return Boolean is + begin + for Item in Valid_Numbers'Range loop + if (Number mod Item) /= 0 then + return false; + end if; + end loop; + return true; + end Divisible_By_Set; +begin + while Should_Continue loop + Value := (Value + Step); + + if Divisible_By_Set (Value) then + Should_Continue := false; + end if; + end loop; + + Put_Line (Natural'Image (Value)); +end Five;