birgermoell commited on
Commit
6190c97
·
verified ·
1 Parent(s): 35432b0

Add 108 offline Harbor tasks for means-test

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. tasks/means-test/means-test-change-d1-e0000/environment/Dockerfile +3 -0
  2. tasks/means-test/means-test-change-d1-e0000/environment/workdir/cases.json +213 -0
  3. tasks/means-test/means-test-change-d1-e0000/environment/workdir/regulation.md +89 -0
  4. tasks/means-test/means-test-change-d1-e0000/instruction.md +18 -0
  5. tasks/means-test/means-test-change-d1-e0000/solution/oracle.py +155 -0
  6. tasks/means-test/means-test-change-d1-e0000/solution/solve.sh +4 -0
  7. tasks/means-test/means-test-change-d1-e0000/task.toml +25 -0
  8. tasks/means-test/means-test-change-d1-e0000/tests/checks.json +100 -0
  9. tasks/means-test/means-test-change-d1-e0000/tests/test.sh +3 -0
  10. tasks/means-test/means-test-change-d1-e0000/tests/verify.py +116 -0
  11. tasks/means-test/means-test-change-d1-e0012/environment/Dockerfile +3 -0
  12. tasks/means-test/means-test-change-d1-e0012/environment/workdir/cases.json +173 -0
  13. tasks/means-test/means-test-change-d1-e0012/environment/workdir/regulation.md +89 -0
  14. tasks/means-test/means-test-change-d1-e0012/instruction.md +18 -0
  15. tasks/means-test/means-test-change-d1-e0012/solution/oracle.py +155 -0
  16. tasks/means-test/means-test-change-d1-e0012/solution/solve.sh +4 -0
  17. tasks/means-test/means-test-change-d1-e0012/task.toml +25 -0
  18. tasks/means-test/means-test-change-d1-e0012/tests/checks.json +100 -0
  19. tasks/means-test/means-test-change-d1-e0012/tests/test.sh +3 -0
  20. tasks/means-test/means-test-change-d1-e0012/tests/verify.py +116 -0
  21. tasks/means-test/means-test-change-d1-t0000/environment/Dockerfile +3 -0
  22. tasks/means-test/means-test-change-d1-t0000/environment/workdir/cases.json +164 -0
  23. tasks/means-test/means-test-change-d1-t0000/environment/workdir/regulation.md +89 -0
  24. tasks/means-test/means-test-change-d1-t0000/instruction.md +18 -0
  25. tasks/means-test/means-test-change-d1-t0000/solution/oracle.py +155 -0
  26. tasks/means-test/means-test-change-d1-t0000/solution/solve.sh +4 -0
  27. tasks/means-test/means-test-change-d1-t0000/task.toml +25 -0
  28. tasks/means-test/means-test-change-d1-t0000/tests/checks.json +100 -0
  29. tasks/means-test/means-test-change-d1-t0000/tests/test.sh +3 -0
  30. tasks/means-test/means-test-change-d1-t0000/tests/verify.py +116 -0
  31. tasks/means-test/means-test-change-d1-t0012/environment/Dockerfile +3 -0
  32. tasks/means-test/means-test-change-d1-t0012/environment/workdir/cases.json +158 -0
  33. tasks/means-test/means-test-change-d1-t0012/environment/workdir/regulation.md +89 -0
  34. tasks/means-test/means-test-change-d1-t0012/instruction.md +18 -0
  35. tasks/means-test/means-test-change-d1-t0012/solution/oracle.py +155 -0
  36. tasks/means-test/means-test-change-d1-t0012/solution/solve.sh +4 -0
  37. tasks/means-test/means-test-change-d1-t0012/task.toml +25 -0
  38. tasks/means-test/means-test-change-d1-t0012/tests/checks.json +100 -0
  39. tasks/means-test/means-test-change-d1-t0012/tests/test.sh +3 -0
  40. tasks/means-test/means-test-change-d1-t0012/tests/verify.py +116 -0
  41. tasks/means-test/means-test-change-d1-t0024/environment/Dockerfile +3 -0
  42. tasks/means-test/means-test-change-d1-t0024/environment/workdir/cases.json +136 -0
  43. tasks/means-test/means-test-change-d1-t0024/environment/workdir/regulation.md +89 -0
  44. tasks/means-test/means-test-change-d1-t0024/instruction.md +18 -0
  45. tasks/means-test/means-test-change-d1-t0024/solution/oracle.py +155 -0
  46. tasks/means-test/means-test-change-d1-t0024/solution/solve.sh +4 -0
  47. tasks/means-test/means-test-change-d1-t0024/task.toml +25 -0
  48. tasks/means-test/means-test-change-d1-t0024/tests/checks.json +100 -0
  49. tasks/means-test/means-test-change-d1-t0024/tests/test.sh +3 -0
  50. tasks/means-test/means-test-change-d1-t0024/tests/verify.py +116 -0
tasks/means-test/means-test-change-d1-e0000/environment/Dockerfile ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ FROM python:3.12-slim
2
+ WORKDIR /app
3
+ COPY workdir/ /app/
tasks/means-test/means-test-change-d1-e0000/environment/workdir/cases.json ADDED
@@ -0,0 +1,213 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "municipality": "Eskermark",
3
+ "month": "2026-03",
4
+ "days_in_month": 31,
5
+ "cases": [
6
+ {
7
+ "case_id": "H4578",
8
+ "caseworker": "LB",
9
+ "members": [
10
+ {
11
+ "person": "P1",
12
+ "role": "applicant",
13
+ "age": 35,
14
+ "income": [
15
+ {
16
+ "type": "earnings",
17
+ "amount": 3500
18
+ }
19
+ ]
20
+ },
21
+ {
22
+ "person": "P2",
23
+ "role": "partner",
24
+ "age": 32,
25
+ "income": [
26
+ {
27
+ "type": "unemployment_benefit",
28
+ "amount": 3500
29
+ }
30
+ ]
31
+ },
32
+ {
33
+ "person": "P3",
34
+ "role": "child",
35
+ "age": 8,
36
+ "income": [
37
+ {
38
+ "type": "child_benefit",
39
+ "amount": 700
40
+ }
41
+ ]
42
+ }
43
+ ],
44
+ "monthly_rent": 6050,
45
+ "liquid_assets": 1600,
46
+ "changes": [
47
+ {
48
+ "date": "2026-03-17",
49
+ "type": "income_change",
50
+ "person": "P2",
51
+ "income": [
52
+ {
53
+ "type": "earnings",
54
+ "amount": 6800
55
+ }
56
+ ]
57
+ }
58
+ ]
59
+ },
60
+ {
61
+ "case_id": "H4260",
62
+ "caseworker": "OH",
63
+ "members": [
64
+ {
65
+ "person": "P1",
66
+ "role": "applicant",
67
+ "age": 56,
68
+ "income": [
69
+ {
70
+ "type": "sickness_benefit",
71
+ "amount": 5350
72
+ }
73
+ ]
74
+ },
75
+ {
76
+ "person": "P2",
77
+ "role": "partner",
78
+ "age": 57,
79
+ "income": [
80
+ {
81
+ "type": "earnings",
82
+ "amount": 3100
83
+ }
84
+ ]
85
+ },
86
+ {
87
+ "person": "P3",
88
+ "role": "child",
89
+ "age": 3,
90
+ "income": [
91
+ {
92
+ "type": "child_benefit",
93
+ "amount": 600
94
+ }
95
+ ]
96
+ },
97
+ {
98
+ "person": "P4",
99
+ "role": "child",
100
+ "age": 0,
101
+ "income": [
102
+ {
103
+ "type": "child_benefit",
104
+ "amount": 600
105
+ }
106
+ ]
107
+ },
108
+ {
109
+ "person": "P5",
110
+ "role": "child",
111
+ "age": 2,
112
+ "income": [
113
+ {
114
+ "type": "child_benefit",
115
+ "amount": 700
116
+ }
117
+ ]
118
+ }
119
+ ],
120
+ "monthly_rent": 8450,
121
+ "liquid_assets": 3700,
122
+ "changes": [
123
+ {
124
+ "date": "2026-03-29",
125
+ "type": "income_change",
126
+ "person": "P1",
127
+ "income": [
128
+ {
129
+ "type": "earnings",
130
+ "amount": 8500
131
+ }
132
+ ]
133
+ }
134
+ ]
135
+ },
136
+ {
137
+ "case_id": "H5201",
138
+ "caseworker": "ES",
139
+ "members": [
140
+ {
141
+ "person": "P1",
142
+ "role": "applicant",
143
+ "age": 46,
144
+ "income": [
145
+ {
146
+ "type": "earnings",
147
+ "amount": 4600
148
+ }
149
+ ]
150
+ },
151
+ {
152
+ "person": "P2",
153
+ "role": "partner",
154
+ "age": 20,
155
+ "income": [
156
+ {
157
+ "type": "unemployment_benefit",
158
+ "amount": 3550
159
+ }
160
+ ]
161
+ },
162
+ {
163
+ "person": "P3",
164
+ "role": "child",
165
+ "age": 13,
166
+ "income": [
167
+ {
168
+ "type": "child_benefit",
169
+ "amount": 700
170
+ }
171
+ ]
172
+ },
173
+ {
174
+ "person": "P4",
175
+ "role": "child",
176
+ "age": 14,
177
+ "income": [
178
+ {
179
+ "type": "child_benefit",
180
+ "amount": 650
181
+ }
182
+ ]
183
+ },
184
+ {
185
+ "person": "P5",
186
+ "role": "child",
187
+ "age": 8,
188
+ "income": [
189
+ {
190
+ "type": "child_benefit",
191
+ "amount": 700
192
+ }
193
+ ]
194
+ }
195
+ ],
196
+ "monthly_rent": 9650,
197
+ "liquid_assets": 2900,
198
+ "changes": [
199
+ {
200
+ "date": "2026-03-05",
201
+ "type": "income_change",
202
+ "person": "P2",
203
+ "income": [
204
+ {
205
+ "type": "earnings",
206
+ "amount": 7300
207
+ }
208
+ ]
209
+ }
210
+ ]
211
+ }
212
+ ]
213
+ }
tasks/means-test/means-test-change-d1-e0000/environment/workdir/regulation.md ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Eskermark Local Support Ordinance (fictional)
2
+
3
+ The Municipality of Eskermark, this ordinance and every amount in it are invented for practice. They do not describe any real benefit scheme. All amounts are per calendar month and in florins (fl). Do not round intermediate results.
4
+
5
+ ## 1. The household
6
+
7
+ The household's **members** are the applicant, the applicant's partner if they live together, and their children under 18 who live with them. In a case file these have the role `applicant`, `partner` or `child`. The applicant and the partner are the adult members.
8
+
9
+ Anyone else who lives in the home has the role `other_resident` (for example a grown-up child or a lodger). An other resident is not a member: their income is ignored and they add nothing to the norm, but they count as a resident when the rent is shared out (section 3).
10
+
11
+ ## 2. The norm
12
+
13
+ The norm is the adult amount plus the child amounts plus the common costs.
14
+
15
+ | Adult amount | fl |
16
+ |---|---|
17
+ | One adult member | 4100 |
18
+ | Two adult members (a couple) | 6900 |
19
+
20
+ | Child amount, for each child member | fl |
21
+ |---|---|
22
+ | Age 0 to 5 | 1450 |
23
+ | Age 6 to 12 | 1800 |
24
+ | Age 13 to 17 | 2250 |
25
+
26
+ | Common costs, by number of members | fl |
27
+ |---|---|
28
+ | 1 | 900 |
29
+ | 2 | 1100 |
30
+ | 3 | 1350 |
31
+ | 4 | 1550 |
32
+ | 5 | 1750 |
33
+ | 6 or more | 1900 |
34
+
35
+ Sanction: if the case file records `sanction_level` 1, the adult amount is reduced by 15%. At `sanction_level` 2 it is reduced by 30%. The child amounts and the common costs are never reduced. Level 0, or no entry, means no sanction.
36
+
37
+ ## 3. Housing allowance
38
+
39
+ The household's rent share is the monthly rent times the number of members, divided by the number of residents (members plus other residents). With no other residents the rent share is the whole rent.
40
+
41
+ The housing allowance is the rent share, but not more than the cap for the number of members:
42
+
43
+ | Number of members | Cap, fl |
44
+ |---|---|
45
+ | 1 | 5200 |
46
+ | 2 | 6400 |
47
+ | 3 | 7300 |
48
+ | 4 | 8100 |
49
+ | 5 or more | 8800 |
50
+
51
+ ## 4. Countable income
52
+
53
+ Each person's income is listed by type.
54
+
55
+ - `earnings` of an adult member: add up that adult's earnings, then take off the work disregard, which is 25% of that adult's earnings but not more than 1200 fl per adult. What is left counts.
56
+ - Counted in full, whichever member receives it: `child_benefit`, `maintenance`, `pension`, `unemployment_benefit`, `sickness_benefit`.
57
+ - Not counted at all: `disability_allowance`, `funeral_grant`, `school_meal_voucher`, and any `earnings` of a child member.
58
+
59
+ Countable income is the sum over all members.
60
+
61
+ ## 5. Assets
62
+
63
+ The asset exemption is 8000 fl for a household with one adult member and 12000 fl for a couple, plus 1500 fl for each child member. The asset excess is the household's liquid assets minus the exemption, or 0 if that is negative. The asset excess is assessed afresh for every month and every period, with the exemption of the household as it then is.
64
+
65
+ ## 6. Monthly entitlement
66
+
67
+ entitlement = norm + housing allowance - countable income - asset excess
68
+
69
+ If this is negative, the entitlement is 0 and the household has no entitlement. For a month in which nothing changes, the benefit payable is the entitlement.
70
+
71
+ ## 7. Changes during a month
72
+
73
+ A change takes effect on its date: that day and the days after it are assessed on the new circumstances. Split the month into periods at each change date. For each period, work out the monthly entitlement (sections 2 to 6) as if the circumstances of that period had lasted the whole month. Then
74
+
75
+ benefit payable for the month = sum over the periods of (monthly entitlement of the period * days in the period / days in the month)
76
+
77
+ If a case file gives a `claim_date`, no benefit is payable for the days before it: the first period starts on the claim date.
78
+
79
+ ## 8. Overpayments and recovery
80
+
81
+ When benefit has been paid on circumstances that later prove to have been different, then for each month under review:
82
+
83
+ correct benefit = the benefit payable for that month on the true circumstances (using section 7 if the change came during the month)
84
+ overpayment = amount paid - correct benefit
85
+
86
+ The total overpayment is the sum over the months under review.
87
+
88
+ - A total overpayment under 300 fl is written off: nothing is recovered.
89
+ - Otherwise it is recovered by a monthly deduction of 10% of the unsanctioned adult amount of the household as it is after the change (410 fl for one adult member, 690 fl for a couple) until the total is repaid. The number of deductions is the total overpayment divided by the monthly deduction, rounded up. Every deduction is the full monthly deduction except the last, which is whatever is still owed.
tasks/means-test/means-test-change-d1-e0000/instruction.md ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Means test: a change during the month
2
+
3
+ `cases.json` holds 3 household case files from the Municipality of Eskermark for 2026-03 (31 days). Each file shows the household as it was on the first day of the month and a list of `changes`, each with the date it takes effect. `regulation.md` is the ordinance to apply (it is fictional; use its rules and amounts exactly). Section 7 says how to handle a change during the month.
4
+
5
+ The kinds of change are:
6
+
7
+ - `income_change`: the named person's whole income list is replaced by the list given.
8
+
9
+ Write `answer.json` in this folder, a JSON object with:
10
+
11
+ - `cases`: an object keyed by case id. Each value has
12
+ - `days`: a list of integers, the number of days in each period, in date order.
13
+ - `rates`: a list of numbers, the monthly entitlement (section 6) of each period, in the same order, fl with 2 decimals.
14
+ - `payable`: the benefit payable for the month, fl with 2 decimals.
15
+ - `nothing_payable`: list of the case ids for which nothing is payable for the month (any order; an empty list if none).
16
+ - `total_payable`: the sum of `payable` over all the cases, fl with 2 decimals.
17
+
18
+ Numbers are accepted within one unit of the last decimal place asked for.
tasks/means-test/means-test-change-d1-e0000/solution/oracle.py ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Reference solution for Means Test. Works only from the files in the current directory.
3
+ The rates below are read off regulation.md (Eskermark Local Support Ordinance, fictional)."""
4
+ import json, os
5
+ from fractions import Fraction as F
6
+
7
+ ADULT_ONE, ADULT_COUPLE = 4100, 6900
8
+ COMMON_COSTS = [900, 1100, 1350, 1550, 1750, 1900] # 1, 2, 3, 4, 5, 6 or more members
9
+ RENT_CAPS = [5200, 6400, 7300, 8100, 8800] # 1, 2, 3, 4, 5 or more members
10
+ FULLY_COUNTED = set(["child_benefit", "maintenance", "pension", "unemployment_benefit", "sickness_benefit"])
11
+
12
+ def load(name):
13
+ with open(name) as f: return json.load(f)
14
+
15
+ def money(x): return round(float(x), 2)
16
+
17
+ def assess(case):
18
+ people = case["members"]
19
+ grown = [p for p in people if p["role"] == "applicant" or p["role"] == "partner"]
20
+ young = [p for p in people if p["role"] == "child"]
21
+ size = len(grown) + len(young)
22
+ # section 2
23
+ adult = F(ADULT_COUPLE if len(grown) == 2 else ADULT_ONE)
24
+ level = case.get("sanction_level") or 0
25
+ if level == 1: adult -= adult * F(15, 100)
26
+ elif level == 2: adult -= adult * F(30, 100)
27
+ norm = adult + COMMON_COSTS[min(size, 6) - 1]
28
+ for p in young:
29
+ norm += 1450 if p["age"] < 6 else 1800 if p["age"] < 13 else 2250
30
+ # section 3
31
+ share = F(case["monthly_rent"]) * size / len(people)
32
+ housing = min(share, F(RENT_CAPS[min(size, 5) - 1]))
33
+ # section 4
34
+ income = F(0)
35
+ for p in grown + young:
36
+ wages = F(0)
37
+ for line in p.get("income", []):
38
+ if line["type"] == "earnings": wages += F(str(line["amount"]))
39
+ elif line["type"] in FULLY_COUNTED: income += F(str(line["amount"]))
40
+ if p["role"] != "child":
41
+ income += wages - min(wages / 4, F(1200))
42
+ # section 5
43
+ allowed = (12000 if len(grown) == 2 else 8000) + 1500 * len(young)
44
+ excess = max(F(0), F(case["liquid_assets"]) - allowed)
45
+ # section 6
46
+ ent = max(F(0), norm + housing - income - excess)
47
+ return {"norm": norm, "countable_income": income, "housing_allowance": housing, "asset_excess": excess, "benefit": ent, "adults": len(grown)}
48
+
49
+ def changed(case, ch):
50
+ new = json.loads(json.dumps(case))
51
+ kind = ch["type"]
52
+ if kind == "income_change":
53
+ for p in new["members"]:
54
+ if p["person"] == ch["person"]: p["income"] = ch["income"]
55
+ elif kind == "rent_change": new["monthly_rent"] = ch["monthly_rent"]
56
+ elif kind == "member_joins": new["members"].append(ch["member"])
57
+ elif kind == "member_leaves": new["members"] = [p for p in new["members"] if p["person"] != ch["person"]]
58
+ return new
59
+
60
+ def day_of(date): return int(date.split("-")[2])
61
+
62
+ def month_plan(case, changes, n_days, first_day=1):
63
+ """Entitlement on each day from first_day to the end of the month, grouped into periods: [(entitlement, days, household)]."""
64
+ changes = sorted(changes, key=lambda c: c["date"])
65
+ periods = []
66
+ for day in range(first_day, n_days + 1):
67
+ cur = case
68
+ for ch in changes:
69
+ if day_of(ch["date"]) <= day: cur = changed(cur, ch)
70
+ starts_new = day == first_day or any(day_of(ch["date"]) == day for ch in changes)
71
+ if starts_new: periods.append([assess(cur)["benefit"], 1, cur])
72
+ else: periods[-1][1] += 1
73
+ return periods
74
+
75
+ def entitlement():
76
+ ans = {"households": {}, "no_entitlement": []}
77
+ total = F(0)
78
+ for case in load("cases.json")["cases"]:
79
+ a = assess(case)
80
+ ans["households"][case["case_id"]] = dict((k, money(a[k])) for k in ("norm", "countable_income", "housing_allowance", "asset_excess", "benefit"))
81
+ if a["benefit"] == 0: ans["no_entitlement"].append(case["case_id"])
82
+ total += a["benefit"]
83
+ ans["total_payable"] = money(total)
84
+ return ans
85
+
86
+ def change():
87
+ data = load("cases.json")
88
+ n_days = data["days_in_month"]
89
+ ans = {"cases": {}, "nothing_payable": []}
90
+ total = F(0)
91
+ for case in data["cases"]:
92
+ first = day_of(case["claim_date"]) if case.get("claim_date") else 1
93
+ periods = month_plan(case, case["changes"], n_days, first)
94
+ pay = sum(e * d for e, d, _ in periods) / n_days
95
+ ans["cases"][case["case_id"]] = {"days": [d for _, d, _ in periods], "rates": [money(e) for e, _, _ in periods], "payable": money(pay)}
96
+ if pay == 0: ans["nothing_payable"].append(case["case_id"])
97
+ total += pay
98
+ ans["total_payable"] = money(total)
99
+ return ans
100
+
101
+ def overpayment():
102
+ ans = {"cases": {}, "written_off": []}
103
+ grand = F(0)
104
+ for case in load("cases.json")["cases"]:
105
+ ch = case["discovered_change"]
106
+ after = changed(case, ch)
107
+ out = {"correct": {}}
108
+ total = F(0)
109
+ for m in case["benefit_paid"]:
110
+ if m["month"] < ch["date"][:7]: right = assess(case)["benefit"]
111
+ elif m["month"] > ch["date"][:7]: right = assess(after)["benefit"]
112
+ else: right = sum(e * d for e, d, _ in month_plan(case, [ch], m["days_in_month"])) / m["days_in_month"]
113
+ out["correct"][m["month"]] = money(right)
114
+ total += F(str(m["paid"])) - right
115
+ out["total_overpayment"] = money(total)
116
+ if total < 300:
117
+ out["deductions"] = 0
118
+ if total > 0: ans["written_off"].append(case["case_id"])
119
+ else:
120
+ step = F(ADULT_COUPLE if assess(after)["adults"] == 2 else ADULT_ONE) / 10
121
+ count = 0; owed = total
122
+ while owed > step:
123
+ owed -= step; count += 1
124
+ out["deductions"] = count + 1
125
+ out["last_deduction"] = money(owed)
126
+ grand += total
127
+ ans["cases"][case["case_id"]] = out
128
+ ans["total_to_recover"] = money(grand)
129
+ return ans
130
+
131
+ def review():
132
+ ans = {"wrong_decisions": [], "corrected": {}}
133
+ under = over = F(0)
134
+ for case in load("decisions.json")["decisions"]:
135
+ a = assess(case)
136
+ dec = case["decision"]
137
+ if all(abs(float(a[k]) - dec[k]) <= 0.01 for k in dec): continue
138
+ cid = case["case_id"]
139
+ ans["wrong_decisions"].append(cid)
140
+ fix = dict((k, money(a[k])) for k in dec)
141
+ diff = a["benefit"] - F(str(dec["benefit"]))
142
+ fix["difference"] = money(diff)
143
+ if diff > 0: under += diff
144
+ else: over -= diff
145
+ ans["corrected"][cid] = fix
146
+ ans["total_underpaid"], ans["total_overpaid"] = money(under), money(over)
147
+ return ans
148
+
149
+ if os.path.exists("decisions.json"): answer = review()
150
+ else:
151
+ first = load("cases.json")["cases"][0]
152
+ if "discovered_change" in first: answer = overpayment()
153
+ elif "changes" in first: answer = change()
154
+ else: answer = entitlement()
155
+ with open("answer.json", "w") as f: json.dump(answer, f, indent=1)
tasks/means-test/means-test-change-d1-e0000/solution/solve.sh ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+ cd /app
4
+ python3 /solution/oracle.py
tasks/means-test/means-test-change-d1-e0000/task.toml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version = "1.0"
2
+
3
+ [metadata]
4
+ author_name = "Renaissance Labs"
5
+ author_email = "unknown"
6
+ difficulty = "easy"
7
+ category = "means-test"
8
+ tags = ["means-test", "change", "isced-0923", "eval"]
9
+ isced_f = "0923"
10
+ family = "change"
11
+ split = "eval"
12
+ seed = 10000
13
+
14
+ [verifier]
15
+ timeout_sec = 120.0
16
+
17
+ [agent]
18
+ timeout_sec = 900.0
19
+
20
+ [environment]
21
+ build_timeout_sec = 600.0
22
+ cpus = 1
23
+ memory_mb = 1024
24
+ storage_mb = 2048
25
+ allow_internet = false
tasks/means-test/means-test-change-d1-e0000/tests/checks.json ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "path": "cases.H4260.days",
4
+ "type": "list",
5
+ "value": [
6
+ 28,
7
+ 3
8
+ ],
9
+ "item": "int",
10
+ "weight": 1.0
11
+ },
12
+ {
13
+ "path": "cases.H4260.rates",
14
+ "type": "list",
15
+ "value": [
16
+ 11875.0,
17
+ 9925.0
18
+ ],
19
+ "item": "number",
20
+ "weight": 1.0,
21
+ "abs_tol": 0.01
22
+ },
23
+ {
24
+ "path": "cases.H4260.payable",
25
+ "type": "number",
26
+ "value": 11686.29,
27
+ "abs_tol": 0.01,
28
+ "weight": 2
29
+ },
30
+ {
31
+ "path": "cases.H4578.days",
32
+ "type": "list",
33
+ "value": [
34
+ 16,
35
+ 15
36
+ ],
37
+ "item": "int",
38
+ "weight": 1.0
39
+ },
40
+ {
41
+ "path": "cases.H4578.rates",
42
+ "type": "list",
43
+ "value": [
44
+ 9275.0,
45
+ 7175.0
46
+ ],
47
+ "item": "number",
48
+ "weight": 1.0,
49
+ "abs_tol": 0.01
50
+ },
51
+ {
52
+ "path": "cases.H4578.payable",
53
+ "type": "number",
54
+ "value": 8258.87,
55
+ "abs_tol": 0.01,
56
+ "weight": 2
57
+ },
58
+ {
59
+ "path": "cases.H5201.days",
60
+ "type": "list",
61
+ "value": [
62
+ 4,
63
+ 27
64
+ ],
65
+ "item": "int",
66
+ "weight": 1.0
67
+ },
68
+ {
69
+ "path": "cases.H5201.rates",
70
+ "type": "list",
71
+ "value": [
72
+ 14700.0,
73
+ 12150.0
74
+ ],
75
+ "item": "number",
76
+ "weight": 1.0,
77
+ "abs_tol": 0.01
78
+ },
79
+ {
80
+ "path": "cases.H5201.payable",
81
+ "type": "number",
82
+ "value": 12479.03,
83
+ "abs_tol": 0.01,
84
+ "weight": 2
85
+ },
86
+ {
87
+ "path": "nothing_payable",
88
+ "type": "set",
89
+ "value": [],
90
+ "item": "str",
91
+ "weight": 2
92
+ },
93
+ {
94
+ "path": "total_payable",
95
+ "type": "number",
96
+ "value": 32424.19,
97
+ "abs_tol": 0.01,
98
+ "weight": 1.0
99
+ }
100
+ ]
tasks/means-test/means-test-change-d1-e0000/tests/test.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
tasks/means-test/means-test-change-d1-e0000/tests/verify.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Verifier for Renaissance Labs practice environments. Standard library only.
3
+
4
+ Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
5
+ The reward is the weighted share of checks that pass. A missing, unreadable or non-object
6
+ answer scores 0. Each check addresses one value in the answer by a dotted path.
7
+
8
+ Check types
9
+ int exact integer (a float with integral value is accepted; booleans are not)
10
+ number within abs_tol of value (default 1e-9); booleans and strings are rejected
11
+ str equal after trimming and case-folding
12
+ bool exact boolean
13
+ list ordered list; items compared as int/number/str according to "item" (default str)
14
+ set unordered collection of distinct strings (or ints)
15
+ custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
16
+ """
17
+ import argparse, json, math, os, sys
18
+
19
+ MISSING = object()
20
+
21
+ def lookup(obj, path):
22
+ cur = obj
23
+ for part in path.split("."):
24
+ if isinstance(cur, dict):
25
+ if part not in cur: return MISSING
26
+ cur = cur[part]
27
+ elif isinstance(cur, list):
28
+ try: cur = cur[int(part)]
29
+ except (ValueError, IndexError): return MISSING
30
+ else:
31
+ return MISSING
32
+ return cur
33
+
34
+ def is_num(x):
35
+ return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
36
+
37
+ def eq_int(got, want):
38
+ return is_num(got) and float(got) == float(int(got)) and int(got) == want
39
+
40
+ def eq_num(got, want, tol):
41
+ return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
42
+
43
+ def eq_str(got, want):
44
+ return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
45
+
46
+ def eq_item(got, want, kind, tol):
47
+ if kind == "int": return eq_int(got, want)
48
+ if kind == "number": return eq_num(got, want, tol)
49
+ return eq_str(got, want)
50
+
51
+ def run_check(answer, chk, validators):
52
+ t = chk["type"]
53
+ if t == "custom":
54
+ fn = getattr(validators, chk["name"], None) if validators else None
55
+ if fn is None: return 0.0
56
+ try: r = fn(answer, chk.get("args", {}))
57
+ except Exception: return 0.0
58
+ if r is True: return 1.0
59
+ if r is False or r is None: return 0.0
60
+ return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
61
+ got = lookup(answer, chk["path"])
62
+ if got is MISSING: return 0.0
63
+ want, tol = chk["value"], chk.get("abs_tol", 1e-9)
64
+ if t == "int": ok = eq_int(got, want)
65
+ elif t == "number": ok = eq_num(got, want, tol)
66
+ elif t == "str": ok = eq_str(got, want)
67
+ elif t == "bool": ok = isinstance(got, bool) and got is want
68
+ elif t == "list":
69
+ ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
70
+ elif t == "set":
71
+ kind = chk.get("item", "str")
72
+ if not isinstance(got, list): ok = False
73
+ else:
74
+ norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
75
+ g = [norm(x) for x in got]; w = [norm(x) for x in want]
76
+ ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
77
+ else: ok = False
78
+ return 1.0 if ok else 0.0
79
+
80
+ def grade(answer, checks, validators=None):
81
+ """Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
82
+ if not isinstance(answer, dict):
83
+ return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
84
+ total = sum(c.get("weight", 1.0) for c in checks)
85
+ got, details = 0.0, []
86
+ for c in checks:
87
+ s = run_check(answer, c, validators)
88
+ got += s * c.get("weight", 1.0)
89
+ details.append({"check": c.get("path", c.get("name")), "score": s})
90
+ return (round(got / total, 6) if total else 0.0), details
91
+
92
+ def main():
93
+ ap = argparse.ArgumentParser()
94
+ ap.add_argument("--answer", default="/app/answer.json")
95
+ ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
96
+ ap.add_argument("--out", default="/logs/verifier")
97
+ a = ap.parse_args()
98
+ checks = json.load(open(a.checks))
99
+ try:
100
+ with open(a.answer) as f: answer = json.load(f)
101
+ except Exception:
102
+ answer = None
103
+ validators = None
104
+ here = os.path.dirname(os.path.abspath(__file__))
105
+ if os.path.exists(os.path.join(here, "validators.py")):
106
+ sys.path.insert(0, here)
107
+ import validators # noqa
108
+ reward, details = grade(answer, checks, validators)
109
+ os.makedirs(a.out, exist_ok=True)
110
+ with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
111
+ with open(os.path.join(a.out, "reward.json"), "w") as f:
112
+ json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
113
+ print("reward", reward)
114
+
115
+ if __name__ == "__main__":
116
+ main()
tasks/means-test/means-test-change-d1-e0012/environment/Dockerfile ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ FROM python:3.12-slim
2
+ WORKDIR /app
3
+ COPY workdir/ /app/
tasks/means-test/means-test-change-d1-e0012/environment/workdir/cases.json ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "municipality": "Eskermark",
3
+ "month": "2026-05",
4
+ "days_in_month": 31,
5
+ "cases": [
6
+ {
7
+ "case_id": "H8656",
8
+ "caseworker": "ES",
9
+ "members": [
10
+ {
11
+ "person": "P1",
12
+ "role": "applicant",
13
+ "age": 37,
14
+ "income": [
15
+ {
16
+ "type": "sickness_benefit",
17
+ "amount": 4550
18
+ }
19
+ ]
20
+ },
21
+ {
22
+ "person": "P2",
23
+ "role": "child",
24
+ "age": 3,
25
+ "income": [
26
+ {
27
+ "type": "child_benefit",
28
+ "amount": 600
29
+ }
30
+ ]
31
+ },
32
+ {
33
+ "person": "P3",
34
+ "role": "child",
35
+ "age": 3,
36
+ "income": [
37
+ {
38
+ "type": "child_benefit",
39
+ "amount": 600
40
+ }
41
+ ]
42
+ },
43
+ {
44
+ "person": "P4",
45
+ "role": "child",
46
+ "age": 12,
47
+ "income": [
48
+ {
49
+ "type": "child_benefit",
50
+ "amount": 650
51
+ }
52
+ ]
53
+ }
54
+ ],
55
+ "monthly_rent": 6350,
56
+ "liquid_assets": 400,
57
+ "changes": [
58
+ {
59
+ "date": "2026-05-21",
60
+ "type": "income_change",
61
+ "person": "P1",
62
+ "income": [
63
+ {
64
+ "type": "earnings",
65
+ "amount": 8750
66
+ }
67
+ ]
68
+ }
69
+ ]
70
+ },
71
+ {
72
+ "case_id": "H2359",
73
+ "caseworker": "TK",
74
+ "members": [
75
+ {
76
+ "person": "P1",
77
+ "role": "applicant",
78
+ "age": 54,
79
+ "income": [
80
+ {
81
+ "type": "earnings",
82
+ "amount": 6350
83
+ }
84
+ ]
85
+ },
86
+ {
87
+ "person": "P2",
88
+ "role": "child",
89
+ "age": 11,
90
+ "income": [
91
+ {
92
+ "type": "maintenance",
93
+ "amount": 1500
94
+ },
95
+ {
96
+ "type": "child_benefit",
97
+ "amount": 650
98
+ }
99
+ ]
100
+ },
101
+ {
102
+ "person": "P3",
103
+ "role": "child",
104
+ "age": 5,
105
+ "income": [
106
+ {
107
+ "type": "child_benefit",
108
+ "amount": 650
109
+ }
110
+ ]
111
+ }
112
+ ],
113
+ "monthly_rent": 7200,
114
+ "liquid_assets": 6000,
115
+ "changes": [
116
+ {
117
+ "date": "2026-05-11",
118
+ "type": "income_change",
119
+ "person": "P1",
120
+ "income": [
121
+ {
122
+ "type": "unemployment_benefit",
123
+ "amount": 2700
124
+ }
125
+ ]
126
+ }
127
+ ]
128
+ },
129
+ {
130
+ "case_id": "H3461",
131
+ "caseworker": "LB",
132
+ "members": [
133
+ {
134
+ "person": "P1",
135
+ "role": "applicant",
136
+ "age": 50,
137
+ "income": [
138
+ {
139
+ "type": "earnings",
140
+ "amount": 2700
141
+ }
142
+ ]
143
+ },
144
+ {
145
+ "person": "P2",
146
+ "role": "child",
147
+ "age": 4,
148
+ "income": [
149
+ {
150
+ "type": "child_benefit",
151
+ "amount": 600
152
+ }
153
+ ]
154
+ }
155
+ ],
156
+ "monthly_rent": 6300,
157
+ "liquid_assets": 2300,
158
+ "changes": [
159
+ {
160
+ "date": "2026-05-10",
161
+ "type": "income_change",
162
+ "person": "P1",
163
+ "income": [
164
+ {
165
+ "type": "earnings",
166
+ "amount": 7800
167
+ }
168
+ ]
169
+ }
170
+ ]
171
+ }
172
+ ]
173
+ }
tasks/means-test/means-test-change-d1-e0012/environment/workdir/regulation.md ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Eskermark Local Support Ordinance (fictional)
2
+
3
+ The Municipality of Eskermark, this ordinance and every amount in it are invented for practice. They do not describe any real benefit scheme. All amounts are per calendar month and in florins (fl). Do not round intermediate results.
4
+
5
+ ## 1. The household
6
+
7
+ The household's **members** are the applicant, the applicant's partner if they live together, and their children under 18 who live with them. In a case file these have the role `applicant`, `partner` or `child`. The applicant and the partner are the adult members.
8
+
9
+ Anyone else who lives in the home has the role `other_resident` (for example a grown-up child or a lodger). An other resident is not a member: their income is ignored and they add nothing to the norm, but they count as a resident when the rent is shared out (section 3).
10
+
11
+ ## 2. The norm
12
+
13
+ The norm is the adult amount plus the child amounts plus the common costs.
14
+
15
+ | Adult amount | fl |
16
+ |---|---|
17
+ | One adult member | 4100 |
18
+ | Two adult members (a couple) | 6900 |
19
+
20
+ | Child amount, for each child member | fl |
21
+ |---|---|
22
+ | Age 0 to 5 | 1450 |
23
+ | Age 6 to 12 | 1800 |
24
+ | Age 13 to 17 | 2250 |
25
+
26
+ | Common costs, by number of members | fl |
27
+ |---|---|
28
+ | 1 | 900 |
29
+ | 2 | 1100 |
30
+ | 3 | 1350 |
31
+ | 4 | 1550 |
32
+ | 5 | 1750 |
33
+ | 6 or more | 1900 |
34
+
35
+ Sanction: if the case file records `sanction_level` 1, the adult amount is reduced by 15%. At `sanction_level` 2 it is reduced by 30%. The child amounts and the common costs are never reduced. Level 0, or no entry, means no sanction.
36
+
37
+ ## 3. Housing allowance
38
+
39
+ The household's rent share is the monthly rent times the number of members, divided by the number of residents (members plus other residents). With no other residents the rent share is the whole rent.
40
+
41
+ The housing allowance is the rent share, but not more than the cap for the number of members:
42
+
43
+ | Number of members | Cap, fl |
44
+ |---|---|
45
+ | 1 | 5200 |
46
+ | 2 | 6400 |
47
+ | 3 | 7300 |
48
+ | 4 | 8100 |
49
+ | 5 or more | 8800 |
50
+
51
+ ## 4. Countable income
52
+
53
+ Each person's income is listed by type.
54
+
55
+ - `earnings` of an adult member: add up that adult's earnings, then take off the work disregard, which is 25% of that adult's earnings but not more than 1200 fl per adult. What is left counts.
56
+ - Counted in full, whichever member receives it: `child_benefit`, `maintenance`, `pension`, `unemployment_benefit`, `sickness_benefit`.
57
+ - Not counted at all: `disability_allowance`, `funeral_grant`, `school_meal_voucher`, and any `earnings` of a child member.
58
+
59
+ Countable income is the sum over all members.
60
+
61
+ ## 5. Assets
62
+
63
+ The asset exemption is 8000 fl for a household with one adult member and 12000 fl for a couple, plus 1500 fl for each child member. The asset excess is the household's liquid assets minus the exemption, or 0 if that is negative. The asset excess is assessed afresh for every month and every period, with the exemption of the household as it then is.
64
+
65
+ ## 6. Monthly entitlement
66
+
67
+ entitlement = norm + housing allowance - countable income - asset excess
68
+
69
+ If this is negative, the entitlement is 0 and the household has no entitlement. For a month in which nothing changes, the benefit payable is the entitlement.
70
+
71
+ ## 7. Changes during a month
72
+
73
+ A change takes effect on its date: that day and the days after it are assessed on the new circumstances. Split the month into periods at each change date. For each period, work out the monthly entitlement (sections 2 to 6) as if the circumstances of that period had lasted the whole month. Then
74
+
75
+ benefit payable for the month = sum over the periods of (monthly entitlement of the period * days in the period / days in the month)
76
+
77
+ If a case file gives a `claim_date`, no benefit is payable for the days before it: the first period starts on the claim date.
78
+
79
+ ## 8. Overpayments and recovery
80
+
81
+ When benefit has been paid on circumstances that later prove to have been different, then for each month under review:
82
+
83
+ correct benefit = the benefit payable for that month on the true circumstances (using section 7 if the change came during the month)
84
+ overpayment = amount paid - correct benefit
85
+
86
+ The total overpayment is the sum over the months under review.
87
+
88
+ - A total overpayment under 300 fl is written off: nothing is recovered.
89
+ - Otherwise it is recovered by a monthly deduction of 10% of the unsanctioned adult amount of the household as it is after the change (410 fl for one adult member, 690 fl for a couple) until the total is repaid. The number of deductions is the total overpayment divided by the monthly deduction, rounded up. Every deduction is the full monthly deduction except the last, which is whatever is still owed.
tasks/means-test/means-test-change-d1-e0012/instruction.md ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Means test: a change during the month
2
+
3
+ `cases.json` holds 3 household case files from the Municipality of Eskermark for 2026-05 (31 days). Each file shows the household as it was on the first day of the month and a list of `changes`, each with the date it takes effect. `regulation.md` is the ordinance to apply (it is fictional; use its rules and amounts exactly). Section 7 says how to handle a change during the month.
4
+
5
+ The kinds of change are:
6
+
7
+ - `income_change`: the named person's whole income list is replaced by the list given.
8
+
9
+ Write `answer.json` in this folder, a JSON object with:
10
+
11
+ - `cases`: an object keyed by case id. Each value has
12
+ - `days`: a list of integers, the number of days in each period, in date order.
13
+ - `rates`: a list of numbers, the monthly entitlement (section 6) of each period, in the same order, fl with 2 decimals.
14
+ - `payable`: the benefit payable for the month, fl with 2 decimals.
15
+ - `nothing_payable`: list of the case ids for which nothing is payable for the month (any order; an empty list if none).
16
+ - `total_payable`: the sum of `payable` over all the cases, fl with 2 decimals.
17
+
18
+ Numbers are accepted within one unit of the last decimal place asked for.
tasks/means-test/means-test-change-d1-e0012/solution/oracle.py ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Reference solution for Means Test. Works only from the files in the current directory.
3
+ The rates below are read off regulation.md (Eskermark Local Support Ordinance, fictional)."""
4
+ import json, os
5
+ from fractions import Fraction as F
6
+
7
+ ADULT_ONE, ADULT_COUPLE = 4100, 6900
8
+ COMMON_COSTS = [900, 1100, 1350, 1550, 1750, 1900] # 1, 2, 3, 4, 5, 6 or more members
9
+ RENT_CAPS = [5200, 6400, 7300, 8100, 8800] # 1, 2, 3, 4, 5 or more members
10
+ FULLY_COUNTED = set(["child_benefit", "maintenance", "pension", "unemployment_benefit", "sickness_benefit"])
11
+
12
+ def load(name):
13
+ with open(name) as f: return json.load(f)
14
+
15
+ def money(x): return round(float(x), 2)
16
+
17
+ def assess(case):
18
+ people = case["members"]
19
+ grown = [p for p in people if p["role"] == "applicant" or p["role"] == "partner"]
20
+ young = [p for p in people if p["role"] == "child"]
21
+ size = len(grown) + len(young)
22
+ # section 2
23
+ adult = F(ADULT_COUPLE if len(grown) == 2 else ADULT_ONE)
24
+ level = case.get("sanction_level") or 0
25
+ if level == 1: adult -= adult * F(15, 100)
26
+ elif level == 2: adult -= adult * F(30, 100)
27
+ norm = adult + COMMON_COSTS[min(size, 6) - 1]
28
+ for p in young:
29
+ norm += 1450 if p["age"] < 6 else 1800 if p["age"] < 13 else 2250
30
+ # section 3
31
+ share = F(case["monthly_rent"]) * size / len(people)
32
+ housing = min(share, F(RENT_CAPS[min(size, 5) - 1]))
33
+ # section 4
34
+ income = F(0)
35
+ for p in grown + young:
36
+ wages = F(0)
37
+ for line in p.get("income", []):
38
+ if line["type"] == "earnings": wages += F(str(line["amount"]))
39
+ elif line["type"] in FULLY_COUNTED: income += F(str(line["amount"]))
40
+ if p["role"] != "child":
41
+ income += wages - min(wages / 4, F(1200))
42
+ # section 5
43
+ allowed = (12000 if len(grown) == 2 else 8000) + 1500 * len(young)
44
+ excess = max(F(0), F(case["liquid_assets"]) - allowed)
45
+ # section 6
46
+ ent = max(F(0), norm + housing - income - excess)
47
+ return {"norm": norm, "countable_income": income, "housing_allowance": housing, "asset_excess": excess, "benefit": ent, "adults": len(grown)}
48
+
49
+ def changed(case, ch):
50
+ new = json.loads(json.dumps(case))
51
+ kind = ch["type"]
52
+ if kind == "income_change":
53
+ for p in new["members"]:
54
+ if p["person"] == ch["person"]: p["income"] = ch["income"]
55
+ elif kind == "rent_change": new["monthly_rent"] = ch["monthly_rent"]
56
+ elif kind == "member_joins": new["members"].append(ch["member"])
57
+ elif kind == "member_leaves": new["members"] = [p for p in new["members"] if p["person"] != ch["person"]]
58
+ return new
59
+
60
+ def day_of(date): return int(date.split("-")[2])
61
+
62
+ def month_plan(case, changes, n_days, first_day=1):
63
+ """Entitlement on each day from first_day to the end of the month, grouped into periods: [(entitlement, days, household)]."""
64
+ changes = sorted(changes, key=lambda c: c["date"])
65
+ periods = []
66
+ for day in range(first_day, n_days + 1):
67
+ cur = case
68
+ for ch in changes:
69
+ if day_of(ch["date"]) <= day: cur = changed(cur, ch)
70
+ starts_new = day == first_day or any(day_of(ch["date"]) == day for ch in changes)
71
+ if starts_new: periods.append([assess(cur)["benefit"], 1, cur])
72
+ else: periods[-1][1] += 1
73
+ return periods
74
+
75
+ def entitlement():
76
+ ans = {"households": {}, "no_entitlement": []}
77
+ total = F(0)
78
+ for case in load("cases.json")["cases"]:
79
+ a = assess(case)
80
+ ans["households"][case["case_id"]] = dict((k, money(a[k])) for k in ("norm", "countable_income", "housing_allowance", "asset_excess", "benefit"))
81
+ if a["benefit"] == 0: ans["no_entitlement"].append(case["case_id"])
82
+ total += a["benefit"]
83
+ ans["total_payable"] = money(total)
84
+ return ans
85
+
86
+ def change():
87
+ data = load("cases.json")
88
+ n_days = data["days_in_month"]
89
+ ans = {"cases": {}, "nothing_payable": []}
90
+ total = F(0)
91
+ for case in data["cases"]:
92
+ first = day_of(case["claim_date"]) if case.get("claim_date") else 1
93
+ periods = month_plan(case, case["changes"], n_days, first)
94
+ pay = sum(e * d for e, d, _ in periods) / n_days
95
+ ans["cases"][case["case_id"]] = {"days": [d for _, d, _ in periods], "rates": [money(e) for e, _, _ in periods], "payable": money(pay)}
96
+ if pay == 0: ans["nothing_payable"].append(case["case_id"])
97
+ total += pay
98
+ ans["total_payable"] = money(total)
99
+ return ans
100
+
101
+ def overpayment():
102
+ ans = {"cases": {}, "written_off": []}
103
+ grand = F(0)
104
+ for case in load("cases.json")["cases"]:
105
+ ch = case["discovered_change"]
106
+ after = changed(case, ch)
107
+ out = {"correct": {}}
108
+ total = F(0)
109
+ for m in case["benefit_paid"]:
110
+ if m["month"] < ch["date"][:7]: right = assess(case)["benefit"]
111
+ elif m["month"] > ch["date"][:7]: right = assess(after)["benefit"]
112
+ else: right = sum(e * d for e, d, _ in month_plan(case, [ch], m["days_in_month"])) / m["days_in_month"]
113
+ out["correct"][m["month"]] = money(right)
114
+ total += F(str(m["paid"])) - right
115
+ out["total_overpayment"] = money(total)
116
+ if total < 300:
117
+ out["deductions"] = 0
118
+ if total > 0: ans["written_off"].append(case["case_id"])
119
+ else:
120
+ step = F(ADULT_COUPLE if assess(after)["adults"] == 2 else ADULT_ONE) / 10
121
+ count = 0; owed = total
122
+ while owed > step:
123
+ owed -= step; count += 1
124
+ out["deductions"] = count + 1
125
+ out["last_deduction"] = money(owed)
126
+ grand += total
127
+ ans["cases"][case["case_id"]] = out
128
+ ans["total_to_recover"] = money(grand)
129
+ return ans
130
+
131
+ def review():
132
+ ans = {"wrong_decisions": [], "corrected": {}}
133
+ under = over = F(0)
134
+ for case in load("decisions.json")["decisions"]:
135
+ a = assess(case)
136
+ dec = case["decision"]
137
+ if all(abs(float(a[k]) - dec[k]) <= 0.01 for k in dec): continue
138
+ cid = case["case_id"]
139
+ ans["wrong_decisions"].append(cid)
140
+ fix = dict((k, money(a[k])) for k in dec)
141
+ diff = a["benefit"] - F(str(dec["benefit"]))
142
+ fix["difference"] = money(diff)
143
+ if diff > 0: under += diff
144
+ else: over -= diff
145
+ ans["corrected"][cid] = fix
146
+ ans["total_underpaid"], ans["total_overpaid"] = money(under), money(over)
147
+ return ans
148
+
149
+ if os.path.exists("decisions.json"): answer = review()
150
+ else:
151
+ first = load("cases.json")["cases"][0]
152
+ if "discovered_change" in first: answer = overpayment()
153
+ elif "changes" in first: answer = change()
154
+ else: answer = entitlement()
155
+ with open("answer.json", "w") as f: json.dump(answer, f, indent=1)
tasks/means-test/means-test-change-d1-e0012/solution/solve.sh ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+ cd /app
4
+ python3 /solution/oracle.py
tasks/means-test/means-test-change-d1-e0012/task.toml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version = "1.0"
2
+
3
+ [metadata]
4
+ author_name = "Renaissance Labs"
5
+ author_email = "unknown"
6
+ difficulty = "easy"
7
+ category = "means-test"
8
+ tags = ["means-test", "change", "isced-0923", "eval"]
9
+ isced_f = "0923"
10
+ family = "change"
11
+ split = "eval"
12
+ seed = 10012
13
+
14
+ [verifier]
15
+ timeout_sec = 120.0
16
+
17
+ [agent]
18
+ timeout_sec = 900.0
19
+
20
+ [environment]
21
+ build_timeout_sec = 600.0
22
+ cpus = 1
23
+ memory_mb = 1024
24
+ storage_mb = 2048
25
+ allow_internet = false
tasks/means-test/means-test-change-d1-e0012/tests/checks.json ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "path": "cases.H2359.days",
4
+ "type": "list",
5
+ "value": [
6
+ 10,
7
+ 21
8
+ ],
9
+ "item": "int",
10
+ "weight": 1.0
11
+ },
12
+ {
13
+ "path": "cases.H2359.rates",
14
+ "type": "list",
15
+ "value": [
16
+ 7950.0,
17
+ 10400.0
18
+ ],
19
+ "item": "number",
20
+ "weight": 1.0,
21
+ "abs_tol": 0.01
22
+ },
23
+ {
24
+ "path": "cases.H2359.payable",
25
+ "type": "number",
26
+ "value": 9609.68,
27
+ "abs_tol": 0.01,
28
+ "weight": 2
29
+ },
30
+ {
31
+ "path": "cases.H3461.days",
32
+ "type": "list",
33
+ "value": [
34
+ 9,
35
+ 22
36
+ ],
37
+ "item": "int",
38
+ "weight": 1.0
39
+ },
40
+ {
41
+ "path": "cases.H3461.rates",
42
+ "type": "list",
43
+ "value": [
44
+ 10325.0,
45
+ 5750.0
46
+ ],
47
+ "item": "number",
48
+ "weight": 1.0,
49
+ "abs_tol": 0.01
50
+ },
51
+ {
52
+ "path": "cases.H3461.payable",
53
+ "type": "number",
54
+ "value": 7078.23,
55
+ "abs_tol": 0.01,
56
+ "weight": 2
57
+ },
58
+ {
59
+ "path": "cases.H8656.days",
60
+ "type": "list",
61
+ "value": [
62
+ 20,
63
+ 11
64
+ ],
65
+ "item": "int",
66
+ "weight": 1.0
67
+ },
68
+ {
69
+ "path": "cases.H8656.rates",
70
+ "type": "list",
71
+ "value": [
72
+ 10300.0,
73
+ 7300.0
74
+ ],
75
+ "item": "number",
76
+ "weight": 1.0,
77
+ "abs_tol": 0.01
78
+ },
79
+ {
80
+ "path": "cases.H8656.payable",
81
+ "type": "number",
82
+ "value": 9235.48,
83
+ "abs_tol": 0.01,
84
+ "weight": 2
85
+ },
86
+ {
87
+ "path": "nothing_payable",
88
+ "type": "set",
89
+ "value": [],
90
+ "item": "str",
91
+ "weight": 2
92
+ },
93
+ {
94
+ "path": "total_payable",
95
+ "type": "number",
96
+ "value": 25923.39,
97
+ "abs_tol": 0.01,
98
+ "weight": 1.0
99
+ }
100
+ ]
tasks/means-test/means-test-change-d1-e0012/tests/test.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
tasks/means-test/means-test-change-d1-e0012/tests/verify.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Verifier for Renaissance Labs practice environments. Standard library only.
3
+
4
+ Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
5
+ The reward is the weighted share of checks that pass. A missing, unreadable or non-object
6
+ answer scores 0. Each check addresses one value in the answer by a dotted path.
7
+
8
+ Check types
9
+ int exact integer (a float with integral value is accepted; booleans are not)
10
+ number within abs_tol of value (default 1e-9); booleans and strings are rejected
11
+ str equal after trimming and case-folding
12
+ bool exact boolean
13
+ list ordered list; items compared as int/number/str according to "item" (default str)
14
+ set unordered collection of distinct strings (or ints)
15
+ custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
16
+ """
17
+ import argparse, json, math, os, sys
18
+
19
+ MISSING = object()
20
+
21
+ def lookup(obj, path):
22
+ cur = obj
23
+ for part in path.split("."):
24
+ if isinstance(cur, dict):
25
+ if part not in cur: return MISSING
26
+ cur = cur[part]
27
+ elif isinstance(cur, list):
28
+ try: cur = cur[int(part)]
29
+ except (ValueError, IndexError): return MISSING
30
+ else:
31
+ return MISSING
32
+ return cur
33
+
34
+ def is_num(x):
35
+ return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
36
+
37
+ def eq_int(got, want):
38
+ return is_num(got) and float(got) == float(int(got)) and int(got) == want
39
+
40
+ def eq_num(got, want, tol):
41
+ return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
42
+
43
+ def eq_str(got, want):
44
+ return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
45
+
46
+ def eq_item(got, want, kind, tol):
47
+ if kind == "int": return eq_int(got, want)
48
+ if kind == "number": return eq_num(got, want, tol)
49
+ return eq_str(got, want)
50
+
51
+ def run_check(answer, chk, validators):
52
+ t = chk["type"]
53
+ if t == "custom":
54
+ fn = getattr(validators, chk["name"], None) if validators else None
55
+ if fn is None: return 0.0
56
+ try: r = fn(answer, chk.get("args", {}))
57
+ except Exception: return 0.0
58
+ if r is True: return 1.0
59
+ if r is False or r is None: return 0.0
60
+ return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
61
+ got = lookup(answer, chk["path"])
62
+ if got is MISSING: return 0.0
63
+ want, tol = chk["value"], chk.get("abs_tol", 1e-9)
64
+ if t == "int": ok = eq_int(got, want)
65
+ elif t == "number": ok = eq_num(got, want, tol)
66
+ elif t == "str": ok = eq_str(got, want)
67
+ elif t == "bool": ok = isinstance(got, bool) and got is want
68
+ elif t == "list":
69
+ ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
70
+ elif t == "set":
71
+ kind = chk.get("item", "str")
72
+ if not isinstance(got, list): ok = False
73
+ else:
74
+ norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
75
+ g = [norm(x) for x in got]; w = [norm(x) for x in want]
76
+ ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
77
+ else: ok = False
78
+ return 1.0 if ok else 0.0
79
+
80
+ def grade(answer, checks, validators=None):
81
+ """Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
82
+ if not isinstance(answer, dict):
83
+ return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
84
+ total = sum(c.get("weight", 1.0) for c in checks)
85
+ got, details = 0.0, []
86
+ for c in checks:
87
+ s = run_check(answer, c, validators)
88
+ got += s * c.get("weight", 1.0)
89
+ details.append({"check": c.get("path", c.get("name")), "score": s})
90
+ return (round(got / total, 6) if total else 0.0), details
91
+
92
+ def main():
93
+ ap = argparse.ArgumentParser()
94
+ ap.add_argument("--answer", default="/app/answer.json")
95
+ ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
96
+ ap.add_argument("--out", default="/logs/verifier")
97
+ a = ap.parse_args()
98
+ checks = json.load(open(a.checks))
99
+ try:
100
+ with open(a.answer) as f: answer = json.load(f)
101
+ except Exception:
102
+ answer = None
103
+ validators = None
104
+ here = os.path.dirname(os.path.abspath(__file__))
105
+ if os.path.exists(os.path.join(here, "validators.py")):
106
+ sys.path.insert(0, here)
107
+ import validators # noqa
108
+ reward, details = grade(answer, checks, validators)
109
+ os.makedirs(a.out, exist_ok=True)
110
+ with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
111
+ with open(os.path.join(a.out, "reward.json"), "w") as f:
112
+ json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
113
+ print("reward", reward)
114
+
115
+ if __name__ == "__main__":
116
+ main()
tasks/means-test/means-test-change-d1-t0000/environment/Dockerfile ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ FROM python:3.12-slim
2
+ WORKDIR /app
3
+ COPY workdir/ /app/
tasks/means-test/means-test-change-d1-t0000/environment/workdir/cases.json ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "municipality": "Eskermark",
3
+ "month": "2026-07",
4
+ "days_in_month": 31,
5
+ "cases": [
6
+ {
7
+ "case_id": "H7903",
8
+ "caseworker": "LB",
9
+ "members": [
10
+ {
11
+ "person": "P1",
12
+ "role": "applicant",
13
+ "age": 41,
14
+ "income": [
15
+ {
16
+ "type": "earnings",
17
+ "amount": 5750
18
+ }
19
+ ]
20
+ },
21
+ {
22
+ "person": "P2",
23
+ "role": "partner",
24
+ "age": 47,
25
+ "income": [
26
+ {
27
+ "type": "unemployment_benefit",
28
+ "amount": 4350
29
+ }
30
+ ]
31
+ }
32
+ ],
33
+ "monthly_rent": 7150,
34
+ "liquid_assets": 0,
35
+ "changes": [
36
+ {
37
+ "date": "2026-07-15",
38
+ "type": "income_change",
39
+ "person": "P1",
40
+ "income": [
41
+ {
42
+ "type": "earnings",
43
+ "amount": 7850
44
+ }
45
+ ]
46
+ }
47
+ ]
48
+ },
49
+ {
50
+ "case_id": "H8675",
51
+ "caseworker": "LB",
52
+ "members": [
53
+ {
54
+ "person": "P1",
55
+ "role": "applicant",
56
+ "age": 54,
57
+ "income": []
58
+ },
59
+ {
60
+ "person": "P2",
61
+ "role": "child",
62
+ "age": 12,
63
+ "income": [
64
+ {
65
+ "type": "child_benefit",
66
+ "amount": 650
67
+ }
68
+ ]
69
+ },
70
+ {
71
+ "person": "P3",
72
+ "role": "child",
73
+ "age": 4,
74
+ "income": [
75
+ {
76
+ "type": "child_benefit",
77
+ "amount": 700
78
+ }
79
+ ]
80
+ }
81
+ ],
82
+ "monthly_rent": 5850,
83
+ "liquid_assets": 1600,
84
+ "changes": [
85
+ {
86
+ "date": "2026-07-19",
87
+ "type": "income_change",
88
+ "person": "P1",
89
+ "income": [
90
+ {
91
+ "type": "earnings",
92
+ "amount": 2750
93
+ }
94
+ ]
95
+ }
96
+ ]
97
+ },
98
+ {
99
+ "case_id": "H9283",
100
+ "caseworker": "ES",
101
+ "members": [
102
+ {
103
+ "person": "P1",
104
+ "role": "applicant",
105
+ "age": 39,
106
+ "income": [
107
+ {
108
+ "type": "earnings",
109
+ "amount": 6350
110
+ }
111
+ ]
112
+ },
113
+ {
114
+ "person": "P2",
115
+ "role": "partner",
116
+ "age": 40,
117
+ "income": [
118
+ {
119
+ "type": "earnings",
120
+ "amount": 3400
121
+ }
122
+ ]
123
+ },
124
+ {
125
+ "person": "P3",
126
+ "role": "child",
127
+ "age": 12,
128
+ "income": [
129
+ {
130
+ "type": "child_benefit",
131
+ "amount": 650
132
+ }
133
+ ]
134
+ },
135
+ {
136
+ "person": "P4",
137
+ "role": "child",
138
+ "age": 16,
139
+ "income": [
140
+ {
141
+ "type": "child_benefit",
142
+ "amount": 700
143
+ }
144
+ ]
145
+ }
146
+ ],
147
+ "monthly_rent": 7750,
148
+ "liquid_assets": 2500,
149
+ "changes": [
150
+ {
151
+ "date": "2026-07-12",
152
+ "type": "income_change",
153
+ "person": "P1",
154
+ "income": [
155
+ {
156
+ "type": "earnings",
157
+ "amount": 8500
158
+ }
159
+ ]
160
+ }
161
+ ]
162
+ }
163
+ ]
164
+ }
tasks/means-test/means-test-change-d1-t0000/environment/workdir/regulation.md ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Eskermark Local Support Ordinance (fictional)
2
+
3
+ The Municipality of Eskermark, this ordinance and every amount in it are invented for practice. They do not describe any real benefit scheme. All amounts are per calendar month and in florins (fl). Do not round intermediate results.
4
+
5
+ ## 1. The household
6
+
7
+ The household's **members** are the applicant, the applicant's partner if they live together, and their children under 18 who live with them. In a case file these have the role `applicant`, `partner` or `child`. The applicant and the partner are the adult members.
8
+
9
+ Anyone else who lives in the home has the role `other_resident` (for example a grown-up child or a lodger). An other resident is not a member: their income is ignored and they add nothing to the norm, but they count as a resident when the rent is shared out (section 3).
10
+
11
+ ## 2. The norm
12
+
13
+ The norm is the adult amount plus the child amounts plus the common costs.
14
+
15
+ | Adult amount | fl |
16
+ |---|---|
17
+ | One adult member | 4100 |
18
+ | Two adult members (a couple) | 6900 |
19
+
20
+ | Child amount, for each child member | fl |
21
+ |---|---|
22
+ | Age 0 to 5 | 1450 |
23
+ | Age 6 to 12 | 1800 |
24
+ | Age 13 to 17 | 2250 |
25
+
26
+ | Common costs, by number of members | fl |
27
+ |---|---|
28
+ | 1 | 900 |
29
+ | 2 | 1100 |
30
+ | 3 | 1350 |
31
+ | 4 | 1550 |
32
+ | 5 | 1750 |
33
+ | 6 or more | 1900 |
34
+
35
+ Sanction: if the case file records `sanction_level` 1, the adult amount is reduced by 15%. At `sanction_level` 2 it is reduced by 30%. The child amounts and the common costs are never reduced. Level 0, or no entry, means no sanction.
36
+
37
+ ## 3. Housing allowance
38
+
39
+ The household's rent share is the monthly rent times the number of members, divided by the number of residents (members plus other residents). With no other residents the rent share is the whole rent.
40
+
41
+ The housing allowance is the rent share, but not more than the cap for the number of members:
42
+
43
+ | Number of members | Cap, fl |
44
+ |---|---|
45
+ | 1 | 5200 |
46
+ | 2 | 6400 |
47
+ | 3 | 7300 |
48
+ | 4 | 8100 |
49
+ | 5 or more | 8800 |
50
+
51
+ ## 4. Countable income
52
+
53
+ Each person's income is listed by type.
54
+
55
+ - `earnings` of an adult member: add up that adult's earnings, then take off the work disregard, which is 25% of that adult's earnings but not more than 1200 fl per adult. What is left counts.
56
+ - Counted in full, whichever member receives it: `child_benefit`, `maintenance`, `pension`, `unemployment_benefit`, `sickness_benefit`.
57
+ - Not counted at all: `disability_allowance`, `funeral_grant`, `school_meal_voucher`, and any `earnings` of a child member.
58
+
59
+ Countable income is the sum over all members.
60
+
61
+ ## 5. Assets
62
+
63
+ The asset exemption is 8000 fl for a household with one adult member and 12000 fl for a couple, plus 1500 fl for each child member. The asset excess is the household's liquid assets minus the exemption, or 0 if that is negative. The asset excess is assessed afresh for every month and every period, with the exemption of the household as it then is.
64
+
65
+ ## 6. Monthly entitlement
66
+
67
+ entitlement = norm + housing allowance - countable income - asset excess
68
+
69
+ If this is negative, the entitlement is 0 and the household has no entitlement. For a month in which nothing changes, the benefit payable is the entitlement.
70
+
71
+ ## 7. Changes during a month
72
+
73
+ A change takes effect on its date: that day and the days after it are assessed on the new circumstances. Split the month into periods at each change date. For each period, work out the monthly entitlement (sections 2 to 6) as if the circumstances of that period had lasted the whole month. Then
74
+
75
+ benefit payable for the month = sum over the periods of (monthly entitlement of the period * days in the period / days in the month)
76
+
77
+ If a case file gives a `claim_date`, no benefit is payable for the days before it: the first period starts on the claim date.
78
+
79
+ ## 8. Overpayments and recovery
80
+
81
+ When benefit has been paid on circumstances that later prove to have been different, then for each month under review:
82
+
83
+ correct benefit = the benefit payable for that month on the true circumstances (using section 7 if the change came during the month)
84
+ overpayment = amount paid - correct benefit
85
+
86
+ The total overpayment is the sum over the months under review.
87
+
88
+ - A total overpayment under 300 fl is written off: nothing is recovered.
89
+ - Otherwise it is recovered by a monthly deduction of 10% of the unsanctioned adult amount of the household as it is after the change (410 fl for one adult member, 690 fl for a couple) until the total is repaid. The number of deductions is the total overpayment divided by the monthly deduction, rounded up. Every deduction is the full monthly deduction except the last, which is whatever is still owed.
tasks/means-test/means-test-change-d1-t0000/instruction.md ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Means test: a change during the month
2
+
3
+ `cases.json` holds 3 household case files from the Municipality of Eskermark for 2026-07 (31 days). Each file shows the household as it was on the first day of the month and a list of `changes`, each with the date it takes effect. `regulation.md` is the ordinance to apply (it is fictional; use its rules and amounts exactly). Section 7 says how to handle a change during the month.
4
+
5
+ The kinds of change are:
6
+
7
+ - `income_change`: the named person's whole income list is replaced by the list given.
8
+
9
+ Write `answer.json` in this folder, a JSON object with:
10
+
11
+ - `cases`: an object keyed by case id. Each value has
12
+ - `days`: a list of integers, the number of days in each period, in date order.
13
+ - `rates`: a list of numbers, the monthly entitlement (section 6) of each period, in the same order, fl with 2 decimals.
14
+ - `payable`: the benefit payable for the month, fl with 2 decimals.
15
+ - `nothing_payable`: list of the case ids for which nothing is payable for the month (any order; an empty list if none).
16
+ - `total_payable`: the sum of `payable` over all the cases, fl with 2 decimals.
17
+
18
+ Numbers are accepted within one unit of the last decimal place asked for.
tasks/means-test/means-test-change-d1-t0000/solution/oracle.py ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Reference solution for Means Test. Works only from the files in the current directory.
3
+ The rates below are read off regulation.md (Eskermark Local Support Ordinance, fictional)."""
4
+ import json, os
5
+ from fractions import Fraction as F
6
+
7
+ ADULT_ONE, ADULT_COUPLE = 4100, 6900
8
+ COMMON_COSTS = [900, 1100, 1350, 1550, 1750, 1900] # 1, 2, 3, 4, 5, 6 or more members
9
+ RENT_CAPS = [5200, 6400, 7300, 8100, 8800] # 1, 2, 3, 4, 5 or more members
10
+ FULLY_COUNTED = set(["child_benefit", "maintenance", "pension", "unemployment_benefit", "sickness_benefit"])
11
+
12
+ def load(name):
13
+ with open(name) as f: return json.load(f)
14
+
15
+ def money(x): return round(float(x), 2)
16
+
17
+ def assess(case):
18
+ people = case["members"]
19
+ grown = [p for p in people if p["role"] == "applicant" or p["role"] == "partner"]
20
+ young = [p for p in people if p["role"] == "child"]
21
+ size = len(grown) + len(young)
22
+ # section 2
23
+ adult = F(ADULT_COUPLE if len(grown) == 2 else ADULT_ONE)
24
+ level = case.get("sanction_level") or 0
25
+ if level == 1: adult -= adult * F(15, 100)
26
+ elif level == 2: adult -= adult * F(30, 100)
27
+ norm = adult + COMMON_COSTS[min(size, 6) - 1]
28
+ for p in young:
29
+ norm += 1450 if p["age"] < 6 else 1800 if p["age"] < 13 else 2250
30
+ # section 3
31
+ share = F(case["monthly_rent"]) * size / len(people)
32
+ housing = min(share, F(RENT_CAPS[min(size, 5) - 1]))
33
+ # section 4
34
+ income = F(0)
35
+ for p in grown + young:
36
+ wages = F(0)
37
+ for line in p.get("income", []):
38
+ if line["type"] == "earnings": wages += F(str(line["amount"]))
39
+ elif line["type"] in FULLY_COUNTED: income += F(str(line["amount"]))
40
+ if p["role"] != "child":
41
+ income += wages - min(wages / 4, F(1200))
42
+ # section 5
43
+ allowed = (12000 if len(grown) == 2 else 8000) + 1500 * len(young)
44
+ excess = max(F(0), F(case["liquid_assets"]) - allowed)
45
+ # section 6
46
+ ent = max(F(0), norm + housing - income - excess)
47
+ return {"norm": norm, "countable_income": income, "housing_allowance": housing, "asset_excess": excess, "benefit": ent, "adults": len(grown)}
48
+
49
+ def changed(case, ch):
50
+ new = json.loads(json.dumps(case))
51
+ kind = ch["type"]
52
+ if kind == "income_change":
53
+ for p in new["members"]:
54
+ if p["person"] == ch["person"]: p["income"] = ch["income"]
55
+ elif kind == "rent_change": new["monthly_rent"] = ch["monthly_rent"]
56
+ elif kind == "member_joins": new["members"].append(ch["member"])
57
+ elif kind == "member_leaves": new["members"] = [p for p in new["members"] if p["person"] != ch["person"]]
58
+ return new
59
+
60
+ def day_of(date): return int(date.split("-")[2])
61
+
62
+ def month_plan(case, changes, n_days, first_day=1):
63
+ """Entitlement on each day from first_day to the end of the month, grouped into periods: [(entitlement, days, household)]."""
64
+ changes = sorted(changes, key=lambda c: c["date"])
65
+ periods = []
66
+ for day in range(first_day, n_days + 1):
67
+ cur = case
68
+ for ch in changes:
69
+ if day_of(ch["date"]) <= day: cur = changed(cur, ch)
70
+ starts_new = day == first_day or any(day_of(ch["date"]) == day for ch in changes)
71
+ if starts_new: periods.append([assess(cur)["benefit"], 1, cur])
72
+ else: periods[-1][1] += 1
73
+ return periods
74
+
75
+ def entitlement():
76
+ ans = {"households": {}, "no_entitlement": []}
77
+ total = F(0)
78
+ for case in load("cases.json")["cases"]:
79
+ a = assess(case)
80
+ ans["households"][case["case_id"]] = dict((k, money(a[k])) for k in ("norm", "countable_income", "housing_allowance", "asset_excess", "benefit"))
81
+ if a["benefit"] == 0: ans["no_entitlement"].append(case["case_id"])
82
+ total += a["benefit"]
83
+ ans["total_payable"] = money(total)
84
+ return ans
85
+
86
+ def change():
87
+ data = load("cases.json")
88
+ n_days = data["days_in_month"]
89
+ ans = {"cases": {}, "nothing_payable": []}
90
+ total = F(0)
91
+ for case in data["cases"]:
92
+ first = day_of(case["claim_date"]) if case.get("claim_date") else 1
93
+ periods = month_plan(case, case["changes"], n_days, first)
94
+ pay = sum(e * d for e, d, _ in periods) / n_days
95
+ ans["cases"][case["case_id"]] = {"days": [d for _, d, _ in periods], "rates": [money(e) for e, _, _ in periods], "payable": money(pay)}
96
+ if pay == 0: ans["nothing_payable"].append(case["case_id"])
97
+ total += pay
98
+ ans["total_payable"] = money(total)
99
+ return ans
100
+
101
+ def overpayment():
102
+ ans = {"cases": {}, "written_off": []}
103
+ grand = F(0)
104
+ for case in load("cases.json")["cases"]:
105
+ ch = case["discovered_change"]
106
+ after = changed(case, ch)
107
+ out = {"correct": {}}
108
+ total = F(0)
109
+ for m in case["benefit_paid"]:
110
+ if m["month"] < ch["date"][:7]: right = assess(case)["benefit"]
111
+ elif m["month"] > ch["date"][:7]: right = assess(after)["benefit"]
112
+ else: right = sum(e * d for e, d, _ in month_plan(case, [ch], m["days_in_month"])) / m["days_in_month"]
113
+ out["correct"][m["month"]] = money(right)
114
+ total += F(str(m["paid"])) - right
115
+ out["total_overpayment"] = money(total)
116
+ if total < 300:
117
+ out["deductions"] = 0
118
+ if total > 0: ans["written_off"].append(case["case_id"])
119
+ else:
120
+ step = F(ADULT_COUPLE if assess(after)["adults"] == 2 else ADULT_ONE) / 10
121
+ count = 0; owed = total
122
+ while owed > step:
123
+ owed -= step; count += 1
124
+ out["deductions"] = count + 1
125
+ out["last_deduction"] = money(owed)
126
+ grand += total
127
+ ans["cases"][case["case_id"]] = out
128
+ ans["total_to_recover"] = money(grand)
129
+ return ans
130
+
131
+ def review():
132
+ ans = {"wrong_decisions": [], "corrected": {}}
133
+ under = over = F(0)
134
+ for case in load("decisions.json")["decisions"]:
135
+ a = assess(case)
136
+ dec = case["decision"]
137
+ if all(abs(float(a[k]) - dec[k]) <= 0.01 for k in dec): continue
138
+ cid = case["case_id"]
139
+ ans["wrong_decisions"].append(cid)
140
+ fix = dict((k, money(a[k])) for k in dec)
141
+ diff = a["benefit"] - F(str(dec["benefit"]))
142
+ fix["difference"] = money(diff)
143
+ if diff > 0: under += diff
144
+ else: over -= diff
145
+ ans["corrected"][cid] = fix
146
+ ans["total_underpaid"], ans["total_overpaid"] = money(under), money(over)
147
+ return ans
148
+
149
+ if os.path.exists("decisions.json"): answer = review()
150
+ else:
151
+ first = load("cases.json")["cases"][0]
152
+ if "discovered_change" in first: answer = overpayment()
153
+ elif "changes" in first: answer = change()
154
+ else: answer = entitlement()
155
+ with open("answer.json", "w") as f: json.dump(answer, f, indent=1)
tasks/means-test/means-test-change-d1-t0000/solution/solve.sh ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+ cd /app
4
+ python3 /solution/oracle.py
tasks/means-test/means-test-change-d1-t0000/task.toml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version = "1.0"
2
+
3
+ [metadata]
4
+ author_name = "Renaissance Labs"
5
+ author_email = "unknown"
6
+ difficulty = "easy"
7
+ category = "means-test"
8
+ tags = ["means-test", "change", "isced-0923", "train"]
9
+ isced_f = "0923"
10
+ family = "change"
11
+ split = "train"
12
+ seed = 0
13
+
14
+ [verifier]
15
+ timeout_sec = 120.0
16
+
17
+ [agent]
18
+ timeout_sec = 900.0
19
+
20
+ [environment]
21
+ build_timeout_sec = 600.0
22
+ cpus = 1
23
+ memory_mb = 1024
24
+ storage_mb = 2048
25
+ allow_internet = false
tasks/means-test/means-test-change-d1-t0000/tests/checks.json ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "path": "cases.H7903.days",
4
+ "type": "list",
5
+ "value": [
6
+ 14,
7
+ 17
8
+ ],
9
+ "item": "int",
10
+ "weight": 1.0
11
+ },
12
+ {
13
+ "path": "cases.H7903.rates",
14
+ "type": "list",
15
+ "value": [
16
+ 5500.0,
17
+ 3400.0
18
+ ],
19
+ "item": "number",
20
+ "weight": 1.0,
21
+ "abs_tol": 0.01
22
+ },
23
+ {
24
+ "path": "cases.H7903.payable",
25
+ "type": "number",
26
+ "value": 4348.39,
27
+ "abs_tol": 0.01,
28
+ "weight": 2
29
+ },
30
+ {
31
+ "path": "cases.H8675.days",
32
+ "type": "list",
33
+ "value": [
34
+ 18,
35
+ 13
36
+ ],
37
+ "item": "int",
38
+ "weight": 1.0
39
+ },
40
+ {
41
+ "path": "cases.H8675.rates",
42
+ "type": "list",
43
+ "value": [
44
+ 13200.0,
45
+ 11137.5
46
+ ],
47
+ "item": "number",
48
+ "weight": 1.0,
49
+ "abs_tol": 0.01
50
+ },
51
+ {
52
+ "path": "cases.H8675.payable",
53
+ "type": "number",
54
+ "value": 12335.08,
55
+ "abs_tol": 0.01,
56
+ "weight": 2
57
+ },
58
+ {
59
+ "path": "cases.H9283.days",
60
+ "type": "list",
61
+ "value": [
62
+ 11,
63
+ 20
64
+ ],
65
+ "item": "int",
66
+ "weight": 1.0
67
+ },
68
+ {
69
+ "path": "cases.H9283.rates",
70
+ "type": "list",
71
+ "value": [
72
+ 11200.0,
73
+ 9050.0
74
+ ],
75
+ "item": "number",
76
+ "weight": 1.0,
77
+ "abs_tol": 0.01
78
+ },
79
+ {
80
+ "path": "cases.H9283.payable",
81
+ "type": "number",
82
+ "value": 9812.9,
83
+ "abs_tol": 0.01,
84
+ "weight": 2
85
+ },
86
+ {
87
+ "path": "nothing_payable",
88
+ "type": "set",
89
+ "value": [],
90
+ "item": "str",
91
+ "weight": 2
92
+ },
93
+ {
94
+ "path": "total_payable",
95
+ "type": "number",
96
+ "value": 26496.37,
97
+ "abs_tol": 0.01,
98
+ "weight": 1.0
99
+ }
100
+ ]
tasks/means-test/means-test-change-d1-t0000/tests/test.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
tasks/means-test/means-test-change-d1-t0000/tests/verify.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Verifier for Renaissance Labs practice environments. Standard library only.
3
+
4
+ Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
5
+ The reward is the weighted share of checks that pass. A missing, unreadable or non-object
6
+ answer scores 0. Each check addresses one value in the answer by a dotted path.
7
+
8
+ Check types
9
+ int exact integer (a float with integral value is accepted; booleans are not)
10
+ number within abs_tol of value (default 1e-9); booleans and strings are rejected
11
+ str equal after trimming and case-folding
12
+ bool exact boolean
13
+ list ordered list; items compared as int/number/str according to "item" (default str)
14
+ set unordered collection of distinct strings (or ints)
15
+ custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
16
+ """
17
+ import argparse, json, math, os, sys
18
+
19
+ MISSING = object()
20
+
21
+ def lookup(obj, path):
22
+ cur = obj
23
+ for part in path.split("."):
24
+ if isinstance(cur, dict):
25
+ if part not in cur: return MISSING
26
+ cur = cur[part]
27
+ elif isinstance(cur, list):
28
+ try: cur = cur[int(part)]
29
+ except (ValueError, IndexError): return MISSING
30
+ else:
31
+ return MISSING
32
+ return cur
33
+
34
+ def is_num(x):
35
+ return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
36
+
37
+ def eq_int(got, want):
38
+ return is_num(got) and float(got) == float(int(got)) and int(got) == want
39
+
40
+ def eq_num(got, want, tol):
41
+ return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
42
+
43
+ def eq_str(got, want):
44
+ return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
45
+
46
+ def eq_item(got, want, kind, tol):
47
+ if kind == "int": return eq_int(got, want)
48
+ if kind == "number": return eq_num(got, want, tol)
49
+ return eq_str(got, want)
50
+
51
+ def run_check(answer, chk, validators):
52
+ t = chk["type"]
53
+ if t == "custom":
54
+ fn = getattr(validators, chk["name"], None) if validators else None
55
+ if fn is None: return 0.0
56
+ try: r = fn(answer, chk.get("args", {}))
57
+ except Exception: return 0.0
58
+ if r is True: return 1.0
59
+ if r is False or r is None: return 0.0
60
+ return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
61
+ got = lookup(answer, chk["path"])
62
+ if got is MISSING: return 0.0
63
+ want, tol = chk["value"], chk.get("abs_tol", 1e-9)
64
+ if t == "int": ok = eq_int(got, want)
65
+ elif t == "number": ok = eq_num(got, want, tol)
66
+ elif t == "str": ok = eq_str(got, want)
67
+ elif t == "bool": ok = isinstance(got, bool) and got is want
68
+ elif t == "list":
69
+ ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
70
+ elif t == "set":
71
+ kind = chk.get("item", "str")
72
+ if not isinstance(got, list): ok = False
73
+ else:
74
+ norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
75
+ g = [norm(x) for x in got]; w = [norm(x) for x in want]
76
+ ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
77
+ else: ok = False
78
+ return 1.0 if ok else 0.0
79
+
80
+ def grade(answer, checks, validators=None):
81
+ """Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
82
+ if not isinstance(answer, dict):
83
+ return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
84
+ total = sum(c.get("weight", 1.0) for c in checks)
85
+ got, details = 0.0, []
86
+ for c in checks:
87
+ s = run_check(answer, c, validators)
88
+ got += s * c.get("weight", 1.0)
89
+ details.append({"check": c.get("path", c.get("name")), "score": s})
90
+ return (round(got / total, 6) if total else 0.0), details
91
+
92
+ def main():
93
+ ap = argparse.ArgumentParser()
94
+ ap.add_argument("--answer", default="/app/answer.json")
95
+ ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
96
+ ap.add_argument("--out", default="/logs/verifier")
97
+ a = ap.parse_args()
98
+ checks = json.load(open(a.checks))
99
+ try:
100
+ with open(a.answer) as f: answer = json.load(f)
101
+ except Exception:
102
+ answer = None
103
+ validators = None
104
+ here = os.path.dirname(os.path.abspath(__file__))
105
+ if os.path.exists(os.path.join(here, "validators.py")):
106
+ sys.path.insert(0, here)
107
+ import validators # noqa
108
+ reward, details = grade(answer, checks, validators)
109
+ os.makedirs(a.out, exist_ok=True)
110
+ with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
111
+ with open(os.path.join(a.out, "reward.json"), "w") as f:
112
+ json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
113
+ print("reward", reward)
114
+
115
+ if __name__ == "__main__":
116
+ main()
tasks/means-test/means-test-change-d1-t0012/environment/Dockerfile ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ FROM python:3.12-slim
2
+ WORKDIR /app
3
+ COPY workdir/ /app/
tasks/means-test/means-test-change-d1-t0012/environment/workdir/cases.json ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "municipality": "Eskermark",
3
+ "month": "2026-06",
4
+ "days_in_month": 30,
5
+ "cases": [
6
+ {
7
+ "case_id": "H4337",
8
+ "caseworker": "ES",
9
+ "members": [
10
+ {
11
+ "person": "P1",
12
+ "role": "applicant",
13
+ "age": 56,
14
+ "income": [
15
+ {
16
+ "type": "earnings",
17
+ "amount": 3800
18
+ }
19
+ ]
20
+ },
21
+ {
22
+ "person": "P2",
23
+ "role": "partner",
24
+ "age": 60,
25
+ "income": [
26
+ {
27
+ "type": "pension",
28
+ "amount": 5050
29
+ }
30
+ ]
31
+ }
32
+ ],
33
+ "monthly_rent": 5200,
34
+ "liquid_assets": 4800,
35
+ "changes": [
36
+ {
37
+ "date": "2026-06-17",
38
+ "type": "income_change",
39
+ "person": "P2",
40
+ "income": [
41
+ {
42
+ "type": "earnings",
43
+ "amount": 7850
44
+ }
45
+ ]
46
+ }
47
+ ]
48
+ },
49
+ {
50
+ "case_id": "H2617",
51
+ "caseworker": "LB",
52
+ "members": [
53
+ {
54
+ "person": "P1",
55
+ "role": "applicant",
56
+ "age": 22,
57
+ "income": [
58
+ {
59
+ "type": "earnings",
60
+ "amount": 3300
61
+ }
62
+ ]
63
+ },
64
+ {
65
+ "person": "P2",
66
+ "role": "partner",
67
+ "age": 29,
68
+ "income": [
69
+ {
70
+ "type": "earnings",
71
+ "amount": 4200
72
+ }
73
+ ]
74
+ },
75
+ {
76
+ "person": "P3",
77
+ "role": "child",
78
+ "age": 2,
79
+ "income": [
80
+ {
81
+ "type": "child_benefit",
82
+ "amount": 650
83
+ }
84
+ ]
85
+ },
86
+ {
87
+ "person": "P4",
88
+ "role": "child",
89
+ "age": 11,
90
+ "income": [
91
+ {
92
+ "type": "child_benefit",
93
+ "amount": 600
94
+ }
95
+ ]
96
+ }
97
+ ],
98
+ "monthly_rent": 8500,
99
+ "liquid_assets": 2500,
100
+ "changes": [
101
+ {
102
+ "date": "2026-06-03",
103
+ "type": "income_change",
104
+ "person": "P2",
105
+ "income": [
106
+ {
107
+ "type": "earnings",
108
+ "amount": 5300
109
+ }
110
+ ]
111
+ }
112
+ ]
113
+ },
114
+ {
115
+ "case_id": "H7541",
116
+ "caseworker": "LB",
117
+ "members": [
118
+ {
119
+ "person": "P1",
120
+ "role": "applicant",
121
+ "age": 30,
122
+ "income": [
123
+ {
124
+ "type": "unemployment_benefit",
125
+ "amount": 4350
126
+ }
127
+ ]
128
+ },
129
+ {
130
+ "person": "P2",
131
+ "role": "partner",
132
+ "age": 43,
133
+ "income": [
134
+ {
135
+ "type": "earnings",
136
+ "amount": 4850
137
+ }
138
+ ]
139
+ }
140
+ ],
141
+ "monthly_rent": 5050,
142
+ "liquid_assets": 2300,
143
+ "changes": [
144
+ {
145
+ "date": "2026-06-11",
146
+ "type": "income_change",
147
+ "person": "P2",
148
+ "income": [
149
+ {
150
+ "type": "unemployment_benefit",
151
+ "amount": 3750
152
+ }
153
+ ]
154
+ }
155
+ ]
156
+ }
157
+ ]
158
+ }
tasks/means-test/means-test-change-d1-t0012/environment/workdir/regulation.md ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Eskermark Local Support Ordinance (fictional)
2
+
3
+ The Municipality of Eskermark, this ordinance and every amount in it are invented for practice. They do not describe any real benefit scheme. All amounts are per calendar month and in florins (fl). Do not round intermediate results.
4
+
5
+ ## 1. The household
6
+
7
+ The household's **members** are the applicant, the applicant's partner if they live together, and their children under 18 who live with them. In a case file these have the role `applicant`, `partner` or `child`. The applicant and the partner are the adult members.
8
+
9
+ Anyone else who lives in the home has the role `other_resident` (for example a grown-up child or a lodger). An other resident is not a member: their income is ignored and they add nothing to the norm, but they count as a resident when the rent is shared out (section 3).
10
+
11
+ ## 2. The norm
12
+
13
+ The norm is the adult amount plus the child amounts plus the common costs.
14
+
15
+ | Adult amount | fl |
16
+ |---|---|
17
+ | One adult member | 4100 |
18
+ | Two adult members (a couple) | 6900 |
19
+
20
+ | Child amount, for each child member | fl |
21
+ |---|---|
22
+ | Age 0 to 5 | 1450 |
23
+ | Age 6 to 12 | 1800 |
24
+ | Age 13 to 17 | 2250 |
25
+
26
+ | Common costs, by number of members | fl |
27
+ |---|---|
28
+ | 1 | 900 |
29
+ | 2 | 1100 |
30
+ | 3 | 1350 |
31
+ | 4 | 1550 |
32
+ | 5 | 1750 |
33
+ | 6 or more | 1900 |
34
+
35
+ Sanction: if the case file records `sanction_level` 1, the adult amount is reduced by 15%. At `sanction_level` 2 it is reduced by 30%. The child amounts and the common costs are never reduced. Level 0, or no entry, means no sanction.
36
+
37
+ ## 3. Housing allowance
38
+
39
+ The household's rent share is the monthly rent times the number of members, divided by the number of residents (members plus other residents). With no other residents the rent share is the whole rent.
40
+
41
+ The housing allowance is the rent share, but not more than the cap for the number of members:
42
+
43
+ | Number of members | Cap, fl |
44
+ |---|---|
45
+ | 1 | 5200 |
46
+ | 2 | 6400 |
47
+ | 3 | 7300 |
48
+ | 4 | 8100 |
49
+ | 5 or more | 8800 |
50
+
51
+ ## 4. Countable income
52
+
53
+ Each person's income is listed by type.
54
+
55
+ - `earnings` of an adult member: add up that adult's earnings, then take off the work disregard, which is 25% of that adult's earnings but not more than 1200 fl per adult. What is left counts.
56
+ - Counted in full, whichever member receives it: `child_benefit`, `maintenance`, `pension`, `unemployment_benefit`, `sickness_benefit`.
57
+ - Not counted at all: `disability_allowance`, `funeral_grant`, `school_meal_voucher`, and any `earnings` of a child member.
58
+
59
+ Countable income is the sum over all members.
60
+
61
+ ## 5. Assets
62
+
63
+ The asset exemption is 8000 fl for a household with one adult member and 12000 fl for a couple, plus 1500 fl for each child member. The asset excess is the household's liquid assets minus the exemption, or 0 if that is negative. The asset excess is assessed afresh for every month and every period, with the exemption of the household as it then is.
64
+
65
+ ## 6. Monthly entitlement
66
+
67
+ entitlement = norm + housing allowance - countable income - asset excess
68
+
69
+ If this is negative, the entitlement is 0 and the household has no entitlement. For a month in which nothing changes, the benefit payable is the entitlement.
70
+
71
+ ## 7. Changes during a month
72
+
73
+ A change takes effect on its date: that day and the days after it are assessed on the new circumstances. Split the month into periods at each change date. For each period, work out the monthly entitlement (sections 2 to 6) as if the circumstances of that period had lasted the whole month. Then
74
+
75
+ benefit payable for the month = sum over the periods of (monthly entitlement of the period * days in the period / days in the month)
76
+
77
+ If a case file gives a `claim_date`, no benefit is payable for the days before it: the first period starts on the claim date.
78
+
79
+ ## 8. Overpayments and recovery
80
+
81
+ When benefit has been paid on circumstances that later prove to have been different, then for each month under review:
82
+
83
+ correct benefit = the benefit payable for that month on the true circumstances (using section 7 if the change came during the month)
84
+ overpayment = amount paid - correct benefit
85
+
86
+ The total overpayment is the sum over the months under review.
87
+
88
+ - A total overpayment under 300 fl is written off: nothing is recovered.
89
+ - Otherwise it is recovered by a monthly deduction of 10% of the unsanctioned adult amount of the household as it is after the change (410 fl for one adult member, 690 fl for a couple) until the total is repaid. The number of deductions is the total overpayment divided by the monthly deduction, rounded up. Every deduction is the full monthly deduction except the last, which is whatever is still owed.
tasks/means-test/means-test-change-d1-t0012/instruction.md ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Means test: a change during the month
2
+
3
+ `cases.json` holds 3 household case files from the Municipality of Eskermark for 2026-06 (30 days). Each file shows the household as it was on the first day of the month and a list of `changes`, each with the date it takes effect. `regulation.md` is the ordinance to apply (it is fictional; use its rules and amounts exactly). Section 7 says how to handle a change during the month.
4
+
5
+ The kinds of change are:
6
+
7
+ - `income_change`: the named person's whole income list is replaced by the list given.
8
+
9
+ Write `answer.json` in this folder, a JSON object with:
10
+
11
+ - `cases`: an object keyed by case id. Each value has
12
+ - `days`: a list of integers, the number of days in each period, in date order.
13
+ - `rates`: a list of numbers, the monthly entitlement (section 6) of each period, in the same order, fl with 2 decimals.
14
+ - `payable`: the benefit payable for the month, fl with 2 decimals.
15
+ - `nothing_payable`: list of the case ids for which nothing is payable for the month (any order; an empty list if none).
16
+ - `total_payable`: the sum of `payable` over all the cases, fl with 2 decimals.
17
+
18
+ Numbers are accepted within one unit of the last decimal place asked for.
tasks/means-test/means-test-change-d1-t0012/solution/oracle.py ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Reference solution for Means Test. Works only from the files in the current directory.
3
+ The rates below are read off regulation.md (Eskermark Local Support Ordinance, fictional)."""
4
+ import json, os
5
+ from fractions import Fraction as F
6
+
7
+ ADULT_ONE, ADULT_COUPLE = 4100, 6900
8
+ COMMON_COSTS = [900, 1100, 1350, 1550, 1750, 1900] # 1, 2, 3, 4, 5, 6 or more members
9
+ RENT_CAPS = [5200, 6400, 7300, 8100, 8800] # 1, 2, 3, 4, 5 or more members
10
+ FULLY_COUNTED = set(["child_benefit", "maintenance", "pension", "unemployment_benefit", "sickness_benefit"])
11
+
12
+ def load(name):
13
+ with open(name) as f: return json.load(f)
14
+
15
+ def money(x): return round(float(x), 2)
16
+
17
+ def assess(case):
18
+ people = case["members"]
19
+ grown = [p for p in people if p["role"] == "applicant" or p["role"] == "partner"]
20
+ young = [p for p in people if p["role"] == "child"]
21
+ size = len(grown) + len(young)
22
+ # section 2
23
+ adult = F(ADULT_COUPLE if len(grown) == 2 else ADULT_ONE)
24
+ level = case.get("sanction_level") or 0
25
+ if level == 1: adult -= adult * F(15, 100)
26
+ elif level == 2: adult -= adult * F(30, 100)
27
+ norm = adult + COMMON_COSTS[min(size, 6) - 1]
28
+ for p in young:
29
+ norm += 1450 if p["age"] < 6 else 1800 if p["age"] < 13 else 2250
30
+ # section 3
31
+ share = F(case["monthly_rent"]) * size / len(people)
32
+ housing = min(share, F(RENT_CAPS[min(size, 5) - 1]))
33
+ # section 4
34
+ income = F(0)
35
+ for p in grown + young:
36
+ wages = F(0)
37
+ for line in p.get("income", []):
38
+ if line["type"] == "earnings": wages += F(str(line["amount"]))
39
+ elif line["type"] in FULLY_COUNTED: income += F(str(line["amount"]))
40
+ if p["role"] != "child":
41
+ income += wages - min(wages / 4, F(1200))
42
+ # section 5
43
+ allowed = (12000 if len(grown) == 2 else 8000) + 1500 * len(young)
44
+ excess = max(F(0), F(case["liquid_assets"]) - allowed)
45
+ # section 6
46
+ ent = max(F(0), norm + housing - income - excess)
47
+ return {"norm": norm, "countable_income": income, "housing_allowance": housing, "asset_excess": excess, "benefit": ent, "adults": len(grown)}
48
+
49
+ def changed(case, ch):
50
+ new = json.loads(json.dumps(case))
51
+ kind = ch["type"]
52
+ if kind == "income_change":
53
+ for p in new["members"]:
54
+ if p["person"] == ch["person"]: p["income"] = ch["income"]
55
+ elif kind == "rent_change": new["monthly_rent"] = ch["monthly_rent"]
56
+ elif kind == "member_joins": new["members"].append(ch["member"])
57
+ elif kind == "member_leaves": new["members"] = [p for p in new["members"] if p["person"] != ch["person"]]
58
+ return new
59
+
60
+ def day_of(date): return int(date.split("-")[2])
61
+
62
+ def month_plan(case, changes, n_days, first_day=1):
63
+ """Entitlement on each day from first_day to the end of the month, grouped into periods: [(entitlement, days, household)]."""
64
+ changes = sorted(changes, key=lambda c: c["date"])
65
+ periods = []
66
+ for day in range(first_day, n_days + 1):
67
+ cur = case
68
+ for ch in changes:
69
+ if day_of(ch["date"]) <= day: cur = changed(cur, ch)
70
+ starts_new = day == first_day or any(day_of(ch["date"]) == day for ch in changes)
71
+ if starts_new: periods.append([assess(cur)["benefit"], 1, cur])
72
+ else: periods[-1][1] += 1
73
+ return periods
74
+
75
+ def entitlement():
76
+ ans = {"households": {}, "no_entitlement": []}
77
+ total = F(0)
78
+ for case in load("cases.json")["cases"]:
79
+ a = assess(case)
80
+ ans["households"][case["case_id"]] = dict((k, money(a[k])) for k in ("norm", "countable_income", "housing_allowance", "asset_excess", "benefit"))
81
+ if a["benefit"] == 0: ans["no_entitlement"].append(case["case_id"])
82
+ total += a["benefit"]
83
+ ans["total_payable"] = money(total)
84
+ return ans
85
+
86
+ def change():
87
+ data = load("cases.json")
88
+ n_days = data["days_in_month"]
89
+ ans = {"cases": {}, "nothing_payable": []}
90
+ total = F(0)
91
+ for case in data["cases"]:
92
+ first = day_of(case["claim_date"]) if case.get("claim_date") else 1
93
+ periods = month_plan(case, case["changes"], n_days, first)
94
+ pay = sum(e * d for e, d, _ in periods) / n_days
95
+ ans["cases"][case["case_id"]] = {"days": [d for _, d, _ in periods], "rates": [money(e) for e, _, _ in periods], "payable": money(pay)}
96
+ if pay == 0: ans["nothing_payable"].append(case["case_id"])
97
+ total += pay
98
+ ans["total_payable"] = money(total)
99
+ return ans
100
+
101
+ def overpayment():
102
+ ans = {"cases": {}, "written_off": []}
103
+ grand = F(0)
104
+ for case in load("cases.json")["cases"]:
105
+ ch = case["discovered_change"]
106
+ after = changed(case, ch)
107
+ out = {"correct": {}}
108
+ total = F(0)
109
+ for m in case["benefit_paid"]:
110
+ if m["month"] < ch["date"][:7]: right = assess(case)["benefit"]
111
+ elif m["month"] > ch["date"][:7]: right = assess(after)["benefit"]
112
+ else: right = sum(e * d for e, d, _ in month_plan(case, [ch], m["days_in_month"])) / m["days_in_month"]
113
+ out["correct"][m["month"]] = money(right)
114
+ total += F(str(m["paid"])) - right
115
+ out["total_overpayment"] = money(total)
116
+ if total < 300:
117
+ out["deductions"] = 0
118
+ if total > 0: ans["written_off"].append(case["case_id"])
119
+ else:
120
+ step = F(ADULT_COUPLE if assess(after)["adults"] == 2 else ADULT_ONE) / 10
121
+ count = 0; owed = total
122
+ while owed > step:
123
+ owed -= step; count += 1
124
+ out["deductions"] = count + 1
125
+ out["last_deduction"] = money(owed)
126
+ grand += total
127
+ ans["cases"][case["case_id"]] = out
128
+ ans["total_to_recover"] = money(grand)
129
+ return ans
130
+
131
+ def review():
132
+ ans = {"wrong_decisions": [], "corrected": {}}
133
+ under = over = F(0)
134
+ for case in load("decisions.json")["decisions"]:
135
+ a = assess(case)
136
+ dec = case["decision"]
137
+ if all(abs(float(a[k]) - dec[k]) <= 0.01 for k in dec): continue
138
+ cid = case["case_id"]
139
+ ans["wrong_decisions"].append(cid)
140
+ fix = dict((k, money(a[k])) for k in dec)
141
+ diff = a["benefit"] - F(str(dec["benefit"]))
142
+ fix["difference"] = money(diff)
143
+ if diff > 0: under += diff
144
+ else: over -= diff
145
+ ans["corrected"][cid] = fix
146
+ ans["total_underpaid"], ans["total_overpaid"] = money(under), money(over)
147
+ return ans
148
+
149
+ if os.path.exists("decisions.json"): answer = review()
150
+ else:
151
+ first = load("cases.json")["cases"][0]
152
+ if "discovered_change" in first: answer = overpayment()
153
+ elif "changes" in first: answer = change()
154
+ else: answer = entitlement()
155
+ with open("answer.json", "w") as f: json.dump(answer, f, indent=1)
tasks/means-test/means-test-change-d1-t0012/solution/solve.sh ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+ cd /app
4
+ python3 /solution/oracle.py
tasks/means-test/means-test-change-d1-t0012/task.toml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version = "1.0"
2
+
3
+ [metadata]
4
+ author_name = "Renaissance Labs"
5
+ author_email = "unknown"
6
+ difficulty = "easy"
7
+ category = "means-test"
8
+ tags = ["means-test", "change", "isced-0923", "train"]
9
+ isced_f = "0923"
10
+ family = "change"
11
+ split = "train"
12
+ seed = 12
13
+
14
+ [verifier]
15
+ timeout_sec = 120.0
16
+
17
+ [agent]
18
+ timeout_sec = 900.0
19
+
20
+ [environment]
21
+ build_timeout_sec = 600.0
22
+ cpus = 1
23
+ memory_mb = 1024
24
+ storage_mb = 2048
25
+ allow_internet = false
tasks/means-test/means-test-change-d1-t0012/tests/checks.json ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "path": "cases.H2617.days",
4
+ "type": "list",
5
+ "value": [
6
+ 2,
7
+ 28
8
+ ],
9
+ "item": "int",
10
+ "weight": 1.0
11
+ },
12
+ {
13
+ "path": "cases.H2617.rates",
14
+ "type": "list",
15
+ "value": [
16
+ 12925.0,
17
+ 11975.0
18
+ ],
19
+ "item": "number",
20
+ "weight": 1.0,
21
+ "abs_tol": 0.01
22
+ },
23
+ {
24
+ "path": "cases.H2617.payable",
25
+ "type": "number",
26
+ "value": 12038.33,
27
+ "abs_tol": 0.01,
28
+ "weight": 2
29
+ },
30
+ {
31
+ "path": "cases.H4337.days",
32
+ "type": "list",
33
+ "value": [
34
+ 16,
35
+ 14
36
+ ],
37
+ "item": "int",
38
+ "weight": 1.0
39
+ },
40
+ {
41
+ "path": "cases.H4337.rates",
42
+ "type": "list",
43
+ "value": [
44
+ 5300.0,
45
+ 3700.0
46
+ ],
47
+ "item": "number",
48
+ "weight": 1.0,
49
+ "abs_tol": 0.01
50
+ },
51
+ {
52
+ "path": "cases.H4337.payable",
53
+ "type": "number",
54
+ "value": 4553.33,
55
+ "abs_tol": 0.01,
56
+ "weight": 2
57
+ },
58
+ {
59
+ "path": "cases.H7541.days",
60
+ "type": "list",
61
+ "value": [
62
+ 10,
63
+ 20
64
+ ],
65
+ "item": "int",
66
+ "weight": 1.0
67
+ },
68
+ {
69
+ "path": "cases.H7541.rates",
70
+ "type": "list",
71
+ "value": [
72
+ 5050.0,
73
+ 4950.0
74
+ ],
75
+ "item": "number",
76
+ "weight": 1.0,
77
+ "abs_tol": 0.01
78
+ },
79
+ {
80
+ "path": "cases.H7541.payable",
81
+ "type": "number",
82
+ "value": 4983.33,
83
+ "abs_tol": 0.01,
84
+ "weight": 2
85
+ },
86
+ {
87
+ "path": "nothing_payable",
88
+ "type": "set",
89
+ "value": [],
90
+ "item": "str",
91
+ "weight": 2
92
+ },
93
+ {
94
+ "path": "total_payable",
95
+ "type": "number",
96
+ "value": 21575.0,
97
+ "abs_tol": 0.01,
98
+ "weight": 1.0
99
+ }
100
+ ]
tasks/means-test/means-test-change-d1-t0012/tests/test.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
tasks/means-test/means-test-change-d1-t0012/tests/verify.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Verifier for Renaissance Labs practice environments. Standard library only.
3
+
4
+ Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
5
+ The reward is the weighted share of checks that pass. A missing, unreadable or non-object
6
+ answer scores 0. Each check addresses one value in the answer by a dotted path.
7
+
8
+ Check types
9
+ int exact integer (a float with integral value is accepted; booleans are not)
10
+ number within abs_tol of value (default 1e-9); booleans and strings are rejected
11
+ str equal after trimming and case-folding
12
+ bool exact boolean
13
+ list ordered list; items compared as int/number/str according to "item" (default str)
14
+ set unordered collection of distinct strings (or ints)
15
+ custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
16
+ """
17
+ import argparse, json, math, os, sys
18
+
19
+ MISSING = object()
20
+
21
+ def lookup(obj, path):
22
+ cur = obj
23
+ for part in path.split("."):
24
+ if isinstance(cur, dict):
25
+ if part not in cur: return MISSING
26
+ cur = cur[part]
27
+ elif isinstance(cur, list):
28
+ try: cur = cur[int(part)]
29
+ except (ValueError, IndexError): return MISSING
30
+ else:
31
+ return MISSING
32
+ return cur
33
+
34
+ def is_num(x):
35
+ return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
36
+
37
+ def eq_int(got, want):
38
+ return is_num(got) and float(got) == float(int(got)) and int(got) == want
39
+
40
+ def eq_num(got, want, tol):
41
+ return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
42
+
43
+ def eq_str(got, want):
44
+ return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
45
+
46
+ def eq_item(got, want, kind, tol):
47
+ if kind == "int": return eq_int(got, want)
48
+ if kind == "number": return eq_num(got, want, tol)
49
+ return eq_str(got, want)
50
+
51
+ def run_check(answer, chk, validators):
52
+ t = chk["type"]
53
+ if t == "custom":
54
+ fn = getattr(validators, chk["name"], None) if validators else None
55
+ if fn is None: return 0.0
56
+ try: r = fn(answer, chk.get("args", {}))
57
+ except Exception: return 0.0
58
+ if r is True: return 1.0
59
+ if r is False or r is None: return 0.0
60
+ return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
61
+ got = lookup(answer, chk["path"])
62
+ if got is MISSING: return 0.0
63
+ want, tol = chk["value"], chk.get("abs_tol", 1e-9)
64
+ if t == "int": ok = eq_int(got, want)
65
+ elif t == "number": ok = eq_num(got, want, tol)
66
+ elif t == "str": ok = eq_str(got, want)
67
+ elif t == "bool": ok = isinstance(got, bool) and got is want
68
+ elif t == "list":
69
+ ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
70
+ elif t == "set":
71
+ kind = chk.get("item", "str")
72
+ if not isinstance(got, list): ok = False
73
+ else:
74
+ norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
75
+ g = [norm(x) for x in got]; w = [norm(x) for x in want]
76
+ ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
77
+ else: ok = False
78
+ return 1.0 if ok else 0.0
79
+
80
+ def grade(answer, checks, validators=None):
81
+ """Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
82
+ if not isinstance(answer, dict):
83
+ return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
84
+ total = sum(c.get("weight", 1.0) for c in checks)
85
+ got, details = 0.0, []
86
+ for c in checks:
87
+ s = run_check(answer, c, validators)
88
+ got += s * c.get("weight", 1.0)
89
+ details.append({"check": c.get("path", c.get("name")), "score": s})
90
+ return (round(got / total, 6) if total else 0.0), details
91
+
92
+ def main():
93
+ ap = argparse.ArgumentParser()
94
+ ap.add_argument("--answer", default="/app/answer.json")
95
+ ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
96
+ ap.add_argument("--out", default="/logs/verifier")
97
+ a = ap.parse_args()
98
+ checks = json.load(open(a.checks))
99
+ try:
100
+ with open(a.answer) as f: answer = json.load(f)
101
+ except Exception:
102
+ answer = None
103
+ validators = None
104
+ here = os.path.dirname(os.path.abspath(__file__))
105
+ if os.path.exists(os.path.join(here, "validators.py")):
106
+ sys.path.insert(0, here)
107
+ import validators # noqa
108
+ reward, details = grade(answer, checks, validators)
109
+ os.makedirs(a.out, exist_ok=True)
110
+ with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
111
+ with open(os.path.join(a.out, "reward.json"), "w") as f:
112
+ json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
113
+ print("reward", reward)
114
+
115
+ if __name__ == "__main__":
116
+ main()
tasks/means-test/means-test-change-d1-t0024/environment/Dockerfile ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ FROM python:3.12-slim
2
+ WORKDIR /app
3
+ COPY workdir/ /app/
tasks/means-test/means-test-change-d1-t0024/environment/workdir/cases.json ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "municipality": "Eskermark",
3
+ "month": "2026-07",
4
+ "days_in_month": 31,
5
+ "cases": [
6
+ {
7
+ "case_id": "H6240",
8
+ "caseworker": "OH",
9
+ "members": [
10
+ {
11
+ "person": "P1",
12
+ "role": "applicant",
13
+ "age": 20,
14
+ "income": [
15
+ {
16
+ "type": "sickness_benefit",
17
+ "amount": 4950
18
+ }
19
+ ]
20
+ },
21
+ {
22
+ "person": "P2",
23
+ "role": "partner",
24
+ "age": 24,
25
+ "income": [
26
+ {
27
+ "type": "earnings",
28
+ "amount": 3000
29
+ }
30
+ ]
31
+ },
32
+ {
33
+ "person": "P3",
34
+ "role": "child",
35
+ "age": 6,
36
+ "income": [
37
+ {
38
+ "type": "child_benefit",
39
+ "amount": 600
40
+ }
41
+ ]
42
+ },
43
+ {
44
+ "person": "P4",
45
+ "role": "child",
46
+ "age": 9,
47
+ "income": [
48
+ {
49
+ "type": "child_benefit",
50
+ "amount": 700
51
+ }
52
+ ]
53
+ }
54
+ ],
55
+ "monthly_rent": 9700,
56
+ "liquid_assets": 2400,
57
+ "changes": [
58
+ {
59
+ "date": "2026-07-31",
60
+ "type": "income_change",
61
+ "person": "P2",
62
+ "income": [
63
+ {
64
+ "type": "unemployment_benefit",
65
+ "amount": 3200
66
+ }
67
+ ]
68
+ }
69
+ ]
70
+ },
71
+ {
72
+ "case_id": "H3736",
73
+ "caseworker": "LB",
74
+ "members": [
75
+ {
76
+ "person": "P1",
77
+ "role": "applicant",
78
+ "age": 43,
79
+ "income": [
80
+ {
81
+ "type": "earnings",
82
+ "amount": 5300
83
+ }
84
+ ]
85
+ }
86
+ ],
87
+ "monthly_rent": 4050,
88
+ "liquid_assets": 200,
89
+ "changes": [
90
+ {
91
+ "date": "2026-07-03",
92
+ "type": "income_change",
93
+ "person": "P1",
94
+ "income": [
95
+ {
96
+ "type": "unemployment_benefit",
97
+ "amount": 2250
98
+ }
99
+ ]
100
+ }
101
+ ]
102
+ },
103
+ {
104
+ "case_id": "H3130",
105
+ "caseworker": "LB",
106
+ "members": [
107
+ {
108
+ "person": "P1",
109
+ "role": "applicant",
110
+ "age": 62,
111
+ "income": [
112
+ {
113
+ "type": "earnings",
114
+ "amount": 7100
115
+ }
116
+ ]
117
+ }
118
+ ],
119
+ "monthly_rent": 5500,
120
+ "liquid_assets": 4800,
121
+ "changes": [
122
+ {
123
+ "date": "2026-07-12",
124
+ "type": "income_change",
125
+ "person": "P1",
126
+ "income": [
127
+ {
128
+ "type": "unemployment_benefit",
129
+ "amount": 2900
130
+ }
131
+ ]
132
+ }
133
+ ]
134
+ }
135
+ ]
136
+ }
tasks/means-test/means-test-change-d1-t0024/environment/workdir/regulation.md ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Eskermark Local Support Ordinance (fictional)
2
+
3
+ The Municipality of Eskermark, this ordinance and every amount in it are invented for practice. They do not describe any real benefit scheme. All amounts are per calendar month and in florins (fl). Do not round intermediate results.
4
+
5
+ ## 1. The household
6
+
7
+ The household's **members** are the applicant, the applicant's partner if they live together, and their children under 18 who live with them. In a case file these have the role `applicant`, `partner` or `child`. The applicant and the partner are the adult members.
8
+
9
+ Anyone else who lives in the home has the role `other_resident` (for example a grown-up child or a lodger). An other resident is not a member: their income is ignored and they add nothing to the norm, but they count as a resident when the rent is shared out (section 3).
10
+
11
+ ## 2. The norm
12
+
13
+ The norm is the adult amount plus the child amounts plus the common costs.
14
+
15
+ | Adult amount | fl |
16
+ |---|---|
17
+ | One adult member | 4100 |
18
+ | Two adult members (a couple) | 6900 |
19
+
20
+ | Child amount, for each child member | fl |
21
+ |---|---|
22
+ | Age 0 to 5 | 1450 |
23
+ | Age 6 to 12 | 1800 |
24
+ | Age 13 to 17 | 2250 |
25
+
26
+ | Common costs, by number of members | fl |
27
+ |---|---|
28
+ | 1 | 900 |
29
+ | 2 | 1100 |
30
+ | 3 | 1350 |
31
+ | 4 | 1550 |
32
+ | 5 | 1750 |
33
+ | 6 or more | 1900 |
34
+
35
+ Sanction: if the case file records `sanction_level` 1, the adult amount is reduced by 15%. At `sanction_level` 2 it is reduced by 30%. The child amounts and the common costs are never reduced. Level 0, or no entry, means no sanction.
36
+
37
+ ## 3. Housing allowance
38
+
39
+ The household's rent share is the monthly rent times the number of members, divided by the number of residents (members plus other residents). With no other residents the rent share is the whole rent.
40
+
41
+ The housing allowance is the rent share, but not more than the cap for the number of members:
42
+
43
+ | Number of members | Cap, fl |
44
+ |---|---|
45
+ | 1 | 5200 |
46
+ | 2 | 6400 |
47
+ | 3 | 7300 |
48
+ | 4 | 8100 |
49
+ | 5 or more | 8800 |
50
+
51
+ ## 4. Countable income
52
+
53
+ Each person's income is listed by type.
54
+
55
+ - `earnings` of an adult member: add up that adult's earnings, then take off the work disregard, which is 25% of that adult's earnings but not more than 1200 fl per adult. What is left counts.
56
+ - Counted in full, whichever member receives it: `child_benefit`, `maintenance`, `pension`, `unemployment_benefit`, `sickness_benefit`.
57
+ - Not counted at all: `disability_allowance`, `funeral_grant`, `school_meal_voucher`, and any `earnings` of a child member.
58
+
59
+ Countable income is the sum over all members.
60
+
61
+ ## 5. Assets
62
+
63
+ The asset exemption is 8000 fl for a household with one adult member and 12000 fl for a couple, plus 1500 fl for each child member. The asset excess is the household's liquid assets minus the exemption, or 0 if that is negative. The asset excess is assessed afresh for every month and every period, with the exemption of the household as it then is.
64
+
65
+ ## 6. Monthly entitlement
66
+
67
+ entitlement = norm + housing allowance - countable income - asset excess
68
+
69
+ If this is negative, the entitlement is 0 and the household has no entitlement. For a month in which nothing changes, the benefit payable is the entitlement.
70
+
71
+ ## 7. Changes during a month
72
+
73
+ A change takes effect on its date: that day and the days after it are assessed on the new circumstances. Split the month into periods at each change date. For each period, work out the monthly entitlement (sections 2 to 6) as if the circumstances of that period had lasted the whole month. Then
74
+
75
+ benefit payable for the month = sum over the periods of (monthly entitlement of the period * days in the period / days in the month)
76
+
77
+ If a case file gives a `claim_date`, no benefit is payable for the days before it: the first period starts on the claim date.
78
+
79
+ ## 8. Overpayments and recovery
80
+
81
+ When benefit has been paid on circumstances that later prove to have been different, then for each month under review:
82
+
83
+ correct benefit = the benefit payable for that month on the true circumstances (using section 7 if the change came during the month)
84
+ overpayment = amount paid - correct benefit
85
+
86
+ The total overpayment is the sum over the months under review.
87
+
88
+ - A total overpayment under 300 fl is written off: nothing is recovered.
89
+ - Otherwise it is recovered by a monthly deduction of 10% of the unsanctioned adult amount of the household as it is after the change (410 fl for one adult member, 690 fl for a couple) until the total is repaid. The number of deductions is the total overpayment divided by the monthly deduction, rounded up. Every deduction is the full monthly deduction except the last, which is whatever is still owed.
tasks/means-test/means-test-change-d1-t0024/instruction.md ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Means test: a change during the month
2
+
3
+ `cases.json` holds 3 household case files from the Municipality of Eskermark for 2026-07 (31 days). Each file shows the household as it was on the first day of the month and a list of `changes`, each with the date it takes effect. `regulation.md` is the ordinance to apply (it is fictional; use its rules and amounts exactly). Section 7 says how to handle a change during the month.
4
+
5
+ The kinds of change are:
6
+
7
+ - `income_change`: the named person's whole income list is replaced by the list given.
8
+
9
+ Write `answer.json` in this folder, a JSON object with:
10
+
11
+ - `cases`: an object keyed by case id. Each value has
12
+ - `days`: a list of integers, the number of days in each period, in date order.
13
+ - `rates`: a list of numbers, the monthly entitlement (section 6) of each period, in the same order, fl with 2 decimals.
14
+ - `payable`: the benefit payable for the month, fl with 2 decimals.
15
+ - `nothing_payable`: list of the case ids for which nothing is payable for the month (any order; an empty list if none).
16
+ - `total_payable`: the sum of `payable` over all the cases, fl with 2 decimals.
17
+
18
+ Numbers are accepted within one unit of the last decimal place asked for.
tasks/means-test/means-test-change-d1-t0024/solution/oracle.py ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Reference solution for Means Test. Works only from the files in the current directory.
3
+ The rates below are read off regulation.md (Eskermark Local Support Ordinance, fictional)."""
4
+ import json, os
5
+ from fractions import Fraction as F
6
+
7
+ ADULT_ONE, ADULT_COUPLE = 4100, 6900
8
+ COMMON_COSTS = [900, 1100, 1350, 1550, 1750, 1900] # 1, 2, 3, 4, 5, 6 or more members
9
+ RENT_CAPS = [5200, 6400, 7300, 8100, 8800] # 1, 2, 3, 4, 5 or more members
10
+ FULLY_COUNTED = set(["child_benefit", "maintenance", "pension", "unemployment_benefit", "sickness_benefit"])
11
+
12
+ def load(name):
13
+ with open(name) as f: return json.load(f)
14
+
15
+ def money(x): return round(float(x), 2)
16
+
17
+ def assess(case):
18
+ people = case["members"]
19
+ grown = [p for p in people if p["role"] == "applicant" or p["role"] == "partner"]
20
+ young = [p for p in people if p["role"] == "child"]
21
+ size = len(grown) + len(young)
22
+ # section 2
23
+ adult = F(ADULT_COUPLE if len(grown) == 2 else ADULT_ONE)
24
+ level = case.get("sanction_level") or 0
25
+ if level == 1: adult -= adult * F(15, 100)
26
+ elif level == 2: adult -= adult * F(30, 100)
27
+ norm = adult + COMMON_COSTS[min(size, 6) - 1]
28
+ for p in young:
29
+ norm += 1450 if p["age"] < 6 else 1800 if p["age"] < 13 else 2250
30
+ # section 3
31
+ share = F(case["monthly_rent"]) * size / len(people)
32
+ housing = min(share, F(RENT_CAPS[min(size, 5) - 1]))
33
+ # section 4
34
+ income = F(0)
35
+ for p in grown + young:
36
+ wages = F(0)
37
+ for line in p.get("income", []):
38
+ if line["type"] == "earnings": wages += F(str(line["amount"]))
39
+ elif line["type"] in FULLY_COUNTED: income += F(str(line["amount"]))
40
+ if p["role"] != "child":
41
+ income += wages - min(wages / 4, F(1200))
42
+ # section 5
43
+ allowed = (12000 if len(grown) == 2 else 8000) + 1500 * len(young)
44
+ excess = max(F(0), F(case["liquid_assets"]) - allowed)
45
+ # section 6
46
+ ent = max(F(0), norm + housing - income - excess)
47
+ return {"norm": norm, "countable_income": income, "housing_allowance": housing, "asset_excess": excess, "benefit": ent, "adults": len(grown)}
48
+
49
+ def changed(case, ch):
50
+ new = json.loads(json.dumps(case))
51
+ kind = ch["type"]
52
+ if kind == "income_change":
53
+ for p in new["members"]:
54
+ if p["person"] == ch["person"]: p["income"] = ch["income"]
55
+ elif kind == "rent_change": new["monthly_rent"] = ch["monthly_rent"]
56
+ elif kind == "member_joins": new["members"].append(ch["member"])
57
+ elif kind == "member_leaves": new["members"] = [p for p in new["members"] if p["person"] != ch["person"]]
58
+ return new
59
+
60
+ def day_of(date): return int(date.split("-")[2])
61
+
62
+ def month_plan(case, changes, n_days, first_day=1):
63
+ """Entitlement on each day from first_day to the end of the month, grouped into periods: [(entitlement, days, household)]."""
64
+ changes = sorted(changes, key=lambda c: c["date"])
65
+ periods = []
66
+ for day in range(first_day, n_days + 1):
67
+ cur = case
68
+ for ch in changes:
69
+ if day_of(ch["date"]) <= day: cur = changed(cur, ch)
70
+ starts_new = day == first_day or any(day_of(ch["date"]) == day for ch in changes)
71
+ if starts_new: periods.append([assess(cur)["benefit"], 1, cur])
72
+ else: periods[-1][1] += 1
73
+ return periods
74
+
75
+ def entitlement():
76
+ ans = {"households": {}, "no_entitlement": []}
77
+ total = F(0)
78
+ for case in load("cases.json")["cases"]:
79
+ a = assess(case)
80
+ ans["households"][case["case_id"]] = dict((k, money(a[k])) for k in ("norm", "countable_income", "housing_allowance", "asset_excess", "benefit"))
81
+ if a["benefit"] == 0: ans["no_entitlement"].append(case["case_id"])
82
+ total += a["benefit"]
83
+ ans["total_payable"] = money(total)
84
+ return ans
85
+
86
+ def change():
87
+ data = load("cases.json")
88
+ n_days = data["days_in_month"]
89
+ ans = {"cases": {}, "nothing_payable": []}
90
+ total = F(0)
91
+ for case in data["cases"]:
92
+ first = day_of(case["claim_date"]) if case.get("claim_date") else 1
93
+ periods = month_plan(case, case["changes"], n_days, first)
94
+ pay = sum(e * d for e, d, _ in periods) / n_days
95
+ ans["cases"][case["case_id"]] = {"days": [d for _, d, _ in periods], "rates": [money(e) for e, _, _ in periods], "payable": money(pay)}
96
+ if pay == 0: ans["nothing_payable"].append(case["case_id"])
97
+ total += pay
98
+ ans["total_payable"] = money(total)
99
+ return ans
100
+
101
+ def overpayment():
102
+ ans = {"cases": {}, "written_off": []}
103
+ grand = F(0)
104
+ for case in load("cases.json")["cases"]:
105
+ ch = case["discovered_change"]
106
+ after = changed(case, ch)
107
+ out = {"correct": {}}
108
+ total = F(0)
109
+ for m in case["benefit_paid"]:
110
+ if m["month"] < ch["date"][:7]: right = assess(case)["benefit"]
111
+ elif m["month"] > ch["date"][:7]: right = assess(after)["benefit"]
112
+ else: right = sum(e * d for e, d, _ in month_plan(case, [ch], m["days_in_month"])) / m["days_in_month"]
113
+ out["correct"][m["month"]] = money(right)
114
+ total += F(str(m["paid"])) - right
115
+ out["total_overpayment"] = money(total)
116
+ if total < 300:
117
+ out["deductions"] = 0
118
+ if total > 0: ans["written_off"].append(case["case_id"])
119
+ else:
120
+ step = F(ADULT_COUPLE if assess(after)["adults"] == 2 else ADULT_ONE) / 10
121
+ count = 0; owed = total
122
+ while owed > step:
123
+ owed -= step; count += 1
124
+ out["deductions"] = count + 1
125
+ out["last_deduction"] = money(owed)
126
+ grand += total
127
+ ans["cases"][case["case_id"]] = out
128
+ ans["total_to_recover"] = money(grand)
129
+ return ans
130
+
131
+ def review():
132
+ ans = {"wrong_decisions": [], "corrected": {}}
133
+ under = over = F(0)
134
+ for case in load("decisions.json")["decisions"]:
135
+ a = assess(case)
136
+ dec = case["decision"]
137
+ if all(abs(float(a[k]) - dec[k]) <= 0.01 for k in dec): continue
138
+ cid = case["case_id"]
139
+ ans["wrong_decisions"].append(cid)
140
+ fix = dict((k, money(a[k])) for k in dec)
141
+ diff = a["benefit"] - F(str(dec["benefit"]))
142
+ fix["difference"] = money(diff)
143
+ if diff > 0: under += diff
144
+ else: over -= diff
145
+ ans["corrected"][cid] = fix
146
+ ans["total_underpaid"], ans["total_overpaid"] = money(under), money(over)
147
+ return ans
148
+
149
+ if os.path.exists("decisions.json"): answer = review()
150
+ else:
151
+ first = load("cases.json")["cases"][0]
152
+ if "discovered_change" in first: answer = overpayment()
153
+ elif "changes" in first: answer = change()
154
+ else: answer = entitlement()
155
+ with open("answer.json", "w") as f: json.dump(answer, f, indent=1)
tasks/means-test/means-test-change-d1-t0024/solution/solve.sh ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+ cd /app
4
+ python3 /solution/oracle.py
tasks/means-test/means-test-change-d1-t0024/task.toml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version = "1.0"
2
+
3
+ [metadata]
4
+ author_name = "Renaissance Labs"
5
+ author_email = "unknown"
6
+ difficulty = "easy"
7
+ category = "means-test"
8
+ tags = ["means-test", "change", "isced-0923", "train"]
9
+ isced_f = "0923"
10
+ family = "change"
11
+ split = "train"
12
+ seed = 24
13
+
14
+ [verifier]
15
+ timeout_sec = 120.0
16
+
17
+ [agent]
18
+ timeout_sec = 900.0
19
+
20
+ [environment]
21
+ build_timeout_sec = 600.0
22
+ cpus = 1
23
+ memory_mb = 1024
24
+ storage_mb = 2048
25
+ allow_internet = false
tasks/means-test/means-test-change-d1-t0024/tests/checks.json ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "path": "cases.H3130.days",
4
+ "type": "list",
5
+ "value": [
6
+ 11,
7
+ 20
8
+ ],
9
+ "item": "int",
10
+ "weight": 1.0
11
+ },
12
+ {
13
+ "path": "cases.H3130.rates",
14
+ "type": "list",
15
+ "value": [
16
+ 4300.0,
17
+ 7300.0
18
+ ],
19
+ "item": "number",
20
+ "weight": 1.0,
21
+ "abs_tol": 0.01
22
+ },
23
+ {
24
+ "path": "cases.H3130.payable",
25
+ "type": "number",
26
+ "value": 6235.48,
27
+ "abs_tol": 0.01,
28
+ "weight": 2
29
+ },
30
+ {
31
+ "path": "cases.H3736.days",
32
+ "type": "list",
33
+ "value": [
34
+ 2,
35
+ 29
36
+ ],
37
+ "item": "int",
38
+ "weight": 1.0
39
+ },
40
+ {
41
+ "path": "cases.H3736.rates",
42
+ "type": "list",
43
+ "value": [
44
+ 4950.0,
45
+ 6800.0
46
+ ],
47
+ "item": "number",
48
+ "weight": 1.0,
49
+ "abs_tol": 0.01
50
+ },
51
+ {
52
+ "path": "cases.H3736.payable",
53
+ "type": "number",
54
+ "value": 6680.65,
55
+ "abs_tol": 0.01,
56
+ "weight": 2
57
+ },
58
+ {
59
+ "path": "cases.H6240.days",
60
+ "type": "list",
61
+ "value": [
62
+ 30,
63
+ 1
64
+ ],
65
+ "item": "int",
66
+ "weight": 1.0
67
+ },
68
+ {
69
+ "path": "cases.H6240.rates",
70
+ "type": "list",
71
+ "value": [
72
+ 11650.0,
73
+ 10700.0
74
+ ],
75
+ "item": "number",
76
+ "weight": 1.0,
77
+ "abs_tol": 0.01
78
+ },
79
+ {
80
+ "path": "cases.H6240.payable",
81
+ "type": "number",
82
+ "value": 11619.35,
83
+ "abs_tol": 0.01,
84
+ "weight": 2
85
+ },
86
+ {
87
+ "path": "nothing_payable",
88
+ "type": "set",
89
+ "value": [],
90
+ "item": "str",
91
+ "weight": 2
92
+ },
93
+ {
94
+ "path": "total_payable",
95
+ "type": "number",
96
+ "value": 24535.48,
97
+ "abs_tol": 0.01,
98
+ "weight": 1.0
99
+ }
100
+ ]
tasks/means-test/means-test-change-d1-t0024/tests/test.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
tasks/means-test/means-test-change-d1-t0024/tests/verify.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Verifier for Renaissance Labs practice environments. Standard library only.
3
+
4
+ Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
5
+ The reward is the weighted share of checks that pass. A missing, unreadable or non-object
6
+ answer scores 0. Each check addresses one value in the answer by a dotted path.
7
+
8
+ Check types
9
+ int exact integer (a float with integral value is accepted; booleans are not)
10
+ number within abs_tol of value (default 1e-9); booleans and strings are rejected
11
+ str equal after trimming and case-folding
12
+ bool exact boolean
13
+ list ordered list; items compared as int/number/str according to "item" (default str)
14
+ set unordered collection of distinct strings (or ints)
15
+ custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
16
+ """
17
+ import argparse, json, math, os, sys
18
+
19
+ MISSING = object()
20
+
21
+ def lookup(obj, path):
22
+ cur = obj
23
+ for part in path.split("."):
24
+ if isinstance(cur, dict):
25
+ if part not in cur: return MISSING
26
+ cur = cur[part]
27
+ elif isinstance(cur, list):
28
+ try: cur = cur[int(part)]
29
+ except (ValueError, IndexError): return MISSING
30
+ else:
31
+ return MISSING
32
+ return cur
33
+
34
+ def is_num(x):
35
+ return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
36
+
37
+ def eq_int(got, want):
38
+ return is_num(got) and float(got) == float(int(got)) and int(got) == want
39
+
40
+ def eq_num(got, want, tol):
41
+ return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
42
+
43
+ def eq_str(got, want):
44
+ return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
45
+
46
+ def eq_item(got, want, kind, tol):
47
+ if kind == "int": return eq_int(got, want)
48
+ if kind == "number": return eq_num(got, want, tol)
49
+ return eq_str(got, want)
50
+
51
+ def run_check(answer, chk, validators):
52
+ t = chk["type"]
53
+ if t == "custom":
54
+ fn = getattr(validators, chk["name"], None) if validators else None
55
+ if fn is None: return 0.0
56
+ try: r = fn(answer, chk.get("args", {}))
57
+ except Exception: return 0.0
58
+ if r is True: return 1.0
59
+ if r is False or r is None: return 0.0
60
+ return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
61
+ got = lookup(answer, chk["path"])
62
+ if got is MISSING: return 0.0
63
+ want, tol = chk["value"], chk.get("abs_tol", 1e-9)
64
+ if t == "int": ok = eq_int(got, want)
65
+ elif t == "number": ok = eq_num(got, want, tol)
66
+ elif t == "str": ok = eq_str(got, want)
67
+ elif t == "bool": ok = isinstance(got, bool) and got is want
68
+ elif t == "list":
69
+ ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
70
+ elif t == "set":
71
+ kind = chk.get("item", "str")
72
+ if not isinstance(got, list): ok = False
73
+ else:
74
+ norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
75
+ g = [norm(x) for x in got]; w = [norm(x) for x in want]
76
+ ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
77
+ else: ok = False
78
+ return 1.0 if ok else 0.0
79
+
80
+ def grade(answer, checks, validators=None):
81
+ """Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
82
+ if not isinstance(answer, dict):
83
+ return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
84
+ total = sum(c.get("weight", 1.0) for c in checks)
85
+ got, details = 0.0, []
86
+ for c in checks:
87
+ s = run_check(answer, c, validators)
88
+ got += s * c.get("weight", 1.0)
89
+ details.append({"check": c.get("path", c.get("name")), "score": s})
90
+ return (round(got / total, 6) if total else 0.0), details
91
+
92
+ def main():
93
+ ap = argparse.ArgumentParser()
94
+ ap.add_argument("--answer", default="/app/answer.json")
95
+ ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
96
+ ap.add_argument("--out", default="/logs/verifier")
97
+ a = ap.parse_args()
98
+ checks = json.load(open(a.checks))
99
+ try:
100
+ with open(a.answer) as f: answer = json.load(f)
101
+ except Exception:
102
+ answer = None
103
+ validators = None
104
+ here = os.path.dirname(os.path.abspath(__file__))
105
+ if os.path.exists(os.path.join(here, "validators.py")):
106
+ sys.path.insert(0, here)
107
+ import validators # noqa
108
+ reward, details = grade(answer, checks, validators)
109
+ os.makedirs(a.out, exist_ok=True)
110
+ with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
111
+ with open(os.path.join(a.out, "reward.json"), "w") as f:
112
+ json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
113
+ print("reward", reward)
114
+
115
+ if __name__ == "__main__":
116
+ main()