aboutsummaryrefslogtreecommitdiff
path: root/2015/14/puzzle-2.bc
blob: b471510b1b56a3a7278e292512b6255d3e374fd9 (plain) (blame)
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
scale = 0

/* Return the largest element from array `a` of length `l` */
define max(a[], l) {
	auto m, i
	for (i = 0; i < l; i++) {
		if (a[i] > m)
			m = a[i]
	}
	return m
}

define calc(speed[], time[], rest[], n) {
	auto i, j, k, p[], d[]
	
	for (i = 0; i < 2503; i++) {
		for (j = k = 0; j < n; j++) {
			if (i % (time[j] + rest[j]) < time[j])
				d[j] += speed[j]
			if (d[j] > k)
				k = d[j]
		}

		for (j = 0; j < n; j++) {
			if (d[j] == k)
				p[j] += 1
		}
	}

	return max(p[], n)
}