-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbowling.cs
38 lines (32 loc) · 1.13 KB
/
bowling.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
public class BowlingProgram {
public static Tuple<int, List<int>> score_frame( List<int> remaining_throws ) {
if( remaining_throws[0] == 10 && remaining_throws.Count >= 3) {
var score = 10 + remaining_throws[1] + remaining_throws[2];
return Tuple.Create(score, remaining_throws.Skip(1));
}
if( remaining_throws.Count >= 3 && remaining_throws[0]+remaining_throws[1] == 10) {
var score = 10 + remaining_throws[2];
return Tuple.Create(score, remaining_throws.Skip(2));
}
if( remaining_throws.Count >= 2) {
var score = remaining_throws[0]+remaining_throws[1];
return Tuple.Create(score, remaining_throws.Skip(2));
}
}
public static int score_game(int frame_number, List<int> throws) {
if(frame_number == 10) {
return 0;
}
else {
var score_tup = score_frame(throws);
var score = score_tup.Item1;
var remaining_throws = score_tup.Item2;
return score + score_game(frame_number+1, remaining_throws);
}
}
public static int bowl(List<int> throwlist) {
var zeros = new List<int>() { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
return score_game(0, throwlist.Concat(zeros));
}
}