Verifier borrow/provenance work, new phase3 shield_index conformance cases, dev-intervals/dev-lru/dev-shards tasks with evaluate.py harness, and agent skill/hook config.
2.0 KiB
Task: sharded word count
Development task (dev set). Its results are not evidence about any language.
Write a program that counts words in its standard input using several concurrent workers, then merges their results.
Input
The input is a sequence of lines separated by \n. If the input ends with \n, that final \n does not start another line. The input is at most 24 KiB and has at most 2000 lines.
The first line is always workers W, where W is a decimal number with 1 ≤ W ≤ 8 and no leading zeros. Every later line is a text line; text lines are numbered from 0. Text lines contain only ASCII characters other than \n.
A word is a maximal run of ASCII letters (A–Z, a–z) in a text line, converted to lowercase. A word longer than 16 letters counts as its first 16 letters. Every other character separates words. There are at most 2000 distinct words.
Concurrency requirement
The program MUST start W workers (threads or tasks) that run concurrently. Text line k is assigned to worker k mod W. Each worker counts the words of its own lines only. After all workers have finished, the results are merged. The output must not depend on how the workers are scheduled.
Output
- For each worker i from 0 to W − 1:
worker i lines L words N, where L is the number of text lines assigned to worker i and N the number of words in them. distinct D, where D is the number of distinct words in the whole input.- Up to 10 lines
word countfor the most frequent words: by count, highest first; equal counts in increasing byte order of the word.
Every output line ends with \n. Nothing else is written to standard output.
Example
Input:
workers 2
The cat sat.
the CAT, the hat
a-b-c
Output:
worker 0 lines 2 words 6
worker 1 lines 1 words 4
distinct 7
the 3
cat 2
a 1
b 1
c 1
hat 1
sat 1
The repository contains a README with the program's interface for this language and a public test script, sh test.sh, which must pass. Hidden tests check the requirements above.