forked from codechefPesuecc/CodeChef-PESUECC-Chapter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoints.ts
More file actions
48 lines (43 loc) · 1.57 KB
/
Copy pathpoints.ts
File metadata and controls
48 lines (43 loc) · 1.57 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* Arena scoring.
*
* The Problem of the Day is a speed bounty: points by finish order, the faster
* your accepted solution the more you earn, with everyone past the top nine still
* earning the base reward. A past problem solved for practice earns a flat base
* reward (`BASE_POINTS`) — never a speed bounty. See `@/lib/scoring` for how the
* two combine into a user's total.
*/
export const SPEED_BOUNTY = [
1000, 800, 600, 500, 400, 300, 250, 200, 150,
] as const;
/** Reward for every accepted solver who finishes 10th or later. */
export const BASE_POINTS = 100;
/** More than this many integrity flags drops a solve to the base points. */
export const FLAG_LIMIT = 5;
/** Points earned for finishing an accepted solution at a given 1-based rank. */
export function pointsForRank(rank: number): number {
if (rank >= 1 && rank <= SPEED_BOUNTY.length) {
return SPEED_BOUNTY[rank - 1];
}
return BASE_POINTS;
}
/** Ordinal label for a rank, e.g. 1 → "1st", 12 → "12th". */
export function ordinal(rank: number): string {
const mod100 = rank % 100;
if (mod100 >= 11 && mod100 <= 13) return `${rank}th`;
switch (rank % 10) {
case 1:
return `${rank}st`;
case 2:
return `${rank}nd`;
case 3:
return `${rank}rd`;
default:
return `${rank}th`;
}
}
/** Display rows for the "how scoring works" bounty ladder. */
export const BOUNTY_LADDER: { label: string; points: number }[] = [
...SPEED_BOUNTY.map((points, i) => ({ label: ordinal(i + 1), points })),
{ label: `${ordinal(SPEED_BOUNTY.length + 1)}+`, points: BASE_POINTS },
];