Files
lush_grading/tasks/pipeline/pipeline_word_freq.toml
Cormac Shannon 20e62f60f6 Reorganize task categories from opaque a/b to descriptive names
Replace category_a/category_b directories with algorithm, pipeline,
environment, filesystem, and process. Add separate mode field (solve/convert)
to decouple orchestration from capability grouping. Add per-category
summary and questionnaire breakdowns to both terminal report and HTML export.
2026-03-29 20:59:01 +01:00

38 lines
1.0 KiB
TOML

name = "pipeline_word_freq"
category = "pipeline"
mode = "convert"
description = """
Read text from stdin. Count the frequency of each word (case-insensitive, only alphabetic characters count as words).
Print the top 5 most frequent words in descending order of frequency, in the format:
"count word"
If two words have the same count, sort them alphabetically.
If there are fewer than 5 unique words, print all of them.
"""
bash_source = """
#!/bin/bash
tr '[:upper:]' '[:lower:]' | tr -cs '[:alpha:]' '\n' | grep -v '^$' | sort | uniq -c | sort -k1,1rn -k2,2 | head -5 | while read -r count word || [[ -n "$word" ]]; do
echo "$count $word"
done
"""
[[test_cases]]
stdin = """The quick brown fox jumps over the lazy dog.
The dog barked at the fox. The fox ran away."""
expected_stdout = """5 the
3 fox
2 dog
1 at
1 away"""
[[test_cases]]
stdin = "hello hello world"
expected_stdout = """2 hello
1 world"""
[[test_cases]]
stdin = "One one ONE two TWO two Three three three three"
expected_stdout = """4 three
3 one
3 two"""