raku

My Raku Scripts Collection
git clone https://fab.ddns.me.uk/stagit/raku
Log | Files | Refs | README

commit f1317fc9ab57cdbfc1df25872215d07876c7af5b
parent 7bf74b976c22fdbcab469dd8d435d32ca9bf9692
Author: masayoshi <masayoshi@example.com>
Date:   Fri, 27 Feb 2026 18:17:09 +0900

Add typing game

Diffstat:
Atyping.raku | 48++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+), 0 deletions(-)

diff --git a/typing.raku b/typing.raku @@ -0,0 +1,47 @@ +#!/usr/bin/env raku + +# 1. 単語リストの準備 +my $dict-path = "/usr/share/dict/british"; +my @words; + +if $dict-path.IO.e && $dict-path.IO.f { + # ファイルが存在する場合:5〜10文字の単語を抽出 + @words = $dict-path.IO.lines.grep({ 5 <= .chars <= 10 }); +} + +# ファイルがない、または中身が空だった場合のフォールバック +if !@words { + say "Note: Using default word list."; + @words = <raku openbsd perl terminal coding coffee apple>; +} + +# 2. ゲーム開始 +say "=== OpenBSD Typing Game ==="; +say "Words loaded: {@words.elems}"; +say "Press Enter to start (Ctrl+C to quit)..."; +get; + +my $total = 5; +my $score = 0; +my $start-time = now; + +for @words.pick($total) -> $target { + say "\n[Type this] : $target"; + print "> "; # 入力プロンプト + + my $input = get; + + if $input eq $target { + say "✨ Correct!"; + $score++; + } else { + say "❌ Wrong... (The word was: $target)"; + } +} + +# 3. 結果表示 +my $duration = now - $start-time; +say "\n" ~ "=" x 20; +say "Result: $score / $total"; +say "Time : {$duration.round(0.01)}s"; +say "=" x 20; +\ No newline at end of file