aboutsummaryrefslogtreecommitdiff
path: root/2015/14/puzzle-2.bc
diff options
context:
space:
mode:
authorThomas Voss <thomasvoss@live.com> 2021-10-29 23:02:39 +0200
committerThomas Voss <thomasvoss@live.com> 2021-10-29 23:02:39 +0200
commite7c9108b95e39d7ea5a29ae06d619c4727f11027 (patch)
tree237261eef3afd0720be77dbcbb9599fa66a24b67 /2015/14/puzzle-2.bc
Initial commit
Diffstat (limited to '2015/14/puzzle-2.bc')
-rw-r--r--2015/14/puzzle-2.bc33
1 files changed, 33 insertions, 0 deletions
diff --git a/2015/14/puzzle-2.bc b/2015/14/puzzle-2.bc
new file mode 100644
index 0000000..4a41277
--- /dev/null
+++ b/2015/14/puzzle-2.bc
@@ -0,0 +1,33 @@
+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)
+}