Raku / book

Using Raku – an unfinished book about Raku
https://perl6book.com/
284 stars 49 forks source link

Example code in Chapter 2 (Basics) produces swapped values #4

Closed baronmog closed 14 years ago

baronmog commented 14 years ago

Running the example code with the specified data produces the following output:

Ana has won 2 games and 8 sets Dave has won 2 games and 6 sets Charlie has won 1 games and 4 sets Beth has won 1 games and 4 sets

It seems that the values for won games and sets are being swapped. The following changes appear to fix the issue.

--- ttscores.pl 2010-05-28 11:14:32.000000000 -0700
+++ ttscores.pl.new     2010-05-28 11:12:02.000000000 -0700
@@ -11,13 +11,13 @@
     my ($p1, $p2)          = $pairing.split(' vs ');
     my ($r1, $r2)          = $result.split(':');

-    %sets{$p1} += $r1;
-    %sets{$p2} += $r2;
+    %games{$p1} += $r1;
+    %games{$p2} += $r2;

     if $r1 > $r2 {
-       %games{$p1}++;
+       %sets{$p1}++;
     } else {
-        %games{$p2}++;
+        %sets{$p2}++;
     }
 }
baronmog commented 14 years ago

Huh. The diff doesn't really display very well.

moritz commented 14 years ago

I've fixed the formatting of the diff by prepending 4 spaces per line... will look at the actual patch soon

moritz commented 14 years ago

It turns out the program was correct, just the terminology was confusing.

I've renamed "games" to "matches" throughout the first chapter, and hope it's less surprising now.