X-Git-Url: https://git.deb.at/?p=debienna.git;a=blobdiff_plain;f=Kata4L%C3%B6sungen%2FCSharp%2Findex.mdwn;h=21d90a4342cacd95ff10d245cc99550b9c4360b1;hp=c728ae1d3ccd8e7e2ac654cad9381d064ec0bfa4;hb=9f6737c66ad6ff3e2482f7311cae290dd2473f0f;hpb=bb58b440ee60e34e1c961060195598787087c131 diff --git "a/Kata4L\303\266sungen/CSharp/index.mdwn" "b/Kata4L\303\266sungen/CSharp/index.mdwn" index c728ae1..21d90a4 100644 --- "a/Kata4L\303\266sungen/CSharp/index.mdwn" +++ "b/Kata4L\303\266sungen/CSharp/index.mdwn" @@ -1,135 +1,139 @@ -= Part 1 = - -{{{ -using System; -using System.IO; -using System.Text.RegularExpressions; - -namespace Kata4 -{ - class Kata4 - { - public static void Main(string[] argv) - { - FileStream fs = new FileStream("K4Weather.txt", FileMode.Open, FileAccess.Read); - StreamReader r = new StreamReader(fs); - int min_spread = Int32.MaxValue; - int spread_day = -1; - while(r.Peek() > -1) - { - string s = r.ReadLine(); - Match fields = Regex.Match(s, "^ +([0-9]+) +([0-9]+)[^ ]* *([0-9]+).*"); - try { - int day = Convert.ToInt32(fields.Groups[1].ToString()); - int min = Convert.ToInt32(fields.Groups[3].ToString()); - int max = Convert.ToInt32(fields.Groups[2].ToString()); - int spread = max - min; - if (spread <= min_spread) - { - spread_day = day; - min_spread = spread; - } - } catch { - } - } - Console.WriteLine(spread_day); - } - } -} - - -}}} - - -= Part 2 = - -{{{ -using System; -using System.IO; -using System.Text.RegularExpressions; - -namespace Kata4 -{ - class Kata4_2 - { - public static void Main(string[] argv) - { - FileStream fs = new FileStream("K4Soccer.txt", FileMode.Open, FileAccess.Read); - StreamReader r = new StreamReader(fs); - int min_spread = Int32.MaxValue; - string spread_day = ""; - while(r.Peek() > -1) - { - string s = r.ReadLine(); - Match fields = Regex.Match(s, "^ +[0-9]+\\. ([A-Za-z_]+) +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +([0-9]+) +- +([0-9]+).*"); - try { - string day = fields.Groups[1].ToString(); - Console.Write("Testing"); - Console.WriteLine(day); - int min = Convert.ToInt32(fields.Groups[2].ToString()); - int max = Convert.ToInt32(fields.Groups[3].ToString()); - int spread = Math.Abs( max - min ); - if (spread <= min_spread) - { - spread_day = day; - min_spread = spread; - } - } catch { - } - } - Console.WriteLine(spread_day); - } - } -} -}}} - -= Part 3 = - -{{{ -using System; -using System.IO; -using System.Text.RegularExpressions; - -namespace Kata4 -{ - class Kata4_2 - { - public static void Main(string[] args) - { - Console.Write("part1: "); - DM("K4Weather.txt", "^ +([0-9]+) +([0-9]+)[^ ]* *([0-9]+).*"); - Console.Write("part2: "); - DM("K4Soccer.txt", "^ +[0-9]+\\. ([A-Za-z_]+) +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +([0-9]+) +- +([0-9]+).*"); - } - - public static void DM(string file, string pattern) - { - FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read); - StreamReader r = new StreamReader(fs); - int min_spread = Int32.MaxValue; - string spread_day = ""; - while(r.Peek() > -1) - { - string s = r.ReadLine(); - Match fields = Regex.Match(s, pattern); - try { - string day = fields.Groups[1].ToString(); - int min = Convert.ToInt32(fields.Groups[2].ToString()); - int max = Convert.ToInt32(fields.Groups[3].ToString()); - int spread = Math.Abs( max - min ); - if (spread <= min_spread) - { - spread_day = day; - min_spread = spread; - } - } catch { - } - } - Console.WriteLine(spread_day); - } - } -} -}}} - ----- -CategoryCodeSnippets \ No newline at end of file + + +# Part 1 + + +[[!format txt """ +using System; +using System.IO; +using System.Text.RegularExpressions; + +namespace Kata4 +{ + class Kata4 + { + public static void Main(string[] argv) + { + FileStream fs = new FileStream("K4Weather.txt", FileMode.Open, FileAccess.Read); + StreamReader r = new StreamReader(fs); + int min_spread = Int32.MaxValue; + int spread_day = -1; + while(r.Peek() > -1) + { + string s = r.ReadLine(); + Match fields = Regex.Match(s, "^ +([0-9]+) +([0-9]+)[^ ]* *([0-9]+).*"); + try { + int day = Convert.ToInt32(fields.Groups[1].ToString()); + int min = Convert.ToInt32(fields.Groups[3].ToString()); + int max = Convert.ToInt32(fields.Groups[2].ToString()); + int spread = max - min; + if (spread <= min_spread) + { + spread_day = day; + min_spread = spread; + } + } catch { + } + } + Console.WriteLine(spread_day); + } + } +} + + +"""]] + +# Part 2 + + +[[!format txt """ +using System; +using System.IO; +using System.Text.RegularExpressions; + +namespace Kata4 +{ + class Kata4_2 + { + public static void Main(string[] argv) + { + FileStream fs = new FileStream("K4Soccer.txt", FileMode.Open, FileAccess.Read); + StreamReader r = new StreamReader(fs); + int min_spread = Int32.MaxValue; + string spread_day = ""; + while(r.Peek() > -1) + { + string s = r.ReadLine(); + Match fields = Regex.Match(s, "^ +[0-9]+\\. ([A-Za-z_]+) +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +([0-9]+) +- +([0-9]+).*"); + try { + string day = fields.Groups[1].ToString(); + Console.Write("Testing"); + Console.WriteLine(day); + int min = Convert.ToInt32(fields.Groups[2].ToString()); + int max = Convert.ToInt32(fields.Groups[3].ToString()); + int spread = Math.Abs( max - min ); + if (spread <= min_spread) + { + spread_day = day; + min_spread = spread; + } + } catch { + } + } + Console.WriteLine(spread_day); + } + } +} +"""]] + +# Part 3 + + +[[!format txt """ +using System; +using System.IO; +using System.Text.RegularExpressions; + +namespace Kata4 +{ + class Kata4_2 + { + public static void Main(string[] args) + { + Console.Write("part1: "); + DM("K4Weather.txt", "^ +([0-9]+) +([0-9]+)[^ ]* *([0-9]+).*"); + Console.Write("part2: "); + DM("K4Soccer.txt", "^ +[0-9]+\\. ([A-Za-z_]+) +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +([0-9]+) +- +([0-9]+).*"); + } + + public static void DM(string file, string pattern) + { + FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read); + StreamReader r = new StreamReader(fs); + int min_spread = Int32.MaxValue; + string spread_day = ""; + while(r.Peek() > -1) + { + string s = r.ReadLine(); + Match fields = Regex.Match(s, pattern); + try { + string day = fields.Groups[1].ToString(); + int min = Convert.ToInt32(fields.Groups[2].ToString()); + int max = Convert.ToInt32(fields.Groups[3].ToString()); + int spread = Math.Abs( max - min ); + if (spread <= min_spread) + { + spread_day = day; + min_spread = spread; + } + } catch { + } + } + Console.WriteLine(spread_day); + } + } +} +"""]] + + + [[!tag CategoryCodeSnippets]]