Autogram checker: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|Raku}}: Declutter sligthly. Better names. Filter out full stop (oops). Add a link to module and install command) |
Thundergnat (talk | contribs) m (→{{header|Raku}}: style tweaks) |
||
Line 96: | Line 96: | ||
for %nums.kv -> $word, $number { $str ~~ s:g/ <|w> $word <|w> /$number/ } |
for %nums.kv -> $word, $number { $str ~~ s:g/ <|w> $word <|w> /$number/ } |
||
$str ~~ s:g/ (\d)<ws>['and'|'-']<ws>(\d) /$0 $1/; |
$str ~~ s:g/ (\d)<ws>['and'|'-']<ws>(\d) /$0 $1/; |
||
$str ~~ s:g/ <|w>(\d ** 2)<ws>(\d ** 2) <|w> /{ $0 |
$str ~~ s:g/ <|w>(\d ** 2)<ws>(\d ** 2) <|w> /{ $0 × 100 + $1}/; |
||
$str ~~ s:g/ ( [\d+<ws>]* \d+ ) /{[+] $0.split: ' '}/; |
$str ~~ s:g/ ( [\d+<ws>]* \d+ ) /{[+] $0.split: ' '}/; |
||
# Build a hash of claimed characters. |
# Build a hash of claimed characters. |
||
my %claim = flat $str.lc.match(:g, /\d+ <:ws> ['comma'|'apostrophe'|'hyphen'|.]/)».split(' ')»[1,0]».pairup; |
my %claim = flat $str.lc.match(:g, /\d+ <:ws> ['comma'|'apostrophe'|'hyphen'|.]/)».split(' ')»[1,0]».pairup; |
||
for <comma , hyphen - apostrophe '> #`['] -> $ |
for <comma , hyphen - apostrophe '> #`['] -> $word, $symbol { %claim{$symbol} = %claim{$word}:delete if %claim{$word} } |
||
say "\nClaimed character counts:\n" ~ wrap-text :100width, %claim.sort( ~*.key ).map( { sprintf "%s\(%d)", .key, .value } ).join: ' '; |
say "\nClaimed character counts:\n" ~ wrap-text :100width, %claim.sort( ~*.key ).map( { sprintf "%s\(%d)", .key, .value } ).join: ' '; |
||