diff --git a/katas/BarcodeValidator/solutions/eu-gen/.gitattributes b/katas/BarcodeValidator/solutions/eu-gen/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/katas/BarcodeValidator/solutions/eu-gen/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/katas/BarcodeValidator/solutions/eu-gen/.gitignore b/katas/BarcodeValidator/solutions/eu-gen/.gitignore new file mode 100644 index 0000000..9491a2f --- /dev/null +++ b/katas/BarcodeValidator/solutions/eu-gen/.gitignore @@ -0,0 +1,363 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Oo]ut/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd \ No newline at end of file diff --git a/katas/BarcodeValidator/solutions/eu-gen/BarcodeValidator.sln b/katas/BarcodeValidator/solutions/eu-gen/BarcodeValidator.sln new file mode 100644 index 0000000..61ba6a5 --- /dev/null +++ b/katas/BarcodeValidator/solutions/eu-gen/BarcodeValidator.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33205.214 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BarcodeValidator", "BarcodeValidator\BarcodeValidator.csproj", "{D7D05C7A-1B3D-454C-87A2-5A0BEB961FEB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D7D05C7A-1B3D-454C-87A2-5A0BEB961FEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D7D05C7A-1B3D-454C-87A2-5A0BEB961FEB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D7D05C7A-1B3D-454C-87A2-5A0BEB961FEB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D7D05C7A-1B3D-454C-87A2-5A0BEB961FEB}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {83B1A78B-2BCD-457C-8D57-9BA825AF2F55} + EndGlobalSection +EndGlobal diff --git a/katas/BarcodeValidator/solutions/eu-gen/BarcodeValidator/BarcodeValidator.csproj b/katas/BarcodeValidator/solutions/eu-gen/BarcodeValidator/BarcodeValidator.csproj new file mode 100644 index 0000000..c446609 --- /dev/null +++ b/katas/BarcodeValidator/solutions/eu-gen/BarcodeValidator/BarcodeValidator.csproj @@ -0,0 +1,19 @@ + + + + Exe + net6.0 + enable + enable + BarcodeValidator.Program + + + + True + + + + False + + + diff --git a/katas/BarcodeValidator/solutions/eu-gen/BarcodeValidator/Program.cs b/katas/BarcodeValidator/solutions/eu-gen/BarcodeValidator/Program.cs new file mode 100644 index 0000000..593296c --- /dev/null +++ b/katas/BarcodeValidator/solutions/eu-gen/BarcodeValidator/Program.cs @@ -0,0 +1,103 @@ +using System; +using System.Numerics; + +namespace BarcodeValidator +{ class Program + { + //Liste der gültigen Barcode Längen + private static readonly List validBarcodeLengths = new() {8, 13}; + + static void Main() + { + string[] arguments = Environment.GetCommandLineArgs(); + + List validBarcodes = new(); + + if (arguments.Length > 0) + { + ValidateBarcodes(arguments, validBarcodes); + + OutputResult(validBarcodes); + }; + + Console.ReadKey(); + } + + /// + /// Übergebene Liste in Commandline ausgeben. + /// + /// Lister der gültigen Barcodes + private static void OutputResult(List validBarcodes) + { + foreach (string bc in validBarcodes) + { + Console.WriteLine(bc); + } + } + + /// + /// Übergebene Barcodes prüfen auf Länge, numerischen Inhalt und Prüfsumme + /// + /// Liste von Barcodes aus der Commandline + /// Liste der Barcodes, die als gültig befunden wurden + private static void ValidateBarcodes(string[] arguments, List validBarcodes) + { + + foreach (string barcode in arguments) + { + string bc = barcode.Trim(); + + //Länge prüfen + if (!validBarcodeLengths.Contains(bc.Length)) + { + continue; + } + + //Numerischen Inhalt prüfen + if (!Int64.TryParse(bc, out _)) + { + continue; + } + + //Prüfsummen-Validierung aufrufen + if (!ValidateChecksum(bc)) + { + continue; + } + + //Alle Prüfungen bestanden, Barcode für Ausgabe in Liste ablegen + validBarcodes.Add(bc); + + } + } + + /// + /// Prüfsummenberechnung nach 313mod10 und Vergleich der Prüfziffer + /// Vergleichsrechner z.B. https://www.gs1-germany.de/serviceverzeichnis/pruefziffernrechner/ + /// + /// zu prüfender Barcode als String + /// true, wenn Prüfziffer korrekt + private static bool ValidateChecksum(string barcode) + { + int product = 0; + char[] reversed = (char[])barcode.ToCharArray(); + Array.Reverse(reversed); + + //i = 0 überspringen, da das die vorhandene angenommene Prüfziffer ist + for (int i = 1; i < reversed.Length; i++) + { + int factor = ( i % 2 == 0) ? 1 : 3; + + product += int.Parse(reversed[i].ToString()) * factor; + } + + //Prüfziffer ist 0, wenn durch 10 teilbar, ansonsten Differenz zur nächsten 10 + int checksum = (product % 10 == 0) ? 0 : 10 - (product % 10); + + //Prüfen, ob bestehende Prüfziffer mit berechneter übereinstimmt + return (checksum == int.Parse(reversed[0].ToString())); + + } + } + +} diff --git a/katas/BarcodeValidator/solutions/eu-gen/BarcodeValidator/Properties/launchSettings.json b/katas/BarcodeValidator/solutions/eu-gen/BarcodeValidator/Properties/launchSettings.json new file mode 100644 index 0000000..10a99b7 --- /dev/null +++ b/katas/BarcodeValidator/solutions/eu-gen/BarcodeValidator/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "BarcodeValidator": { + "commandName": "Project", + "commandLineArgs": "4012345123456 \r\n4102430015329 \r\n4020753015706 \r\n70278358219069\r\n8001841920573\r\n8000500003787\r\n50001593\r\n541343\r\n9002804150203\r\n9010054115002\r\n4711471147114711\r\n5060108450515\r\n5054903836766\r\n7322540790146\r\n20515713\r\n27131336\r\n20017224\r\n27264096\r\n28170280\r\n90087066\r\n4711" + } + } +} \ No newline at end of file diff --git a/katas/LangtonAnt/solutions/eu-gen/.gitattributes b/katas/LangtonAnt/solutions/eu-gen/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/katas/LangtonAnt/solutions/eu-gen/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/katas/LangtonAnt/solutions/eu-gen/.gitignore b/katas/LangtonAnt/solutions/eu-gen/.gitignore new file mode 100644 index 0000000..9491a2f --- /dev/null +++ b/katas/LangtonAnt/solutions/eu-gen/.gitignore @@ -0,0 +1,363 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Oo]ut/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd \ No newline at end of file diff --git a/katas/LangtonAnt/solutions/eu-gen/LangtonAnt.sln b/katas/LangtonAnt/solutions/eu-gen/LangtonAnt.sln new file mode 100644 index 0000000..1b5bf35 --- /dev/null +++ b/katas/LangtonAnt/solutions/eu-gen/LangtonAnt.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33205.214 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LangtonBackend", "LangtonBackend\LangtonBackend.csproj", "{CD69938C-12A6-4498-9012-FFE8FFD4CD47}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LangtonFrontend", "LangtonFrontend\LangtonFrontend.csproj", "{16ED1C07-43CE-40A8-91B9-52DEB6C7A9BB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CD69938C-12A6-4498-9012-FFE8FFD4CD47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CD69938C-12A6-4498-9012-FFE8FFD4CD47}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CD69938C-12A6-4498-9012-FFE8FFD4CD47}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CD69938C-12A6-4498-9012-FFE8FFD4CD47}.Release|Any CPU.Build.0 = Release|Any CPU + {16ED1C07-43CE-40A8-91B9-52DEB6C7A9BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {16ED1C07-43CE-40A8-91B9-52DEB6C7A9BB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {16ED1C07-43CE-40A8-91B9-52DEB6C7A9BB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {16ED1C07-43CE-40A8-91B9-52DEB6C7A9BB}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {7FD6245F-57B5-4083-B4E3-E7FA0F798B4E} + EndGlobalSection +EndGlobal diff --git a/katas/LangtonAnt/solutions/eu-gen/LangtonBackend/Field.cs b/katas/LangtonAnt/solutions/eu-gen/LangtonBackend/Field.cs new file mode 100644 index 0000000..1386b8b --- /dev/null +++ b/katas/LangtonAnt/solutions/eu-gen/LangtonBackend/Field.cs @@ -0,0 +1,43 @@ +namespace LangtonBackend +{ + /// + /// Das gesamte Feld, auf dem sich die Ameise bewegt. + /// + internal class Field + { + Position[,] positions; + + private int _width; + private int _height; + + public int Width { get { return _width; } } + public int Height { get { return _height; } } + + public Field(int width, int height) + { + _width= width; + _height = height; + + //Feld erstellen + positions = new Position[width, height]; + + for (int x = 0; x < width; x++) + { + for (int y = 0; y < height; y++) + { + positions[x, y] = new Position( x, y, this); + } + } + } + + public Position GetPosition(int x, int y) + { + // Grenzen prüfen + if (x > _width || x < 0 || y > _height || y < 0) + { + return null; + } + return positions[x, y]; + } + } +} diff --git a/katas/LangtonAnt/solutions/eu-gen/LangtonBackend/Langton.cs b/katas/LangtonAnt/solutions/eu-gen/LangtonBackend/Langton.cs new file mode 100644 index 0000000..cb7df6b --- /dev/null +++ b/katas/LangtonAnt/solutions/eu-gen/LangtonBackend/Langton.cs @@ -0,0 +1,203 @@ +namespace LangtonBackend +{ + internal class Langton + { + //Definition: Höhe = width und Breite = width + private readonly int _width; + private readonly int _height; + + private Position _antCurrentPosition; + private Char _antDirection; + private static Field _field { get; set; } + + public Position AntCurrentPosition { get { return _antCurrentPosition; } set { _antCurrentPosition = AntCurrentPosition; } } + public Char AntDirection{ get {return _antDirection;} } + + /// + /// Hauptklasse für Langton Ant Simulator. + /// Initialisiert auch Feld und Startposition. + /// + /// Kantenlänge des Feldes + /// Startkoordinate waagrecht + /// Startkoordinate senkrecht + /// Blickrichtung zum Start + public Langton(int width, int startX, int startY, char direction ) + { + _width = width; + _height = width; + _antDirection = direction; + _antCurrentPosition = new(startX, startY); + _field = new Field(width, width); + } + + /// + /// Ant bewegen und Feld färben, Direction ermitteln und setzen + /// + internal Position Step() + { + + //Zustand vor Step + Position positionNow = _field.GetPosition(_antCurrentPosition.X , _antCurrentPosition.Y ); + bool turnLeft = positionNow.IsBlack; + Char currentDirection = _antDirection; + + //Step Actions + Char newDirection = GetNewDirection(currentDirection, turnLeft); + positionNow.IsBlack = !positionNow.IsBlack; + Move(newDirection); //_antCurrentPosition und _antDirection werden auch gesetzt + + //neue Position returnen + return _antCurrentPosition; + } + + /// + /// Je nach Richtung die X- oder Y-Koordinate ändern, + /// Blickrichtung für Ant setzen. + /// + /// + private void Move(Char direction) + { + switch (direction) + { + case 'n': + _antCurrentPosition.Y += 1; + break; + case 's': + _antCurrentPosition.Y += -1; + break; + case 'o': + _antCurrentPosition.X += 1; + break; + case 'w': + _antCurrentPosition.X += -1; + break; + } + + _antDirection= direction; + } + + /// + /// Bekomme aktuelle Richtung und Drehrichtung, returne neue Richtung + /// Richtungen: n,o,s,w + /// + /// Die aktuelle Richtung + /// true = Rotation nach links + /// + private char GetNewDirection(char currentDirection, bool turnLeft) + { + if (turnLeft) + { + switch (currentDirection) + { + case 'n': + return 'w'; + case 's': + return 'o'; + case 'o': + return 'n'; + case 'w': + return 's'; + } + } + else + { + switch (currentDirection) + { + case 'n': + return 'o'; + case 'o': + return 's'; + case 's': + return 'w'; + case 'w': + return 'n'; + } + } + + return ' '; //egtl. unreachable + } + + /// + /// Gesamtes Feld in Console ausgeben. + /// Dauert bei größeren Werten ganz schön lange, daher optional gestaltet. + /// + internal void PrintField() + { + Console.Write("("); + for (int iRow = 0; iRow < _field.Height; iRow++) + { + for (int iCol = 0; iCol < _field.Width; iCol++) + { + Position pos = _field.GetPosition(iCol, iRow); + if (pos.X == _antCurrentPosition.X && pos.Y == _antCurrentPosition.Y) + { + Console.Write(_antDirection); + } + Console.Write(_field.GetPosition(iCol, iRow).IsBlack ? "s" : "w"); + Console.Write(","); + } + Console.WriteLine(); + } + Console.WriteLine(")"); + } + + /// + /// Aktuellen Feldzustand in Datei schreiben (append) + /// Datei im Verzeichnis der Binaries mit Name Lanton[GUID].txt + /// Klammern als Begrenzungen des Feldes. + /// + /// + /// + internal async Task SaveFieldAsync(Guid guid) + { + string[] lines = new string[_field.Height]; + + for (int iRow = 0; iRow < _field.Height; iRow++) + { + string row = string.Empty; + + if (iRow == 0) { row = "("; } + + for (int iCol = 0; iCol < _field.Width; iCol++) + { + Position pos = _field.GetPosition(iCol, iRow); + if (pos.X == _antCurrentPosition.X && pos.Y == _antCurrentPosition.Y) + { + row += _antDirection; + } + row += _field.GetPosition(iCol, iRow).IsBlack ? "s" : "w"; + row += ","; + } + + if (iRow == _field.Height -1) { row += ")"; } + lines[iRow] = row; + } + + using StreamWriter file = new("Langton" + guid.ToString() + ".txt", append: true); + foreach (string line in lines) + { + await file.WriteLineAsync(line); + } + + } + + /// + /// Prüfen, ob der nächste Step die Feldgrenzen überschreiten würde + /// + /// aktuelle Position + /// + public bool CanStep() + { + if (_antCurrentPosition.X < 0 + || (_antCurrentPosition.X == 0 && _antDirection == 'w') + || _antCurrentPosition.Y < 0 + || (_antCurrentPosition.Y == this._height && _antDirection == 's') + ) + { + return false; + } + + return true; + } + } +} diff --git a/katas/LangtonAnt/solutions/eu-gen/LangtonBackend/LangtonBackend.csproj b/katas/LangtonAnt/solutions/eu-gen/LangtonBackend/LangtonBackend.csproj new file mode 100644 index 0000000..74abf5c --- /dev/null +++ b/katas/LangtonAnt/solutions/eu-gen/LangtonBackend/LangtonBackend.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/katas/LangtonAnt/solutions/eu-gen/LangtonBackend/Position.cs b/katas/LangtonAnt/solutions/eu-gen/LangtonBackend/Position.cs new file mode 100644 index 0000000..718e3a2 --- /dev/null +++ b/katas/LangtonAnt/solutions/eu-gen/LangtonBackend/Position.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LangtonBackend +{ + /// + /// Eine Position innerhalb des Feldes. + /// + internal class Position + { + public int X { get; set; } + public int Y { get; set; } + + /// + /// Default: false + /// + public bool IsBlack { get; set; } + + public Position(int x, int y) + { + X = x; + Y = y; + IsBlack= false; + } + + /// + /// Weiße Feldposition erstellen. + /// + /// + /// + /// Das "Parent" Feld der Position + public Position(int x, int y, Field field) + { + X = x; + Y = y; + IsBlack = false; + } + } +} diff --git a/katas/LangtonAnt/solutions/eu-gen/LangtonBackend/Program.cs b/katas/LangtonAnt/solutions/eu-gen/LangtonBackend/Program.cs new file mode 100644 index 0000000..b453af0 --- /dev/null +++ b/katas/LangtonAnt/solutions/eu-gen/LangtonBackend/Program.cs @@ -0,0 +1,195 @@ +namespace LangtonBackend +{ + internal class Program + { + + //notwendige Werte, müssen in Commandline übergeben werden + /// + /// Kantenlänge des Feldes + /// + private static int width; + + /// + /// Startkoordinate der Ameise waagrecht + /// + private static int startX; + + /// + /// Startkoordinate der Ameise senkrecht + /// + private static int startY; + + /// + /// Startausrichtung der Ameise + /// + private static char direction; + + /// + /// Anzahl der Schritte, die durchgeführt werden + /// + private static int steps; + + /// + /// optional: Ausgabe auch in Console, erhöht Laufzeit erheblich bei größeren Zahlen + /// + private static int printtoconsole = 0; + + static void Main(string[] args) + { + Console.WriteLine("LangtonAnt Backend started."); + + if(!InitCommandLineParameters(args)) + { + Console.WriteLine("InitCommandLineParameters failed. Parameter format example: LangtonBackend.exe width=10 x=5 y=5 direction=n steps=10"); + } + + if (!ParametersCheckValid()) + { + Console.WriteLine("ParametersCheckValid failed. Parameters contain invalid values. Parameter format example: LangtonBackend.exe width=10 x=5 y=5 direction=n steps=10"); + } + + DoLangtonAnt(); + + Console.WriteLine("LangtonAnt Backend finished. Press any key to exit."); + Console.ReadKey(); + } + + private static void DoLangtonAnt() + { + int stepsPerformed = 0; + Guid filenameGuid = Guid.NewGuid(); + Langton langton = new(width, startX, startY, direction); + + while (langton.CanStep() + && stepsPerformed < steps) + { + //Bewegung, Färbung und Rotation ausführen + langton.AntCurrentPosition = langton.Step(); + + //gesamtes Feld in Console ausgeben + if (printtoconsole == 1) + { + langton.PrintField(); + } + + //gesamtes Feld in Datei ausgeben + langton.SaveFieldAsync(filenameGuid); + + stepsPerformed++; + } + + Console.WriteLine(String.Format("Output saved to File Langton{0}.txt", filenameGuid.ToString())); + + } + + + + /// + /// Logische Prüfung der Parameter + /// + /// true, wenn alle Parameter ok sind + private static bool ParametersCheckValid() + { + if(width < 1 || startX < 1 || startY < 1 || steps < 1 || startX > width || startY > width) + { + Console.WriteLine("Parameters out of bounds."); + return false; + } + + if (!(direction != 'n' || direction != 'o' || direction != 's' || direction != 'w')) + { + Console.WriteLine("Direction parameters must be any value of (n,o,s,w)."); + return false; + } + + return true; + } + /// + /// Ccommandline Parameter auslesen und zuordnen + /// + /// + /// + private static bool InitCommandLineParameters(string[] args) + { + if (args == null) + return false; + + Console.WriteLine("InitCommandLineParameters: {0}", string.Join(", ", args)); + + Dictionary dict = new(); + + if (args.Length > 0) + { + foreach (string arg in args) + { + int ix = arg.IndexOf('='); + if (ix > 0) + dict[arg.Substring(0, ix)] = arg.Substring(ix + 1); + } + } + + if (dict.Count < 5) + { + Console.WriteLine("Invalid parameters. Example: LangtonBackend.exe width=10 x=2 y=3 direction=n steps=100"); + return false; + } + + if (dict.ContainsKey("width")) + { + int.TryParse(dict["width"], out width); + } + else + { + Console.WriteLine("Missing parameter width, example: width=10"); + return false; + } + + if (dict.ContainsKey("x")) + { + bool b = int.TryParse(dict["x"], out startX); + } + else + { + Console.WriteLine("Missing parameter x, example: x=2"); + return false; + } + + if (dict.ContainsKey("y")) + { + bool b = int.TryParse(dict["y"], out startY); + } + else + { + Console.WriteLine("Missing parameter y, example: y=3"); + return false; + } + + if (dict.ContainsKey("direction")) + { + direction = dict["direction"].ToCharArray()[0]; + } + else + { + Console.WriteLine("Missing parameter direction (n,o,s,w), example: direction=n"); + return false; + } + + if (dict.ContainsKey("steps")) + { + bool b = int.TryParse(dict["steps"], out steps); + } + else + { + Console.WriteLine("Missing parameter steps, example: steps=100"); + return false; + } + + if (dict.ContainsKey("printtoconsole")) + { + bool b = int.TryParse(dict["printtoconsole"], out printtoconsole); + } + + return true; + } + } +} \ No newline at end of file diff --git a/katas/LangtonAnt/solutions/eu-gen/LangtonBackend/Properties/launchSettings.json b/katas/LangtonAnt/solutions/eu-gen/LangtonBackend/Properties/launchSettings.json new file mode 100644 index 0000000..ea1d33f --- /dev/null +++ b/katas/LangtonAnt/solutions/eu-gen/LangtonBackend/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "LangtonBackend": { + "commandName": "Project", + "commandLineArgs": "width=10 x=5 y=5 direction=n steps=10" + } + } +} \ No newline at end of file diff --git a/katas/LangtonAnt/solutions/eu-gen/LangtonFrontend/LangtonFrontend.csproj b/katas/LangtonAnt/solutions/eu-gen/LangtonFrontend/LangtonFrontend.csproj new file mode 100644 index 0000000..74abf5c --- /dev/null +++ b/katas/LangtonAnt/solutions/eu-gen/LangtonFrontend/LangtonFrontend.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/katas/LangtonAnt/solutions/eu-gen/LangtonFrontend/Program.cs b/katas/LangtonAnt/solutions/eu-gen/LangtonFrontend/Program.cs new file mode 100644 index 0000000..2c53e03 --- /dev/null +++ b/katas/LangtonAnt/solutions/eu-gen/LangtonFrontend/Program.cs @@ -0,0 +1,104 @@ +namespace LangtonFrontend +{ + internal class Program + { + /// + /// Annahme: Erster Parameter ist Zuggeschwindigkeit in ms, zweiter Parameter ist Dateipfad + /// + /// + static void Main(string[] args) + { + if (args.Length < 2) + { + Console.WriteLine("Missing parameters. No data to process. Example LangtonFrontend.exe 1000 C:\\source\\LangtonAnt\\LangtonAnt\\LangtonBackend\\bin\\Debug\\net6.0\\Langtonb7e1a0ee-a4e6-4c0c-85e7-c7c3c8465c03.txt"); + } + + bool valid = int.TryParse( args[0], out int waittime); + if (!valid) + { + waittime = 1000; + } + + string filename = args[1]; + + if (!File.Exists(filename)) + { + Console.WriteLine("File not found. No data to process: " + filename); + } + + DoFileProcess(filename, waittime); + + } + + /// + /// Datei einlesen, im Intervall der übergebenen waittime ausgeben: + /// Kantenlänge, Startposition der Ameise, Blickrichtung der Ameise(n, o, s, w), Anzahl der Züge + /// + /// Dateiname + /// Ausgabeintervall + private static void DoFileProcess(string filename, int waittime) + { + string[] lines = File.ReadAllLines(filename); + + int fieldlength = 0; + int stepCounter = 1; + int linecounter = 0; + bool found = false; + + foreach (string line in lines) + { + string[] fieldValues = line.Split(','); + + if (stepCounter == 1) + { + fieldlength = fieldValues.Length - 1; //-1 wegen Komma am Zeilenende + } + + //Ameise in der Zeile suchen, falls noch nicht in diesem Block gefunden + if (!found) + { + int xcounter = 0; + foreach (string fieldval in fieldValues) + { + //Treffer wenn Positionsinhalt zweistellig und keine Klammer enthalten ist + if (fieldval.Length.Equals(2) && !fieldval[0].Equals('(') && !fieldval[1].Equals(')') ) + { + //Ameise gefunden + Console.WriteLine(String.Format("Step {0}: Kantenlänge: {1}, Startposition: X={2} Y={3}, Blickrichtung: {4}", + stepCounter, fieldlength, xcounter, linecounter, fieldval[0])); + found = true; + + break; + } + + xcounter++; + } + } + + if (!found) + { + linecounter++; + } + else + { + //wenn Ameise bereits gefunden, den Block Terminator suchen und ggf. resetten + if (fieldValues.Contains(")")) + { + found = false; + + //nach gefundener Ameise im nächsten Block wieder die Zeilen von 0 beginnend zählen. + linecounter = 0; + + //einen erfolgreichen Step hochzählen + stepCounter++; + + //apply waittime + Thread.Sleep(waittime); + } + } + } + + } + + } +} \ No newline at end of file diff --git a/katas/LangtonAnt/solutions/eu-gen/LangtonFrontend/Properties/launchSettings.json b/katas/LangtonAnt/solutions/eu-gen/LangtonFrontend/Properties/launchSettings.json new file mode 100644 index 0000000..351912b --- /dev/null +++ b/katas/LangtonAnt/solutions/eu-gen/LangtonFrontend/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "LangtonFrontend": { + "commandName": "Project", + "commandLineArgs": "1000 C:\\source\\LangtonAnt\\LangtonAnt\\LangtonBackend\\bin\\Debug\\net6.0\\Langton3f2bf2d1-e08c-4748-9d35-ecad1111f30d.txt" + } + } +} \ No newline at end of file