Sha256: 3e505ced5822393c42c08dde3fd9bf9a1efd5c8047c38c3e50ff10b8bd8d79dd

Contents?: true

Size: 519 Bytes

Versions: 83

Compression:

Stored size: 519 Bytes

Contents

unit class Robot:ver<2>;

subset Name of Str where * ~~ /^<[A..Z]>**2 <[0..9]>**3$/;
has Name $.name = self.reset-name;

method reset-name {
  state Promise:D $promise = start ('AA000'..'ZZ999').pick: *;
  state Bool:D %record{Name:D};
  state Int:D $i = 0;

  if $promise.status ~~ 'Kept' {
    ($!name = $promise.result[$i++]) or die 'All names used.';
  } else {
    $!name = ('A'..'Z').roll(2).join ~ (^10).roll(3).join;
  }
  self.reset-name if %record{$!name}:exists;
  %record{$!name} = True;
  return $!name;
}

Version data entries

83 entries across 83 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/perl6/exercises/robot-name/.meta/solutions/Robot.pm6
trackler-2.2.1.179 tracks/perl6/exercises/robot-name/.meta/solutions/Robot.pm6
trackler-2.2.1.178 tracks/perl6/exercises/robot-name/.meta/solutions/Robot.pm6
trackler-2.2.1.177 tracks/perl6/exercises/robot-name/.meta/solutions/Robot.pm6
trackler-2.2.1.176 tracks/perl6/exercises/robot-name/.meta/solutions/Robot.pm6
trackler-2.2.1.175 tracks/perl6/exercises/robot-name/.meta/solutions/Robot.pm6
trackler-2.2.1.174 tracks/perl6/exercises/robot-name/.meta/solutions/Robot.pm6
trackler-2.2.1.173 tracks/perl6/exercises/robot-name/.meta/solutions/Robot.pm6
trackler-2.2.1.172 tracks/perl6/exercises/robot-name/.meta/solutions/Robot.pm6
trackler-2.2.1.171 tracks/perl6/exercises/robot-name/.meta/solutions/Robot.pm6
trackler-2.2.1.170 tracks/perl6/exercises/robot-name/.meta/solutions/Robot.pm6
trackler-2.2.1.169 tracks/perl6/exercises/robot-name/.meta/solutions/Robot.pm6
trackler-2.2.1.167 tracks/perl6/exercises/robot-name/.meta/solutions/Robot.pm6
trackler-2.2.1.166 tracks/perl6/exercises/robot-name/.meta/solutions/Robot.pm6
trackler-2.2.1.165 tracks/perl6/exercises/robot-name/.meta/solutions/Robot.pm6
trackler-2.2.1.164 tracks/perl6/exercises/robot-name/.meta/solutions/Robot.pm6
trackler-2.2.1.163 tracks/perl6/exercises/robot-name/.meta/solutions/Robot.pm6
trackler-2.2.1.162 tracks/perl6/exercises/robot-name/.meta/solutions/Robot.pm6
trackler-2.2.1.161 tracks/perl6/exercises/robot-name/.meta/solutions/Robot.pm6
trackler-2.2.1.160 tracks/perl6/exercises/robot-name/.meta/solutions/Robot.pm6