Skip to content

Instantly share code, notes, and snippets.

@JogoShugh
Created April 9, 2018 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JogoShugh/8552767d9a16b2ffafbcec336e344c9d to your computer and use it in GitHub Desktop.
Save JogoShugh/8552767d9a16b2ffafbcec336e344c9d to your computer and use it in GitHub Desktop.
Bowling
fun score rolls =
case rolls of
[] => 0
| n1::n2::n3::[] => n1 + n2 + n3
| n1::n2::n3::rest =>
if n1 = 10 then 10 + n2 + n3 + score (n2::n3::rest)
else if n1 < 10 andalso n1 + n2 = 10 then n1 + n2 + n3 + score (n3::rest)
else if n1 + n2 < 10 then n1 + n2 + score (n3::rest)
else score rest
| n1::rest => n1 + score rest
val gutters = score [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0
val all_2s = score [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2] = 40
val with_2_2s_then_3s = score [2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3] = 58
val alt_2s_and_5s = score [2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5] = 70
val first_spare_then_2s = score [0, 10, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2] = 48
val first_spares_2_8s_then_2s = score [2, 8, 2, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2] = 56
val fist_strike_then_2s = score [10, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2] = 50
val fist_2_strike_then_2s = score [10, 10, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2] = 68
val perfect = score [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10] = 300
val alt_strikes_and_spares = score [10, 2, 8, 10, 2, 8, 10, 2, 8, 10, 2, 8, 10, 2, 8, 10] = 200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment