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.159 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.158 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.157 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.156 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.155 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.154 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.153 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.152 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.151 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.150 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.149 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.148 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.147 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.146 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.145 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.144 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.143 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.142 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.141 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.140 tracks/ocaml/exercises/robot-name/example.ml