/euler001/Euler001.adb
Ada | 60 lines | 33 code | 6 blank | 21 comment | 4 complexity | 84c36d9680e1603b186f5d974e60f314 MD5 | raw file
- pragma License ( GPL );
- ------------------------------------------------------------------------------
- -- Author: darkestkhan --
- -- Email: darkestkhan@gmail.com --
- -- License: GNU GPLv3 or any later as published by Free Software Foundation --
- -- ( see license.txt file ) --
- -- Copyright  2011 darkestkhan --
- ------------------------------------------------------------------------------
- -- This Program is Free Software: You Can Redistribute It and/or Modify --
- -- It Under The Terms of The GNU General Public License As Published By --
- -- The Free Software Foundation, Either Version 3 of The License, or --
- -- (at Your Option) Any Later Version. --
- -- --
- -- This Program is Distributed in The Hope That It Will Be Useful, --
- -- But WITHOUT ANY WARRANTY; Without Even The Implied Warranty of --
- -- MERCHANTABILITY or FITNESS for A PARTICULAR PURPOSE. See The --
- -- GNU General Public License for More Details. --
- -- --
- -- You Should Have Received A Copy of The GNU General Public License --
- -- Along with This Program. if not, See <Http://Www.Gnu.Org/Licenses/>. --
- ------------------------------------------------------------------------------
- with Ada.Text_IO;
- with Ada.Command_Line;
- with Ada.IO_Exceptions;
- procedure Euler001 is
- function Sum_Up_To ( Limit: in Integer ) return Integer is
- Sum: Natural := 0;
- I: Integer := 3;
- begin
- while I < Limit loop
- Sum := Sum + I;
- I := I + 3;
- end loop;
- I := 5;
- while I < Limit loop
- if I mod 3 /= 0 then
- Sum := Sum + I;
- end if;
- I := I + 5;
- end loop;
- return Sum;
- end Sum_Up_To;
- Sum: Integer;
- Limit: Integer;
- begin
- for Index in 1 .. Ada.Command_Line.Argument_Count loop
- Limit := Integer'Value ( Ada.Command_Line.Argument ( Index ) );
- --NOTE if argument is greater than integer'range then data_error will be raised
- Sum := Sum_Up_To ( Limit => Limit );
- Ada.Text_IO.Put_Line ( "The sum of numbers divisible by 3 or 5, but less than " & Ada.Command_Line.Argument ( Index ) & " is " & Sum'img );
- end loop;
- exception
- when Ada.IO_Exceptions.Data_Error => Ada.Text_IO.Put_Line ( "One of arguments was too big. Aborting. Aborting." );
- end Euler001;