From ed56f56b0df25d7a6358188b5b845bb19d9fcd69 Mon Sep 17 00:00:00 2001 From: Jeremy Walker Date: Sat, 7 Nov 2026 17:02:28 +0900 Subject: [PATCH] Add a sign-up snippet The Exercism sign-up page shows this code sample to people who say they can code a little, to check whether they understand coding basics. The maintainers-admin team owns the file. Co-Authored-By: Claude Opus 5.5 --- .github/CODEOWNERS | 3 +++ docs/SIGN_UP_SNIPPET.txt | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 docs/SIGN_UP_SNIPPET.txt diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index ee71743c..7a9739a7 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,3 +1,6 @@ +# The code sample shown in the code check when people sign up to Exercism +docs/SIGN_UP_SNIPPET.txt @exercism/maintainers-admin + # Changes to `fetch-configlet` should be made in the `exercism/configlet` repo bin/fetch-configlet @exercism/maintainers-admin bin/fetch-configlet.ps1 @exercism/maintainers-admin diff --git a/docs/SIGN_UP_SNIPPET.txt b/docs/SIGN_UP_SNIPPET.txt new file mode 100644 index 00000000..c62d888e --- /dev/null +++ b/docs/SIGN_UP_SNIPPET.txt @@ -0,0 +1,16 @@ +fn mostCommonWord(allocator: std.mem.Allocator, text: []const u8) ![]u8 { + var counts = std.StringHashMap(u32).init(allocator); + defer counts.deinit(); + var best: []const u8 = ""; + var best_count: u32 = 0; + var words = std.mem.splitScalar(u8, text, ' '); + while (words.next()) |word| { + const count = (counts.get(word) orelse 0) + 1; + try counts.put(word, count); + if (count > best_count) { + best = word; + best_count = count; + } + } + return std.fmt.allocPrint(allocator, "\"{s}\" appears {d} times", .{ best, best_count }); +}