From 0c1f074fa73e68419dbc39cc3597dd6407023e49 Mon Sep 17 00:00:00 2001 From: Ivan Mahonin Date: Jan 18 2019 18:41:14 +0000 Subject: lazarus: lucky-number --- diff --git a/lazarus/lucky-number/project1.ico b/lazarus/lucky-number/project1.ico new file mode 100644 index 0000000..0341321 Binary files /dev/null and b/lazarus/lucky-number/project1.ico differ diff --git a/lazarus/lucky-number/project1.lpi b/lazarus/lucky-number/project1.lpi new file mode 100644 index 0000000..3afe492 --- /dev/null +++ b/lazarus/lucky-number/project1.lpi @@ -0,0 +1,79 @@ + + + + + + + + + <ResourceType Value="res"/> + <UseXPManifest Value="True"/> + <Icon Value="0"/> + </General> + <i18n> + <EnableI18N LFM="False"/> + </i18n> + <VersionInfo> + <StringTable ProductVersion=""/> + </VersionInfo> + <BuildModes Count="1"> + <Item1 Name="Default" Default="True"/> + </BuildModes> + <PublishOptions> + <Version Value="2"/> + </PublishOptions> + <RunParams> + <local> + <FormatVersion Value="1"/> + </local> + </RunParams> + <RequiredPackages Count="1"> + <Item1> + <PackageName Value="LCL"/> + </Item1> + </RequiredPackages> + <Units Count="2"> + <Unit0> + <Filename Value="project1.lpr"/> + <IsPartOfProject Value="True"/> + </Unit0> + <Unit1> + <Filename Value="unit1.pas"/> + <IsPartOfProject Value="True"/> + <ComponentName Value="Form1"/> + <ResourceBaseClass Value="Form"/> + <UnitName Value="Unit1"/> + </Unit1> + </Units> + </ProjectOptions> + <CompilerOptions> + <Version Value="11"/> + <Target> + <Filename Value="project1"/> + </Target> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir)"/> + <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> + </SearchPaths> + <Linking> + <Options> + <Win32> + <GraphicApplication Value="True"/> + </Win32> + </Options> + </Linking> + </CompilerOptions> + <Debugging> + <Exceptions Count="3"> + <Item1> + <Name Value="EAbort"/> + </Item1> + <Item2> + <Name Value="ECodetoolError"/> + </Item2> + <Item3> + <Name Value="EFOpenError"/> + </Item3> + </Exceptions> + </Debugging> +</CONFIG> diff --git a/lazarus/lucky-number/project1.lpr b/lazarus/lucky-number/project1.lpr new file mode 100644 index 0000000..58c35dc --- /dev/null +++ b/lazarus/lucky-number/project1.lpr @@ -0,0 +1,21 @@ +program project1; + +{$mode objfpc}{$H+} + +uses + {$IFDEF UNIX}{$IFDEF UseCThreads} + cthreads, + {$ENDIF}{$ENDIF} + Interfaces, // this includes the LCL widgetset + Forms, Unit1 + { you can add units after this }; + +{$R *.res} + +begin + RequireDerivedFormResource:=True; + Application.Initialize; + Application.CreateForm(TForm1, Form1); + Application.Run; +end. + diff --git a/lazarus/lucky-number/project1.res b/lazarus/lucky-number/project1.res new file mode 100644 index 0000000..e994dfa Binary files /dev/null and b/lazarus/lucky-number/project1.res differ diff --git a/lazarus/lucky-number/unit1.lfm b/lazarus/lucky-number/unit1.lfm new file mode 100644 index 0000000..2b59c08 --- /dev/null +++ b/lazarus/lucky-number/unit1.lfm @@ -0,0 +1,52 @@ +object Form1: TForm1 + Left = 319 + Height = 321 + Top = 261 + Width = 518 + Caption = 'Form1' + ClientHeight = 321 + ClientWidth = 518 + LCLVersion = '1.6.2.0' + object Edit1: TEdit + Left = 16 + Height = 38 + Top = 24 + Width = 128 + TabOrder = 0 + Text = '000000' + end + object Button1: TButton + Left = 16 + Height = 25 + Top = 72 + Width = 128 + Caption = 'Check' + OnClick = Button1Click + TabOrder = 1 + end + object Button2: TButton + Left = 16 + Height = 25 + Top = 104 + Width = 128 + Caption = 'Check 2' + OnClick = Button2Click + TabOrder = 2 + end + object Label1: TLabel + Left = 16 + Height = 21 + Top = 144 + Width = 12 + Caption = '--' + ParentColor = False + end + object Label2: TLabel + Left = 16 + Height = 105 + Top = 184 + Width = 347 + Caption = 'Check six-digit number for luckiness.'#10'The number ABCDEF is lucky when A+B+C = D+E+F.'#10#10'''Check'' and ''Check 2'' gives a same results,'#10'but uses a different algorithms internally.' + ParentColor = False + end +end diff --git a/lazarus/lucky-number/unit1.pas b/lazarus/lucky-number/unit1.pas new file mode 100644 index 0000000..54c79c6 --- /dev/null +++ b/lazarus/lucky-number/unit1.pas @@ -0,0 +1,92 @@ +unit Unit1; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, + Math; + +type + + { TForm1 } + + TForm1 = class(TForm) + Button1: TButton; + Button2: TButton; + Edit1: TEdit; + Label1: TLabel; + Label2: TLabel; + procedure Button1Click(Sender: TObject); + procedure Button2Click(Sender: TObject); + private + { private declarations } + public + { public declarations } + end; + +var + Form1: TForm1; + +implementation + +{$R *.lfm} + +procedure TForm1.Button1Click(Sender: TObject); +var + num: integer; + n1, n2, n3, n4, n5, n6, sum1, sum2: integer; +begin + num := StrToInt(Edit1.Text); + + n1 := num mod 10; + n2 := (num div 10) mod 10; + n3 := (num div 100) mod 10; + n4 := (num div 1000) mod 10; + n5 := (num div 10000) mod 10; + n6 := num div 100000; + + sum1 := n1 + n2 + n3; + sum2 := n4 + n5 + n6; + + if sum1 = sum2 then + Label1.Caption := 'Счастливый' + else + Label1.Caption := 'Обычный'; +end; + +// extract digit from number +function digit(num, pos: integer): integer; +var + x: integer; +begin + x := round(Power(10, pos)); + Result := (num div x) mod 10; +end; + +// here, for new experience, we will +// extract digits from integer instead of string +procedure TForm1.Button2Click(Sender: TObject); +var + num: integer; + i, sum1, sum2: integer; +begin + num := StrToInt(Edit1.Text); + + sum1 := 0; + sum2 := 0; + + for i := 0 to 2 do begin + sum1 := sum1 + digit(num, i); + sum2 := sum2 + digit(num, i+3); + end; + + if sum1 = sum2 then + Label1.Caption := 'Счастливый' + else + Label1.Caption := 'Обычный'; +end; + +end. +