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.98 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.97 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.96 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.95 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.94 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.93 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.92 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.91 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.90 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.89 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.88 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.87 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.86 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.85 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.84 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.83 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.82 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.81 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.80 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas
trackler-2.2.1.79 tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas