conerted moin to mdwn format
[debienna.git] / Kata4Lösungen / Perl / index.mdwn
index f02db6b..9e07b54 100644 (file)
-= Part 1 =\r
-\r
-{{{\r
-#!/usr/bin/perl\r
-\r
-while(<>)\r
-{\r
-        split;\r
-        next unless ($_[0] > 0 and $_[0] < 31);\r
-        $day = $_[0];\r
-        $spread = $_[1] - $_[2];\r
-        unless (defined $min_spread) \r
-        {\r
-                $spread_day = $day;\r
-                $min_spread = $spread;\r
-        }\r
-        if ($spread <= $min_spread)\r
-        {\r
-                $spread_day = $day;\r
-                $min_spread = $spread;\r
-        }\r
-}\r
-print $spread_day, "\n";\r
-}}}\r
-\r
-= Part 2 =\r
-\r
-{{{\r
-#!/usr/bin/perl\r
-\r
-while(<>)\r
-{\r
-        split;\r
-        next unless ($_[0] > 0 and $_[0] < 21);\r
-        $team = $_[1];\r
-        $spread = abs($_[6] - $_[8]);\r
-        unless (defined $min_spread)\r
-        {\r
-                $spread_team = $team;\r
-                $min_spread = $spread;\r
-        }\r
-        if ($spread <= $min_spread)\r
-        {\r
-                $spread_team = $team;\r
-                $min_spread = $spread;\r
-        }\r
-}\r
-print $spread_team, "\n";\r
-}}}\r
-\r
-= Part 3 =\r
-\r
-{{{\r
-#!/usr/bin/perl\r
-\r
-sub dm($$$$)\r
-{\r
-        my $file = shift;\r
-        my $label_col = shift;\r
-        my $alpha_col = shift;\r
-        my $beta_col = shift;\r
-\r
-        my ($spread_label, $min_spread) = ("", 100000);\r
-\r
-        open (IN, "<$file");\r
-        while(<IN>)\r
-        {\r
-                split;\r
-                next unless ($_[$alpha_col] =~ /^[0-9]+/);\r
-                next unless ($_[$beta_col] =~ /^[0-9]+/);\r
-                my $label = $_[$label_col];\r
-                my $spread = abs($_[$alpha_col] - $_[$beta_col]);\r
-                unless (defined $min_spread)\r
-                {\r
-                        print ".";\r
-                        $spread_label = $label;\r
-                        $min_spread = $spread;\r
-                }\r
-                if ($spread <= $min_spread)\r
-                {\r
-                        $spread_label = $label;\r
-                        $min_spread = $spread;\r
-                }\r
-        }\r
-        close (IN);\r
-        $spread_label;\r
-}\r
-\r
-print "part1: ", dm("../K4Weather.txt", 0, 1, 2), "\n";\r
-print "part2: ", dm("../K4Soccer.txt", 1, 6, 8), "\n";\r
-}}}\r
-----\r
-CategoryCodeSnippets
\ No newline at end of file
+
+
+# Part 1
+
+
+[[!format txt """
+#!/usr/bin/perl
+
+while(<>)
+{
+        split;
+        next unless ($_[0] > 0 and $_[0] < 31);
+        $day = $_[0];
+        $spread = $_[1] - $_[2];
+        unless (defined $min_spread) 
+        {
+                $spread_day = $day;
+                $min_spread = $spread;
+        }
+        if ($spread <= $min_spread)
+        {
+                $spread_day = $day;
+                $min_spread = $spread;
+        }
+}
+print $spread_day, "\n";
+"""]]
+
+# Part 2
+
+
+[[!format txt """
+#!/usr/bin/perl
+
+while(<>)
+{
+        split;
+        next unless ($_[0] > 0 and $_[0] < 21);
+        $team = $_[1];
+        $spread = abs($_[6] - $_[8]);
+        unless (defined $min_spread)
+        {
+                $spread_team = $team;
+                $min_spread = $spread;
+        }
+        if ($spread <= $min_spread)
+        {
+                $spread_team = $team;
+                $min_spread = $spread;
+        }
+}
+print $spread_team, "\n";
+"""]]
+
+# Part 3
+
+
+[[!format txt """
+#!/usr/bin/perl
+
+sub dm($$$$)
+{
+        my $file = shift;
+        my $label_col = shift;
+        my $alpha_col = shift;
+        my $beta_col = shift;
+
+        my ($spread_label, $min_spread) = ("", 100000);
+
+        open (IN, "<$file");
+        while(<IN>)
+        {
+                split;
+                next unless ($_[$alpha_col] =~ /^[0-9]+/);
+                next unless ($_[$beta_col] =~ /^[0-9]+/);
+                my $label = $_[$label_col];
+                my $spread = abs($_[$alpha_col] - $_[$beta_col]);
+                unless (defined $min_spread)
+                {
+                        print ".";
+                        $spread_label = $label;
+                        $min_spread = $spread;
+                }
+                if ($spread <= $min_spread)
+                {
+                        $spread_label = $label;
+                        $min_spread = $spread;
+                }
+        }
+        close (IN);
+        $spread_label;
+}
+
+print "part1: ", dm("../K4Weather.txt", 0, 1, 2), "\n";
+print "part2: ", dm("../K4Soccer.txt", 1, 6, 8), "\n";
+"""]]
+
+
+---
+
+ [[CategoryCodeSnippets|CategoryCodeSnippets]]