Sha256: 7b1df72072d3f8fcecece472143338a8d4be621fc5d6eb1f2058000169383396

Contents?: true

Size: 1.39 KB

Versions: 104

Compression:

Stored size: 1.39 KB

Contents

unit uSecretHandshake;

interface
uses Generics.Collections;

type
  TSecretHandshake = class
  private
    class var CommandValues: TList<TPair<integer, string>>;
    class procedure BuildCommandValues;
    class function ShouldReverse(aCommandValue: integer): Boolean;
  public
    class function commands(aInput: integer): TArray<string>;
  end;

implementation
uses SysUtils;

{ TSecretHandshake }

class procedure TSecretHandshake.BuildCommandValues;
begin
  if not assigned(CommandValues) then
  begin
    CommandValues := TList<TPair<integer, string>>.Create;
    CommandValues.Add(TPair<integer,string>.Create(1, 'wink'));
    CommandValues.Add(TPair<integer,string>.Create(2, 'double blink'));
    CommandValues.Add(TPair<integer,string>.Create(4, 'close your eyes'));
    CommandValues.Add(TPair<integer,string>.Create(8, 'jump'));
  end;
end;

class function TSecretHandshake.commands(aInput: integer): TArray<string>;
var lCommands: TList<string>;
    lKeyValue: TPair<integer,string>;
begin
  BuildCommandValues;
  lCommands := TList<string>.Create;

  for lKeyValue in CommandValues do
  begin
    if aInput and lKeyValue.Key <> 0 then
      lCommands.Add(lKeyValue.Value);
  end;

  if ShouldReverse(aInput) then
    lCommands.Reverse;
  result := lCommands.ToArray;
end;

class function TSecretHandshake.ShouldReverse(aCommandValue: integer): Boolean;
begin
  result := (aCommandValue and 16) <> 0;
end;

end.

Version data entries

104 entries across 104 versions & 1 rubygems

Version Path
trackler-2.2.1.119 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.118 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.117 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.116 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.115 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.114 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.113 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.111 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.110 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.109 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.108 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.107 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.106 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.105 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.104 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.103 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.102 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.101 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.100 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.99 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas