aboutsummaryrefslogtreecommitdiff
path: root/challenge-153/deadmarshal/pascal/ch2.pas
blob: 9cdf2a836f7acdba0a1aa76ee19ff91b81a1383f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
program Ch2;

{$mode objfpc}
uses
   SysUtils;

function Factorial(N:Integer):Integer;
begin
   if(N = 0) then Factorial := 1
   else Factorial := n * Factorial(N-1);
end;

function Factorions(N:Integer):Boolean;
var
   Copy, Sum:Integer;
begin
   Copy := N;
   repeat
      Sum := Sum + Factorial((Copy mod 10));
      Copy := Copy div 10;
   until(Copy = 0);
   
   Result := Sum = N;
end;

var
   Num:Integer;
begin
   if(ParamCount <> 1) then
   begin
      WriteLn(StdErr, 'No args provided!');
      Halt(1);
   end;

   try
      Num := StrToInt(ParamStr(1));
   except
      on E:EConvertError do
	 Halt(1);
   end;

   WriteLn(Factorions(Num));
end.