Permalink
Browse files

switch to a big hash; print statistics

  • Loading branch information...
1 parent 120ab80 commit 5235a8ebb9d8c1d2102c0a9f341285706c11bb85 @moritz committed Oct 21, 2010
Showing with 24 additions and 7 deletions.
  1. +23 −6 coach.pl
  2. +1 −1 data/words-no-de
View
@@ -5,7 +5,7 @@
my $file = open $fn;
-my @words;
+my %words;
for $file.lines -> $l {
my @lang = $l.split(/\s+ '-' \s+ /);
@@ -14,10 +14,15 @@
next;
}
@lang>>.=trim;
- @words.push: @lang[0] => @lang[1];
+ 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 {
+unless %words {
die "No valid lines in data file found";
}
@@ -26,17 +31,29 @@ ($x)
=> [<aa oe ae Aa Oe Ae ae oe ue Ae Oe Ue>]);
}
+my ($right, $wrong) = 0 xx *;
loop {
- my $pair = @words.pick;
- my ($fl, $sl) = $pair.kv;
+ 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++;
}
}
View
@@ -98,4 +98,4 @@ en oppgave - Aufgabe
å svømme - schwimmen
å drikke - trinken
å vaske opp - spülen
go på fest - eine Party besuchen
på fest - eine Party besuchen

0 comments on commit 5235a8e

Please sign in to comment.