X-Git-Url: https://git.deb.at/?p=debienna.git;a=blobdiff_plain;f=Kata4L%C3%B6sungen%2FPerl%2Findex.mdwn;h=9e07b54972a4f688cc4a34fd14dd429631f8b49f;hp=f02db6be5482a7406796f5ba1eb910d9c331d055;hb=ea8c87317210d15fe425d979903108b7998ba38b;hpb=bb58b440ee60e34e1c961060195598787087c131 diff --git "a/Kata4L\303\266sungen/Perl/index.mdwn" "b/Kata4L\303\266sungen/Perl/index.mdwn" index f02db6b..9e07b54 100644 --- "a/Kata4L\303\266sungen/Perl/index.mdwn" +++ "b/Kata4L\303\266sungen/Perl/index.mdwn" @@ -1,93 +1,101 @@ -= Part 1 = - -{{{ -#!/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 = - -{{{ -#!/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 = - -{{{ -#!/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() - { - 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 \ 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() + { + 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]]