X-Git-Url: https://git.deb.at/?p=debienna.git;a=blobdiff_plain;f=Archive%2FKata4L%C3%B6sungen%2FCSharp%2Findex.mdwn;fp=Archive%2FKata4L%C3%B6sungen%2FCSharp%2Findex.mdwn;h=21d90a4342cacd95ff10d245cc99550b9c4360b1;hp=0000000000000000000000000000000000000000;hb=730888d3909be35cdad7d089b4b8b045adadd5e1;hpb=002c2ec44e7cad8ac26f85657700e703b4d923b4 diff --git "a/Archive/Kata4L\303\266sungen/CSharp/index.mdwn" "b/Archive/Kata4L\303\266sungen/CSharp/index.mdwn" new file mode 100644 index 0000000..21d90a4 --- /dev/null +++ "b/Archive/Kata4L\303\266sungen/CSharp/index.mdwn" @@ -0,0 +1,139 @@ + + +# 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]]