Sha256: 1d0ac20c45c77981d9d6ed65b609c75b0beaac68e5edf54332a5c9180ad25032

Contents?: true

Size: 688 Bytes

Versions: 167

Compression:

Stored size: 688 Bytes

Contents

open Core.Std

type t = int list

(* Calculates a list of the frame scores. t1 is the score for throw 1. *)
let frame_scores =
  let is_spare t1 t2 = t1 + t2 = 10 in
  let rec go acc = function
    | [t1; t2] -> (t1 + t2) :: acc
    | [t1; t2; t3] -> (t1 + t2 + t3) :: acc
    | t1 :: t2 :: t3 :: ts when t1 = 10 -> go (10 + t2 + t3 :: acc) (t2 :: t3 :: ts)
    | t1 :: t2 :: t3 :: ts when is_spare t1 t2 -> go (10 + t3 :: acc) (t3 :: ts)
    | t1 :: t2 :: t3 :: ts -> go (t1 + t2 :: acc) (t3 :: ts)
    | _ -> failwith "this is expected to be unreachable code"
  in go []

let new_game = []
let roll pins g = pins :: g
let score g = frame_scores (List.rev g) |> List.fold ~init:0 ~f:(+)

Version data entries

167 entries across 167 versions & 1 rubygems

Version Path
trackler-2.1.0.11 tracks/ocaml/exercises/bowling/example.ml
trackler-2.1.0.10 tracks/ocaml/exercises/bowling/example.ml
trackler-2.1.0.9 tracks/ocaml/exercises/bowling/example.ml
trackler-2.1.0.8 tracks/ocaml/exercises/bowling/example.ml
trackler-2.1.0.7 tracks/ocaml/exercises/bowling/example.ml
trackler-2.1.0.6 tracks/ocaml/exercises/bowling/example.ml
trackler-2.1.0.5 tracks/ocaml/exercises/bowling/example.ml
trackler-2.1.0.4 tracks/ocaml/exercises/bowling/example.ml
trackler-2.1.0.3 tracks/ocaml/exercises/bowling/example.ml
trackler-2.1.0.2 tracks/ocaml/exercises/bowling/example.ml
trackler-2.1.0.1 tracks/ocaml/exercises/bowling/example.ml
trackler-2.1.0.0 tracks/ocaml/exercises/bowling/example.ml
trackler-2.0.8.55 tracks/ocaml/exercises/bowling/example.ml
trackler-2.0.8.54 tracks/ocaml/exercises/bowling/example.ml
trackler-2.0.8.53 tracks/ocaml/exercises/bowling/example.ml
trackler-2.0.8.52 tracks/ocaml/exercises/bowling/example.ml
trackler-2.0.8.51 tracks/ocaml/exercises/bowling/example.ml
trackler-2.0.8.50 tracks/ocaml/exercises/bowling/example.ml
trackler-2.0.8.49 tracks/ocaml/exercises/bowling/example.ml
trackler-2.0.8.48 tracks/ocaml/exercises/bowling/example.ml