aboutsummaryrefslogtreecommitdiff
path: root/challenge-081/arne-sommer/raku/frequency-sort-postfix
blob: 1abba1e403b410a9ce16cfc36094215eca3c6db3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
#! /usr/bin/env raku

unit sub MAIN ($file where $file.IO.e && $file.IO.r = "input.txt");

my $content = $file.IO.slurp.trans(/<[."(),]>/ => ' ').subst("'s", " ", :global).subst("--", " ", :global);

my %freq = $content.words.Bag;

my @freq;

@freq[%freq{$_}] ~= $_ ~ " " for %freq.keys.sort;

say "$_ { @freq[$_] }" for @freq.keys.grep({ @freq[$_] });