/
coach.pl
61 lines (51 loc) · 1.26 KB
/
coach.pl
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use v6;
my $fn = 'data/words-no-de';
my $file = open $fn;
my %words;
for $file.lines -> $l {
my @lang = $l.split(/\s+ '-' \s+ /);
if @lang != 2 {
warn "Igoring line '$l'";
next;
}
@lang>>.=trim;
if %words.exists(@lang[1]) {
warn "Ignoring second translation for @lang[1]"
~ "('@lang[0]' vs. '%words{@lang[1]}'";
} else {
%words{@lang[1]} = @lang[0];
}
}
unless %words {
die "No valid lines in data file found";
}
sub normalize($x) {
$x.trans([<å ø æ Å Ø Æ ä ö ü Ä Ö Ü>]
=> [<aa oe ae Aa Oe Ae ae oe ue Ae Oe Ue>]);
}
my ($right, $wrong) = 0 xx *;
loop {
my $sl = %words.keys.pick;
my $fl = %words{$sl};
my $response = prompt("(de) $sl = (no) ");
unless $response.defined {
say '';
say "Total: {$right + $wrong} words";
last unless $right + $wrong;
say "$right :-) or :-/";
say "$wrong :-(";
printf "%.2f%% right\n", ($right / ($right + $wrong));
last;
}
if $response eq $fl {
say ":-)";
$right++;
} elsif normalize($response) eq normalize($fl) {
say ":-/ $fl";
$right++;
} else {
say ":-( $fl";
$wrong++;
}
}
# vim: ft=perl6