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.139 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.138 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.137 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.136 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.135 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.134 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.133 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.132 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.131 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.130 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.129 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.128 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.127 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.126 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.125 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.124 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.123 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.122 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.121 tracks/ocaml/exercises/robot-name/example.ml
trackler-2.2.1.120 tracks/ocaml/exercises/robot-name/example.ml