Permalink
Browse files

working state

  • Loading branch information...
1 parent 3937fa1 commit 525d08aacdce0cb12b32af04f97570dbdefd9415 @moritz committed Oct 22, 2010
Showing with 27 additions and 10 deletions.
  1. +27 −10 coach.pl
View
@@ -30,7 +30,7 @@
return () unless $fn.IO.e;
my $contents = slurp $fn;
my $results = from-json($contents);
- return $results.hash;
+ return $results;
}
sub save-state($fn, %state) {
@@ -70,15 +70,32 @@ ($x)
say "hade bra!";
last;
}
- if $response eq $fl {
- say ":-)";
- $right++;
- } elsif normalize($response) eq normalize($fl) {
- say ":-/ $fl";
- $right++;
- } else {
- say ":-( $fl";
- $wrong++;
+
+ unless defined %state{$sl}<answers> {
+ %state{$sl}<answers> = [];
+ }
+
+ given %state{$sl}<answers> {
+ if $response eq $fl {
+ say ":-)";
+ $right++;
+ .push: True;
+ } elsif normalize($response) eq normalize($fl) {
+ say ":-/ $fl";
+ $right++;
+ .push: True;
+ } else {
+ say ":-( $fl";
+ $wrong++;
+ .push: False;
+ }
+ if .elems > 5 {
+ .pop;
+ if all @($_) {
+ say "removing entry due to sound knowledge";
+ %words.delete($sl);
+ }
+ }
}
}

0 comments on commit 525d08a

Please sign in to comment.