-
Notifications
You must be signed in to change notification settings - Fork 319
/
ch-2.raku
40 lines (34 loc) · 792 Bytes
/
ch-2.raku
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env raku
sub detox (Str $a) {
$a
andthen .trans: '."(),' => ''
andthen .subst: / <[']> s » /, '', :g
andthen .subst: / '--' /, ' ',:g
}
multi frequency-sort ( IO(Any) :$input-file! ) {
$input-file
andthen .slurp
andthen samewith $_
}
multi frequency-sort ( Str $input ) {
$input
andthen .&detox
andthen .words
andthen .Bag
andthen .sort
andthen .classify: *.value, as => *.key
}
multi MAIN () {
put frequency-sort slurp() ;
}
multi MAIN ( IO(Str) $file ) {
put frequency-sort :input-file( $file );
}
multi MAIN ( Bool :$test! ) {
use Test;
my $fs = frequency-sort :input-file<input.txt> ;
is $fs.{9}, <and the>;
is $fs.{3}, <Maria Tony a can of stop>;
is $fs.{1}.elems, 84;
done-testing;
}