Sha256: 14626e2db3e184f8ec18369bafeacbbbb1c911a061f08ad19794cedc8bfd71eb

Contents?: true

Size: 636 Bytes

Versions: 68

Compression:

Stored size: 636 Bytes

Contents

open Base

type robot = {mutable index : int}

let index = ref (-1)

let unique_ids: int array =
  let ids = Array.init (26*26*1000) ~f:Fn.id in
  Array.permute ids;
  ids

let new_robot () =
  index := !index + 1;
  {index = unique_ids.(!index)}

let name r =
  let n = r.index in
  let letters_part = n / 1000 in
  let letter_A = Char.to_int 'A' in
  let first_letter = Char.of_int_exn (letter_A + (letters_part / 26)) in
  let second_letter = Char.of_int_exn (letter_A + (letters_part % 26)) in
  Printf.sprintf "%c%c%03d" first_letter second_letter (n % 1000)

let reset r =
  index := !index + 1;
  r.index <- unique_ids.(!index);

Version data entries

68 entries across 68 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.179 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.178 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.177 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.176 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.175 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.174 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.173 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.172 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.171 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.170 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.169 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.167 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.166 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.165 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.164 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.163 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.162 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.161 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.160 tracks/ocaml/exercises/robot-name/example.ml