From f070c5d8eb4cd8a157e8342d8fcb147b55a8fc80 Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Tue, 9 Apr 2024 19:39:46 +0530 Subject: [PATCH 1/4] CC-1126: Add C# support to grep challenge. --- compiled_starters/csharp/.gitattributes | 1 + compiled_starters/csharp/.gitignore | 456 ++++++++++++++++++ compiled_starters/csharp/README.md | 39 ++ .../csharp/codecrafters-grep.csproj | 11 + .../csharp/codecrafters-grep.sln | 22 + compiled_starters/csharp/codecrafters.yml | 11 + compiled_starters/csharp/src/Program.cs | 39 ++ compiled_starters/csharp/your_grep.sh | 8 + course-definition.yml | 2 + dockerfiles/dotnet-8.0.Dockerfile | 24 + solutions/csharp/01-init/code/.gitattributes | 1 + solutions/csharp/01-init/code/.gitignore | 456 ++++++++++++++++++ solutions/csharp/01-init/code/README.md | 39 ++ .../01-init/code/codecrafters-grep.csproj | 11 + .../csharp/01-init/code/codecrafters-grep.sln | 22 + .../csharp/01-init/code/codecrafters.yml | 11 + solutions/csharp/01-init/code/src/Program.cs | 34 ++ solutions/csharp/01-init/code/your_grep.sh | 8 + .../csharp/01-init/diff/src/Program.cs.diff | 71 +++ solutions/csharp/01-init/explanation.md | 47 ++ starter-repository-definitions.yml | 22 + starter_templates/codecrafters.yml | 4 +- starter_templates/csharp/.gitignore | 456 ++++++++++++++++++ .../csharp/codecrafters-grep.csproj | 11 + .../csharp/codecrafters-grep.sln | 22 + starter_templates/csharp/src/Program.cs | 39 ++ starter_templates/csharp/your_grep.sh | 8 + 27 files changed, 1873 insertions(+), 2 deletions(-) create mode 100644 compiled_starters/csharp/.gitattributes create mode 100644 compiled_starters/csharp/.gitignore create mode 100644 compiled_starters/csharp/README.md create mode 100644 compiled_starters/csharp/codecrafters-grep.csproj create mode 100644 compiled_starters/csharp/codecrafters-grep.sln create mode 100644 compiled_starters/csharp/codecrafters.yml create mode 100644 compiled_starters/csharp/src/Program.cs create mode 100755 compiled_starters/csharp/your_grep.sh create mode 100644 dockerfiles/dotnet-8.0.Dockerfile create mode 100644 solutions/csharp/01-init/code/.gitattributes create mode 100644 solutions/csharp/01-init/code/.gitignore create mode 100644 solutions/csharp/01-init/code/README.md create mode 100644 solutions/csharp/01-init/code/codecrafters-grep.csproj create mode 100644 solutions/csharp/01-init/code/codecrafters-grep.sln create mode 100644 solutions/csharp/01-init/code/codecrafters.yml create mode 100644 solutions/csharp/01-init/code/src/Program.cs create mode 100755 solutions/csharp/01-init/code/your_grep.sh create mode 100644 solutions/csharp/01-init/diff/src/Program.cs.diff create mode 100644 solutions/csharp/01-init/explanation.md create mode 100644 starter_templates/csharp/.gitignore create mode 100644 starter_templates/csharp/codecrafters-grep.csproj create mode 100644 starter_templates/csharp/codecrafters-grep.sln create mode 100644 starter_templates/csharp/src/Program.cs create mode 100755 starter_templates/csharp/your_grep.sh diff --git a/compiled_starters/csharp/.gitattributes b/compiled_starters/csharp/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/compiled_starters/csharp/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/compiled_starters/csharp/.gitignore b/compiled_starters/csharp/.gitignore new file mode 100644 index 0000000..fc41c61 --- /dev/null +++ b/compiled_starters/csharp/.gitignore @@ -0,0 +1,456 @@ +*.db + +## 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/ +[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/ + +# Tye +.tye/ + +# 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 + +## +## Visual studio for Mac +## + + +# globs +Makefile.in +*.userprefs +*.usertasks +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.tar.gz +tarballs/ +test-results/ + +# Mac bundle stuff +*.dmg +*.app + +# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# JetBrains Rider +.idea/ +*.sln.iml + +## +## Visual Studio Code +## +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json \ No newline at end of file diff --git a/compiled_starters/csharp/README.md b/compiled_starters/csharp/README.md new file mode 100644 index 0000000..adcb3ac --- /dev/null +++ b/compiled_starters/csharp/README.md @@ -0,0 +1,39 @@ +![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/grep.png) + +This is a starting point for C# solutions to the +["Build Your Own grep" Challenge](https://app.codecrafters.io/courses/grep/overview). + +[Regular expressions](https://en.wikipedia.org/wiki/Regular_expression) +(Regexes, for short) are patterns used to match character combinations in +strings. [`grep`](https://en.wikipedia.org/wiki/Grep) is a CLI tool for +searching using Regexes. + +In this challenge you'll build your own implementation of `grep`. Along the way +we'll learn about Regex syntax, how parsers/lexers work, and how regular +expressions are evaluated. + +**Note**: If you're viewing this repo on GitHub, head over to +[codecrafters.io](https://codecrafters.io) to try the challenge. + +# Passing the first stage + +The entry point for your `grep` implementation is in `src/Program.cs`. Study and +uncomment the relevant code, and push your changes to pass the first stage: + +```sh +git add . +git commit -m "pass 1st stage" # any msg +git push origin master +``` + +Time to move on to the next stage! + +# Stage 2 & beyond + +Note: This section is for stages 2 and beyond. + +1. Ensure you have `dotnet (8.0)` installed locally +1. Run `./your_grep.sh` to run your program, which is implemented in + `src/Program.cs`. +1. Commit your changes and run `git push origin master` to submit your solution + to CodeCrafters. Test output will be streamed to your terminal. diff --git a/compiled_starters/csharp/codecrafters-grep.csproj b/compiled_starters/csharp/codecrafters-grep.csproj new file mode 100644 index 0000000..acd8b7a --- /dev/null +++ b/compiled_starters/csharp/codecrafters-grep.csproj @@ -0,0 +1,11 @@ + + + + Exe + net8.0 + codecrafters_grep + enable + enable + + + diff --git a/compiled_starters/csharp/codecrafters-grep.sln b/compiled_starters/csharp/codecrafters-grep.sln new file mode 100644 index 0000000..ef78b81 --- /dev/null +++ b/compiled_starters/csharp/codecrafters-grep.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "codecrafters-grep", "codecrafters-grep.csproj", "{5647EB94-C939-4AAF-BDC4-807AA270FCF0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/compiled_starters/csharp/codecrafters.yml b/compiled_starters/csharp/codecrafters.yml new file mode 100644 index 0000000..51be79a --- /dev/null +++ b/compiled_starters/csharp/codecrafters.yml @@ -0,0 +1,11 @@ +# Set this to true if you want debug logs. +# +# These can be VERY verbose, so we suggest turning them off +# unless you really need them. +debug: true + +# Use this to change the C# version used to run your code +# on Codecrafters. +# +# Available versions: dotnet-8.0 +language_pack: dotnet-8.0 diff --git a/compiled_starters/csharp/src/Program.cs b/compiled_starters/csharp/src/Program.cs new file mode 100644 index 0000000..8ded987 --- /dev/null +++ b/compiled_starters/csharp/src/Program.cs @@ -0,0 +1,39 @@ +using System; +using System.IO; + +// You can use print statements as follows for debugging, they'll be visible when running tests. +Console.WriteLine("Logs from your program will appear here!"); + +// Uncomment this block to pass the first stage +// +// if (args.Length < 2) +// { +// Console.WriteLine("Expected at least two arguments."); +// Environment.Exit(2); +// } +// if (args[0] != "-E") +// { +// Console.WriteLine("Expected first argument to be '-E'"); +// Environment.Exit(2); +// } +// string pattern = args[1]; +// string inputLine = Console.In.ReadToEnd(); +// if (MatchPattern(inputLine, pattern)) +// { +// Environment.Exit(0); +// } +// else +// { +// Environment.Exit(1); +// } +// static bool MatchPattern(string inputLine, string pattern) +// { +// if (pattern.Length == 1) +// { +// return inputLine.Contains(pattern); +// } +// else +// { +// throw new ArgumentException($"Unhandled pattern: {pattern}"); +// } +// } diff --git a/compiled_starters/csharp/your_grep.sh b/compiled_starters/csharp/your_grep.sh new file mode 100755 index 0000000..089eba7 --- /dev/null +++ b/compiled_starters/csharp/your_grep.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# +# DON'T EDIT THIS! +# +# CodeCrafters uses this file to test your code. Don't make any changes here! +# +# DON'T EDIT THIS! +exec dotnet run --project . --configuration Release "$@" diff --git a/course-definition.yml b/course-definition.yml index 59bdf74..e390ebf 100644 --- a/course-definition.yml +++ b/course-definition.yml @@ -26,6 +26,8 @@ languages: release_status: "alpha" alpha_tester_usernames: ["rohitpaulk", "sreeram-venkitesh"] - slug: "rust" + - slug: "csharp" + release_status: "alpha" marketing: difficulty: medium diff --git a/dockerfiles/dotnet-8.0.Dockerfile b/dockerfiles/dotnet-8.0.Dockerfile new file mode 100644 index 0000000..5e9822a --- /dev/null +++ b/dockerfiles/dotnet-8.0.Dockerfile @@ -0,0 +1,24 @@ +FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine + +COPY codecrafters-grep.csproj /app/codecrafters-grep.csproj +COPY codecrafters-grep.sln /app/codecrafters-grep.sln + +RUN mkdir /app/src +RUN (echo 'System.Console.WriteLine("If you are seeing this, there is something wrong with our caching mechanism! Please contact us at hello@codecrafters.io.");' > /app/src/Program.cs) > /dev/null + +WORKDIR /app + +# This saves nuget packages to ~/.nuget +RUN dotnet build --configuration Release . + +# Overwrite Program.cs to remove the echoed line +RUN rm /app/src/Program.cs + +# This seems to cause a caching issue with the dotnet build command, where contents from the removed /src/Program.cs are used +RUN rm -rf /app/obj +RUN rm -rf /app/bin + +RUN echo "cd \${CODECRAFTERS_SUBMISSION_DIR} && dotnet build --configuration Release ." > /codecrafters-precompile.sh +RUN chmod +x /codecrafters-precompile.sh + +ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="codecrafters-grep.csproj,codecrafters-grep.sln" diff --git a/solutions/csharp/01-init/code/.gitattributes b/solutions/csharp/01-init/code/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/solutions/csharp/01-init/code/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/solutions/csharp/01-init/code/.gitignore b/solutions/csharp/01-init/code/.gitignore new file mode 100644 index 0000000..fc41c61 --- /dev/null +++ b/solutions/csharp/01-init/code/.gitignore @@ -0,0 +1,456 @@ +*.db + +## 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/ +[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/ + +# Tye +.tye/ + +# 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 + +## +## Visual studio for Mac +## + + +# globs +Makefile.in +*.userprefs +*.usertasks +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.tar.gz +tarballs/ +test-results/ + +# Mac bundle stuff +*.dmg +*.app + +# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# JetBrains Rider +.idea/ +*.sln.iml + +## +## Visual Studio Code +## +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json \ No newline at end of file diff --git a/solutions/csharp/01-init/code/README.md b/solutions/csharp/01-init/code/README.md new file mode 100644 index 0000000..adcb3ac --- /dev/null +++ b/solutions/csharp/01-init/code/README.md @@ -0,0 +1,39 @@ +![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/grep.png) + +This is a starting point for C# solutions to the +["Build Your Own grep" Challenge](https://app.codecrafters.io/courses/grep/overview). + +[Regular expressions](https://en.wikipedia.org/wiki/Regular_expression) +(Regexes, for short) are patterns used to match character combinations in +strings. [`grep`](https://en.wikipedia.org/wiki/Grep) is a CLI tool for +searching using Regexes. + +In this challenge you'll build your own implementation of `grep`. Along the way +we'll learn about Regex syntax, how parsers/lexers work, and how regular +expressions are evaluated. + +**Note**: If you're viewing this repo on GitHub, head over to +[codecrafters.io](https://codecrafters.io) to try the challenge. + +# Passing the first stage + +The entry point for your `grep` implementation is in `src/Program.cs`. Study and +uncomment the relevant code, and push your changes to pass the first stage: + +```sh +git add . +git commit -m "pass 1st stage" # any msg +git push origin master +``` + +Time to move on to the next stage! + +# Stage 2 & beyond + +Note: This section is for stages 2 and beyond. + +1. Ensure you have `dotnet (8.0)` installed locally +1. Run `./your_grep.sh` to run your program, which is implemented in + `src/Program.cs`. +1. Commit your changes and run `git push origin master` to submit your solution + to CodeCrafters. Test output will be streamed to your terminal. diff --git a/solutions/csharp/01-init/code/codecrafters-grep.csproj b/solutions/csharp/01-init/code/codecrafters-grep.csproj new file mode 100644 index 0000000..acd8b7a --- /dev/null +++ b/solutions/csharp/01-init/code/codecrafters-grep.csproj @@ -0,0 +1,11 @@ + + + + Exe + net8.0 + codecrafters_grep + enable + enable + + + diff --git a/solutions/csharp/01-init/code/codecrafters-grep.sln b/solutions/csharp/01-init/code/codecrafters-grep.sln new file mode 100644 index 0000000..ef78b81 --- /dev/null +++ b/solutions/csharp/01-init/code/codecrafters-grep.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "codecrafters-grep", "codecrafters-grep.csproj", "{5647EB94-C939-4AAF-BDC4-807AA270FCF0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/solutions/csharp/01-init/code/codecrafters.yml b/solutions/csharp/01-init/code/codecrafters.yml new file mode 100644 index 0000000..51be79a --- /dev/null +++ b/solutions/csharp/01-init/code/codecrafters.yml @@ -0,0 +1,11 @@ +# Set this to true if you want debug logs. +# +# These can be VERY verbose, so we suggest turning them off +# unless you really need them. +debug: true + +# Use this to change the C# version used to run your code +# on Codecrafters. +# +# Available versions: dotnet-8.0 +language_pack: dotnet-8.0 diff --git a/solutions/csharp/01-init/code/src/Program.cs b/solutions/csharp/01-init/code/src/Program.cs new file mode 100644 index 0000000..38f6753 --- /dev/null +++ b/solutions/csharp/01-init/code/src/Program.cs @@ -0,0 +1,34 @@ +using System; +using System.IO; + +if (args.Length < 2) +{ + Console.WriteLine("Expected at least two arguments."); + Environment.Exit(2); +} +if (args[0] != "-E") +{ + Console.WriteLine("Expected first argument to be '-E'"); + Environment.Exit(2); +} +string pattern = args[1]; +string inputLine = Console.In.ReadToEnd(); +if (MatchPattern(inputLine, pattern)) +{ + Environment.Exit(0); +} +else +{ + Environment.Exit(1); +} +static bool MatchPattern(string inputLine, string pattern) +{ + if (pattern.Length == 1) + { + return inputLine.Contains(pattern); + } + else + { + throw new ArgumentException($"Unhandled pattern: {pattern}"); + } +} diff --git a/solutions/csharp/01-init/code/your_grep.sh b/solutions/csharp/01-init/code/your_grep.sh new file mode 100755 index 0000000..089eba7 --- /dev/null +++ b/solutions/csharp/01-init/code/your_grep.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# +# DON'T EDIT THIS! +# +# CodeCrafters uses this file to test your code. Don't make any changes here! +# +# DON'T EDIT THIS! +exec dotnet run --project . --configuration Release "$@" diff --git a/solutions/csharp/01-init/diff/src/Program.cs.diff b/solutions/csharp/01-init/diff/src/Program.cs.diff new file mode 100644 index 0000000..68184c5 --- /dev/null +++ b/solutions/csharp/01-init/diff/src/Program.cs.diff @@ -0,0 +1,71 @@ +@@ -1,39 +1,34 @@ + using System; + using System.IO; + +-// You can use print statements as follows for debugging, they'll be visible when running tests. +-Console.WriteLine("Logs from your program will appear here!"); +- +-// Uncomment this block to pass the first stage +-// +-// if (args.Length < 2) +-// { +-// Console.WriteLine("Expected at least two arguments."); +-// Environment.Exit(2); +-// } +-// if (args[0] != "-E") +-// { +-// Console.WriteLine("Expected first argument to be '-E'"); +-// Environment.Exit(2); +-// } +-// string pattern = args[1]; +-// string inputLine = Console.In.ReadToEnd(); +-// if (MatchPattern(inputLine, pattern)) +-// { +-// Environment.Exit(0); +-// } +-// else +-// { +-// Environment.Exit(1); +-// } +-// static bool MatchPattern(string inputLine, string pattern) +-// { +-// if (pattern.Length == 1) +-// { +-// return inputLine.Contains(pattern); +-// } +-// else +-// { +-// throw new ArgumentException($"Unhandled pattern: {pattern}"); +-// } +-// } ++if (args.Length < 2) ++{ ++ Console.WriteLine("Expected at least two arguments."); ++ Environment.Exit(2); ++} ++if (args[0] != "-E") ++{ ++ Console.WriteLine("Expected first argument to be '-E'"); ++ Environment.Exit(2); ++} ++string pattern = args[1]; ++string inputLine = Console.In.ReadToEnd(); ++if (MatchPattern(inputLine, pattern)) ++{ ++ Environment.Exit(0); ++} ++else ++{ ++ Environment.Exit(1); ++} ++static bool MatchPattern(string inputLine, string pattern) ++{ ++ if (pattern.Length == 1) ++ { ++ return inputLine.Contains(pattern); ++ } ++ else ++ { ++ throw new ArgumentException($"Unhandled pattern: {pattern}"); ++ } ++} diff --git a/solutions/csharp/01-init/explanation.md b/solutions/csharp/01-init/explanation.md new file mode 100644 index 0000000..6078cb9 --- /dev/null +++ b/solutions/csharp/01-init/explanation.md @@ -0,0 +1,47 @@ +The entry point for your grep implementation is in `src/Program.cs`. + +Study and uncomment the relevant code: + +```csharp +// Uncomment this block to pass the first stage + +if (args.Length < 2) +{ + Console.WriteLine("Expected at least two arguments."); + Environment.Exit(2); +} +if (args[0] != "-E") +{ + Console.WriteLine("Expected first argument to be '-E'"); + Environment.Exit(2); +} +string pattern = args[1]; +string inputLine = Console.In.ReadToEnd(); +if (MatchPattern(inputLine, pattern)) +{ + Environment.Exit(0); +} +else +{ + Environment.Exit(1); +} +static bool MatchPattern(string inputLine, string pattern) +{ + if (pattern.Length == 1) + { + return inputLine.Contains(pattern); + } + else + { + throw new ArgumentException($"Unhandled pattern: {pattern}"); + } +} +``` + +Push your changes to pass the first stage: + +``` +git add . +git commit -m "pass 1st stage" # any msg +git push origin master +``` diff --git a/starter-repository-definitions.yml b/starter-repository-definitions.yml index 0245a73..303cfb5 100644 --- a/starter-repository-definitions.yml +++ b/starter-repository-definitions.yml @@ -137,3 +137,25 @@ template_attributes: required_executable: "node (18)" user_editable_file: "app/main.js" + +- language: csharp + file_mappings: + - source: starter_templates/README.md + target: README.md + - source: starter_templates/codecrafters.yml + target: codecrafters.yml + - source: starter_templates/csharp/.gitignore + target: .gitignore + - source: starter_templates/csharp/src/Program.cs + target: src/Program.cs + - source: starter_templates/csharp/codecrafters-grep.csproj + target: codecrafters-grep.csproj + - source: starter_templates/csharp/codecrafters-grep.sln + target: codecrafters-grep.sln + - source: starter_templates/csharp/your_grep.sh + target: your_grep.sh + - source: starter_templates/.gitattributes + target: .gitattributes + template_attributes: + required_executable: "dotnet (8.0)" + user_editable_file: "src/Program.cs" diff --git a/starter_templates/codecrafters.yml b/starter_templates/codecrafters.yml index 4517604..bf64eca 100644 --- a/starter_templates/codecrafters.yml +++ b/starter_templates/codecrafters.yml @@ -68,8 +68,8 @@ language_pack: crystal-1.1 language_pack: clojure-1.10.3 {{/language_is_clojure}} {{#language_is_csharp}} -# Available versions: dotnet-6.0 -language_pack: dotnet-6.0 +# Available versions: dotnet-8.0 +language_pack: dotnet-8.0 {{/language_is_csharp}} {{#language_is_cpp}} # Available versions: cpp-20 diff --git a/starter_templates/csharp/.gitignore b/starter_templates/csharp/.gitignore new file mode 100644 index 0000000..fc41c61 --- /dev/null +++ b/starter_templates/csharp/.gitignore @@ -0,0 +1,456 @@ +*.db + +## 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/ +[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/ + +# Tye +.tye/ + +# 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 + +## +## Visual studio for Mac +## + + +# globs +Makefile.in +*.userprefs +*.usertasks +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.tar.gz +tarballs/ +test-results/ + +# Mac bundle stuff +*.dmg +*.app + +# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# JetBrains Rider +.idea/ +*.sln.iml + +## +## Visual Studio Code +## +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json \ No newline at end of file diff --git a/starter_templates/csharp/codecrafters-grep.csproj b/starter_templates/csharp/codecrafters-grep.csproj new file mode 100644 index 0000000..acd8b7a --- /dev/null +++ b/starter_templates/csharp/codecrafters-grep.csproj @@ -0,0 +1,11 @@ + + + + Exe + net8.0 + codecrafters_grep + enable + enable + + + diff --git a/starter_templates/csharp/codecrafters-grep.sln b/starter_templates/csharp/codecrafters-grep.sln new file mode 100644 index 0000000..ef78b81 --- /dev/null +++ b/starter_templates/csharp/codecrafters-grep.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "codecrafters-grep", "codecrafters-grep.csproj", "{5647EB94-C939-4AAF-BDC4-807AA270FCF0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/starter_templates/csharp/src/Program.cs b/starter_templates/csharp/src/Program.cs new file mode 100644 index 0000000..8ded987 --- /dev/null +++ b/starter_templates/csharp/src/Program.cs @@ -0,0 +1,39 @@ +using System; +using System.IO; + +// You can use print statements as follows for debugging, they'll be visible when running tests. +Console.WriteLine("Logs from your program will appear here!"); + +// Uncomment this block to pass the first stage +// +// if (args.Length < 2) +// { +// Console.WriteLine("Expected at least two arguments."); +// Environment.Exit(2); +// } +// if (args[0] != "-E") +// { +// Console.WriteLine("Expected first argument to be '-E'"); +// Environment.Exit(2); +// } +// string pattern = args[1]; +// string inputLine = Console.In.ReadToEnd(); +// if (MatchPattern(inputLine, pattern)) +// { +// Environment.Exit(0); +// } +// else +// { +// Environment.Exit(1); +// } +// static bool MatchPattern(string inputLine, string pattern) +// { +// if (pattern.Length == 1) +// { +// return inputLine.Contains(pattern); +// } +// else +// { +// throw new ArgumentException($"Unhandled pattern: {pattern}"); +// } +// } diff --git a/starter_templates/csharp/your_grep.sh b/starter_templates/csharp/your_grep.sh new file mode 100755 index 0000000..089eba7 --- /dev/null +++ b/starter_templates/csharp/your_grep.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# +# DON'T EDIT THIS! +# +# CodeCrafters uses this file to test your code. Don't make any changes here! +# +# DON'T EDIT THIS! +exec dotnet run --project . --configuration Release "$@" From 1d54f5437e26378ba7b156ce82250cf16ffe243e Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Tue, 9 Apr 2024 19:42:23 +0530 Subject: [PATCH 2/4] CC-1126: fix codecrafters.yml after compile --- compiled_starters/csharp/codecrafters.yml | 2 +- solutions/csharp/01-init/code/codecrafters.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiled_starters/csharp/codecrafters.yml b/compiled_starters/csharp/codecrafters.yml index 51be79a..80bc236 100644 --- a/compiled_starters/csharp/codecrafters.yml +++ b/compiled_starters/csharp/codecrafters.yml @@ -2,7 +2,7 @@ # # These can be VERY verbose, so we suggest turning them off # unless you really need them. -debug: true +debug: false # Use this to change the C# version used to run your code # on Codecrafters. diff --git a/solutions/csharp/01-init/code/codecrafters.yml b/solutions/csharp/01-init/code/codecrafters.yml index 51be79a..80bc236 100644 --- a/solutions/csharp/01-init/code/codecrafters.yml +++ b/solutions/csharp/01-init/code/codecrafters.yml @@ -2,7 +2,7 @@ # # These can be VERY verbose, so we suggest turning them off # unless you really need them. -debug: true +debug: false # Use this to change the C# version used to run your code # on Codecrafters. From a27b99efe2f37f24d4d207acffc3082824e4ef1e Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Tue, 9 Apr 2024 22:14:29 +0530 Subject: [PATCH 3/4] style: update C# starter_template styling. --- compiled_starters/csharp/src/Program.cs | 36 ++++------- solutions/csharp/01-init/code/src/Program.cs | 34 ++++------ .../csharp/01-init/diff/src/Program.cs.diff | 64 +++++-------------- solutions/csharp/01-init/explanation.md | 26 +------- starter_templates/csharp/src/Program.cs | 36 ++++------- 5 files changed, 55 insertions(+), 141 deletions(-) diff --git a/compiled_starters/csharp/src/Program.cs b/compiled_starters/csharp/src/Program.cs index 8ded987..5227bfd 100644 --- a/compiled_starters/csharp/src/Program.cs +++ b/compiled_starters/csharp/src/Program.cs @@ -1,39 +1,27 @@ using System; using System.IO; +static bool MatchPattern(string inputLine, string pattern) { + if (pattern.Length == 1) { + return inputLine.Contains(pattern); + } else { + throw new ArgumentException($"Unhandled pattern: {pattern}"); + } +} + // You can use print statements as follows for debugging, they'll be visible when running tests. Console.WriteLine("Logs from your program will appear here!"); // Uncomment this block to pass the first stage // -// if (args.Length < 2) -// { -// Console.WriteLine("Expected at least two arguments."); -// Environment.Exit(2); -// } -// if (args[0] != "-E") -// { +// if (args[0] != "-E") { // Console.WriteLine("Expected first argument to be '-E'"); // Environment.Exit(2); // } // string pattern = args[1]; // string inputLine = Console.In.ReadToEnd(); -// if (MatchPattern(inputLine, pattern)) -// { +// if (MatchPattern(inputLine, pattern)) { // Environment.Exit(0); -// } -// else -// { +// } else { // Environment.Exit(1); -// } -// static bool MatchPattern(string inputLine, string pattern) -// { -// if (pattern.Length == 1) -// { -// return inputLine.Contains(pattern); -// } -// else -// { -// throw new ArgumentException($"Unhandled pattern: {pattern}"); -// } -// } +// } \ No newline at end of file diff --git a/solutions/csharp/01-init/code/src/Program.cs b/solutions/csharp/01-init/code/src/Program.cs index 38f6753..11b6842 100644 --- a/solutions/csharp/01-init/code/src/Program.cs +++ b/solutions/csharp/01-init/code/src/Program.cs @@ -1,34 +1,22 @@ using System; using System.IO; -if (args.Length < 2) -{ - Console.WriteLine("Expected at least two arguments."); - Environment.Exit(2); +static bool MatchPattern(string inputLine, string pattern) { + if (pattern.Length == 1) { + return inputLine.Contains(pattern); + } else { + throw new ArgumentException($"Unhandled pattern: {pattern}"); + } } -if (args[0] != "-E") -{ + +if (args[0] != "-E") { Console.WriteLine("Expected first argument to be '-E'"); Environment.Exit(2); } string pattern = args[1]; string inputLine = Console.In.ReadToEnd(); -if (MatchPattern(inputLine, pattern)) -{ +if (MatchPattern(inputLine, pattern)) { Environment.Exit(0); -} -else -{ +} else { Environment.Exit(1); -} -static bool MatchPattern(string inputLine, string pattern) -{ - if (pattern.Length == 1) - { - return inputLine.Contains(pattern); - } - else - { - throw new ArgumentException($"Unhandled pattern: {pattern}"); - } -} +} \ No newline at end of file diff --git a/solutions/csharp/01-init/diff/src/Program.cs.diff b/solutions/csharp/01-init/diff/src/Program.cs.diff index 68184c5..910c6c8 100644 --- a/solutions/csharp/01-init/diff/src/Program.cs.diff +++ b/solutions/csharp/01-init/diff/src/Program.cs.diff @@ -1,71 +1,41 @@ -@@ -1,39 +1,34 @@ +@@ -1,27 +1,22 @@ using System; using System.IO; + static bool MatchPattern(string inputLine, string pattern) { + if (pattern.Length == 1) { + return inputLine.Contains(pattern); + } else { + throw new ArgumentException($"Unhandled pattern: {pattern}"); + } + } + -// You can use print statements as follows for debugging, they'll be visible when running tests. -Console.WriteLine("Logs from your program will appear here!"); - -// Uncomment this block to pass the first stage -// --// if (args.Length < 2) --// { --// Console.WriteLine("Expected at least two arguments."); --// Environment.Exit(2); --// } --// if (args[0] != "-E") --// { +-// if (args[0] != "-E") { -// Console.WriteLine("Expected first argument to be '-E'"); -// Environment.Exit(2); -// } -// string pattern = args[1]; -// string inputLine = Console.In.ReadToEnd(); --// if (MatchPattern(inputLine, pattern)) --// { +-// if (MatchPattern(inputLine, pattern)) { -// Environment.Exit(0); --// } --// else --// { +-// } else { -// Environment.Exit(1); -// } --// static bool MatchPattern(string inputLine, string pattern) --// { --// if (pattern.Length == 1) --// { --// return inputLine.Contains(pattern); --// } --// else --// { --// throw new ArgumentException($"Unhandled pattern: {pattern}"); --// } --// } -+if (args.Length < 2) -+{ -+ Console.WriteLine("Expected at least two arguments."); -+ Environment.Exit(2); -+} -+if (args[0] != "-E") -+{ +\ No newline at end of file ++if (args[0] != "-E") { + Console.WriteLine("Expected first argument to be '-E'"); + Environment.Exit(2); +} +string pattern = args[1]; +string inputLine = Console.In.ReadToEnd(); -+if (MatchPattern(inputLine, pattern)) -+{ ++if (MatchPattern(inputLine, pattern)) { + Environment.Exit(0); -+} -+else -+{ ++} else { + Environment.Exit(1); +} -+static bool MatchPattern(string inputLine, string pattern) -+{ -+ if (pattern.Length == 1) -+ { -+ return inputLine.Contains(pattern); -+ } -+ else -+ { -+ throw new ArgumentException($"Unhandled pattern: {pattern}"); -+ } -+} +\ No newline at end of file diff --git a/solutions/csharp/01-init/explanation.md b/solutions/csharp/01-init/explanation.md index 6078cb9..5dfb920 100644 --- a/solutions/csharp/01-init/explanation.md +++ b/solutions/csharp/01-init/explanation.md @@ -5,37 +5,17 @@ Study and uncomment the relevant code: ```csharp // Uncomment this block to pass the first stage -if (args.Length < 2) -{ - Console.WriteLine("Expected at least two arguments."); - Environment.Exit(2); -} -if (args[0] != "-E") -{ +if (args[0] != "-E") { Console.WriteLine("Expected first argument to be '-E'"); Environment.Exit(2); } string pattern = args[1]; string inputLine = Console.In.ReadToEnd(); -if (MatchPattern(inputLine, pattern)) -{ +if (MatchPattern(inputLine, pattern)) { Environment.Exit(0); -} -else -{ +} else { Environment.Exit(1); } -static bool MatchPattern(string inputLine, string pattern) -{ - if (pattern.Length == 1) - { - return inputLine.Contains(pattern); - } - else - { - throw new ArgumentException($"Unhandled pattern: {pattern}"); - } -} ``` Push your changes to pass the first stage: diff --git a/starter_templates/csharp/src/Program.cs b/starter_templates/csharp/src/Program.cs index 8ded987..5227bfd 100644 --- a/starter_templates/csharp/src/Program.cs +++ b/starter_templates/csharp/src/Program.cs @@ -1,39 +1,27 @@ using System; using System.IO; +static bool MatchPattern(string inputLine, string pattern) { + if (pattern.Length == 1) { + return inputLine.Contains(pattern); + } else { + throw new ArgumentException($"Unhandled pattern: {pattern}"); + } +} + // You can use print statements as follows for debugging, they'll be visible when running tests. Console.WriteLine("Logs from your program will appear here!"); // Uncomment this block to pass the first stage // -// if (args.Length < 2) -// { -// Console.WriteLine("Expected at least two arguments."); -// Environment.Exit(2); -// } -// if (args[0] != "-E") -// { +// if (args[0] != "-E") { // Console.WriteLine("Expected first argument to be '-E'"); // Environment.Exit(2); // } // string pattern = args[1]; // string inputLine = Console.In.ReadToEnd(); -// if (MatchPattern(inputLine, pattern)) -// { +// if (MatchPattern(inputLine, pattern)) { // Environment.Exit(0); -// } -// else -// { +// } else { // Environment.Exit(1); -// } -// static bool MatchPattern(string inputLine, string pattern) -// { -// if (pattern.Length == 1) -// { -// return inputLine.Contains(pattern); -// } -// else -// { -// throw new ArgumentException($"Unhandled pattern: {pattern}"); -// } -// } +// } \ No newline at end of file From 818e6641853da9ca56982f8cae7f47e06a7374dc Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Wed, 10 Apr 2024 15:20:20 +0530 Subject: [PATCH 4/4] style: format starter_template using `dotnet format` --- compiled_starters/csharp/src/Program.cs | 36 ++++++++----- solutions/csharp/01-init/code/src/Program.cs | 24 ++++++--- .../csharp/01-init/diff/src/Program.cs.diff | 51 ++++++++++--------- solutions/csharp/01-init/explanation.md | 13 ++--- starter_templates/csharp/src/Program.cs | 36 ++++++++----- 5 files changed, 96 insertions(+), 64 deletions(-) diff --git a/compiled_starters/csharp/src/Program.cs b/compiled_starters/csharp/src/Program.cs index 5227bfd..a973848 100644 --- a/compiled_starters/csharp/src/Program.cs +++ b/compiled_starters/csharp/src/Program.cs @@ -1,27 +1,37 @@ using System; using System.IO; -static bool MatchPattern(string inputLine, string pattern) { - if (pattern.Length == 1) { +static bool MatchPattern(string inputLine, string pattern) +{ + if (pattern.Length == 1) + { return inputLine.Contains(pattern); - } else { + } + else + { throw new ArgumentException($"Unhandled pattern: {pattern}"); } } +if (args[0] != "-E") +{ + Console.WriteLine("Expected first argument to be '-E'"); + Environment.Exit(2); +} + +string pattern = args[1]; +string inputLine = Console.In.ReadToEnd(); + // You can use print statements as follows for debugging, they'll be visible when running tests. Console.WriteLine("Logs from your program will appear here!"); // Uncomment this block to pass the first stage -// -// if (args[0] != "-E") { -// Console.WriteLine("Expected first argument to be '-E'"); -// Environment.Exit(2); -// } -// string pattern = args[1]; -// string inputLine = Console.In.ReadToEnd(); -// if (MatchPattern(inputLine, pattern)) { +// +// if (MatchPattern(inputLine, pattern)) +// { // Environment.Exit(0); -// } else { +// } +// else +// { // Environment.Exit(1); -// } \ No newline at end of file +// } diff --git a/solutions/csharp/01-init/code/src/Program.cs b/solutions/csharp/01-init/code/src/Program.cs index 11b6842..629afee 100644 --- a/solutions/csharp/01-init/code/src/Program.cs +++ b/solutions/csharp/01-init/code/src/Program.cs @@ -1,22 +1,32 @@ using System; using System.IO; -static bool MatchPattern(string inputLine, string pattern) { - if (pattern.Length == 1) { +static bool MatchPattern(string inputLine, string pattern) +{ + if (pattern.Length == 1) + { return inputLine.Contains(pattern); - } else { + } + else + { throw new ArgumentException($"Unhandled pattern: {pattern}"); } } -if (args[0] != "-E") { +if (args[0] != "-E") +{ Console.WriteLine("Expected first argument to be '-E'"); Environment.Exit(2); } + string pattern = args[1]; string inputLine = Console.In.ReadToEnd(); -if (MatchPattern(inputLine, pattern)) { + +if (MatchPattern(inputLine, pattern)) +{ Environment.Exit(0); -} else { +} +else +{ Environment.Exit(1); -} \ No newline at end of file +} diff --git a/solutions/csharp/01-init/diff/src/Program.cs.diff b/solutions/csharp/01-init/diff/src/Program.cs.diff index 910c6c8..34d9983 100644 --- a/solutions/csharp/01-init/diff/src/Program.cs.diff +++ b/solutions/csharp/01-init/diff/src/Program.cs.diff @@ -1,41 +1,46 @@ -@@ -1,27 +1,22 @@ +@@ -1,37 +1,32 @@ using System; using System.IO; - static bool MatchPattern(string inputLine, string pattern) { - if (pattern.Length == 1) { + static bool MatchPattern(string inputLine, string pattern) + { + if (pattern.Length == 1) + { return inputLine.Contains(pattern); - } else { + } + else + { throw new ArgumentException($"Unhandled pattern: {pattern}"); } } + if (args[0] != "-E") + { + Console.WriteLine("Expected first argument to be '-E'"); + Environment.Exit(2); + } + + string pattern = args[1]; + string inputLine = Console.In.ReadToEnd(); + -// You can use print statements as follows for debugging, they'll be visible when running tests. -Console.WriteLine("Logs from your program will appear here!"); - -// Uncomment this block to pass the first stage --// --// if (args[0] != "-E") { --// Console.WriteLine("Expected first argument to be '-E'"); --// Environment.Exit(2); --// } --// string pattern = args[1]; --// string inputLine = Console.In.ReadToEnd(); --// if (MatchPattern(inputLine, pattern)) { +-// +-// if (MatchPattern(inputLine, pattern)) +-// { -// Environment.Exit(0); --// } else { +-// } +-// else +-// { -// Environment.Exit(1); -// } -\ No newline at end of file -+if (args[0] != "-E") { -+ Console.WriteLine("Expected first argument to be '-E'"); -+ Environment.Exit(2); -+} -+string pattern = args[1]; -+string inputLine = Console.In.ReadToEnd(); -+if (MatchPattern(inputLine, pattern)) { ++if (MatchPattern(inputLine, pattern)) ++{ + Environment.Exit(0); -+} else { ++} ++else ++{ + Environment.Exit(1); +} -\ No newline at end of file diff --git a/solutions/csharp/01-init/explanation.md b/solutions/csharp/01-init/explanation.md index 5dfb920..7f7ff16 100644 --- a/solutions/csharp/01-init/explanation.md +++ b/solutions/csharp/01-init/explanation.md @@ -5,15 +5,12 @@ Study and uncomment the relevant code: ```csharp // Uncomment this block to pass the first stage -if (args[0] != "-E") { - Console.WriteLine("Expected first argument to be '-E'"); - Environment.Exit(2); -} -string pattern = args[1]; -string inputLine = Console.In.ReadToEnd(); -if (MatchPattern(inputLine, pattern)) { +if (MatchPattern(inputLine, pattern)) +{ Environment.Exit(0); -} else { +} +else +{ Environment.Exit(1); } ``` diff --git a/starter_templates/csharp/src/Program.cs b/starter_templates/csharp/src/Program.cs index 5227bfd..a973848 100644 --- a/starter_templates/csharp/src/Program.cs +++ b/starter_templates/csharp/src/Program.cs @@ -1,27 +1,37 @@ using System; using System.IO; -static bool MatchPattern(string inputLine, string pattern) { - if (pattern.Length == 1) { +static bool MatchPattern(string inputLine, string pattern) +{ + if (pattern.Length == 1) + { return inputLine.Contains(pattern); - } else { + } + else + { throw new ArgumentException($"Unhandled pattern: {pattern}"); } } +if (args[0] != "-E") +{ + Console.WriteLine("Expected first argument to be '-E'"); + Environment.Exit(2); +} + +string pattern = args[1]; +string inputLine = Console.In.ReadToEnd(); + // You can use print statements as follows for debugging, they'll be visible when running tests. Console.WriteLine("Logs from your program will appear here!"); // Uncomment this block to pass the first stage -// -// if (args[0] != "-E") { -// Console.WriteLine("Expected first argument to be '-E'"); -// Environment.Exit(2); -// } -// string pattern = args[1]; -// string inputLine = Console.In.ReadToEnd(); -// if (MatchPattern(inputLine, pattern)) { +// +// if (MatchPattern(inputLine, pattern)) +// { // Environment.Exit(0); -// } else { +// } +// else +// { // Environment.Exit(1); -// } \ No newline at end of file +// }