├── .github └── workflows │ ├── post-diffs-in-pr.yml │ └── test.yml ├── .gitignore ├── LICENSE ├── README.md ├── compiled_starters ├── cpp │ ├── .codecrafters │ │ ├── compile.sh │ │ └── run.sh │ ├── .gitattributes │ ├── .gitignore │ ├── CMakeLists.txt │ ├── README.md │ ├── codecrafters.yml │ ├── src │ │ └── Server.cpp │ ├── vcpkg-configuration.json │ ├── vcpkg.json │ └── your_program.sh ├── csharp │ ├── .codecrafters │ │ ├── compile.sh │ │ └── run.sh │ ├── .gitattributes │ ├── .gitignore │ ├── README.md │ ├── codecrafters-grep.csproj │ ├── codecrafters-grep.sln │ ├── codecrafters.yml │ ├── src │ │ └── Program.cs │ └── your_program.sh ├── gleam │ ├── .codecrafters │ │ ├── compile.sh │ │ └── run.sh │ ├── .gitattributes │ ├── .gitignore │ ├── README.md │ ├── codecrafters.yml │ ├── gleam.toml │ ├── manifest.toml │ ├── src │ │ └── main.gleam │ └── your_program.sh ├── go │ ├── .codecrafters │ │ ├── compile.sh │ │ └── run.sh │ ├── .gitattributes │ ├── README.md │ ├── app │ │ └── main.go │ ├── codecrafters.yml │ ├── go.mod │ ├── go.sum │ └── your_program.sh ├── haskell │ ├── .codecrafters │ │ ├── compile.sh │ │ └── run.sh │ ├── .gitattributes │ ├── .gitignore │ ├── README.md │ ├── app │ │ └── Main.hs │ ├── codecrafters.yml │ ├── package.yaml │ ├── stack.yaml │ ├── stack.yaml.lock │ └── your_program.sh ├── java │ ├── .codecrafters │ │ ├── compile.sh │ │ └── run.sh │ ├── .gitattributes │ ├── .gitignore │ ├── README.md │ ├── codecrafters.yml │ ├── pom.xml │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── Main.java │ └── your_program.sh ├── javascript │ ├── .codecrafters │ │ ├── compile.sh │ │ └── run.sh │ ├── .gitattributes │ ├── .gitignore │ ├── README.md │ ├── app │ │ └── main.js │ ├── codecrafters.yml │ ├── package-lock.json │ ├── package.json │ └── your_program.sh ├── kotlin │ ├── .codecrafters │ │ ├── compile.sh │ │ └── run.sh │ ├── .gitattributes │ ├── .gitignore │ ├── README.md │ ├── codecrafters.yml │ ├── pom.xml │ ├── src │ │ └── main │ │ │ └── kotlin │ │ │ └── Main.kt │ └── your_program.sh ├── php │ ├── .codecrafters │ │ ├── compile.sh │ │ └── run.sh │ ├── .gitattributes │ ├── README.md │ ├── app │ │ └── main.php │ ├── codecrafters.yml │ └── your_program.sh ├── python │ ├── .codecrafters │ │ ├── compile.sh │ │ └── run.sh │ ├── .gitattributes │ ├── .gitignore │ ├── Pipfile │ ├── Pipfile.lock │ ├── README.md │ ├── app │ │ └── main.py │ ├── codecrafters.yml │ └── your_program.sh ├── ruby │ ├── .codecrafters │ │ ├── compile.sh │ │ └── run.sh │ ├── .gitattributes │ ├── Gemfile │ ├── Gemfile.lock │ ├── README.md │ ├── app │ │ └── main.rb │ ├── codecrafters.yml │ └── your_program.sh ├── rust │ ├── .codecrafters │ │ ├── compile.sh │ │ └── run.sh │ ├── .gitattributes │ ├── .gitignore │ ├── Cargo.lock │ ├── Cargo.toml │ ├── README.md │ ├── codecrafters.yml │ ├── src │ │ └── main.rs │ └── your_program.sh ├── typescript │ ├── .codecrafters │ │ ├── compile.sh │ │ └── run.sh │ ├── .gitattributes │ ├── .gitignore │ ├── README.md │ ├── app │ │ └── main.ts │ ├── bun.lockb │ ├── codecrafters.yml │ ├── package.json │ ├── tsconfig.json │ └── your_program.sh └── zig │ ├── .codecrafters │ ├── compile.sh │ └── run.sh │ ├── .gitattributes │ ├── .gitignore │ ├── README.md │ ├── build.zig │ ├── build.zig.zon │ ├── codecrafters.yml │ ├── src │ └── main.zig │ └── your_program.sh ├── course-definition.yml ├── dockerfiles ├── bun-1.1.Dockerfile ├── bun-1.2.Dockerfile ├── cpp-20.Dockerfile ├── cpp-23.Dockerfile ├── dotnet-8.0.Dockerfile ├── dotnet-9.0.Dockerfile ├── gleam-1.0.Dockerfile ├── gleam-1.4.Dockerfile ├── gleam-1.6.Dockerfile ├── gleam-1.9.Dockerfile ├── go-1.19.Dockerfile ├── go-1.21.Dockerfile ├── go-1.22.Dockerfile ├── go-1.24.Dockerfile ├── haskell-9.2.Dockerfile ├── haskell-9.8.Dockerfile ├── java-23.Dockerfile ├── kotlin-2.0.Dockerfile ├── nodejs-18.Dockerfile ├── nodejs-21.Dockerfile ├── php-8.4.Dockerfile ├── python-3.10.Dockerfile ├── python-3.11.Dockerfile ├── python-3.12.Dockerfile ├── python-3.13.Dockerfile ├── ruby-2.7.Dockerfile ├── ruby-3.2.Dockerfile ├── ruby-3.3.Dockerfile ├── rust-1.62.Dockerfile ├── rust-1.68.Dockerfile ├── rust-1.70.Dockerfile ├── rust-1.76.Dockerfile ├── rust-1.77.Dockerfile ├── rust-1.80.Dockerfile ├── rust-1.82.Dockerfile ├── rust-1.85.Dockerfile ├── rust-1.86.Dockerfile └── zig-0.14.Dockerfile ├── solutions ├── cpp │ └── 01-cq2 │ │ ├── code │ │ ├── .codecrafters │ │ │ ├── compile.sh │ │ │ └── run.sh │ │ ├── .gitattributes │ │ ├── .gitignore │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ ├── codecrafters.yml │ │ ├── src │ │ │ └── Server.cpp │ │ ├── vcpkg-configuration.json │ │ ├── vcpkg.json │ │ └── your_program.sh │ │ ├── diff │ │ └── src │ │ │ └── Server.cpp.diff │ │ └── explanation.md ├── csharp │ └── 01-cq2 │ │ ├── code │ │ ├── .codecrafters │ │ │ ├── compile.sh │ │ │ └── run.sh │ │ ├── .gitattributes │ │ ├── .gitignore │ │ ├── README.md │ │ ├── codecrafters-grep.csproj │ │ ├── codecrafters-grep.sln │ │ ├── codecrafters.yml │ │ ├── src │ │ │ └── Program.cs │ │ └── your_program.sh │ │ ├── diff │ │ └── src │ │ │ └── Program.cs.diff │ │ └── explanation.md ├── gleam │ └── 01-cq2 │ │ ├── code │ │ ├── .codecrafters │ │ │ ├── compile.sh │ │ │ └── run.sh │ │ ├── .gitattributes │ │ ├── .gitignore │ │ ├── README.md │ │ ├── codecrafters.yml │ │ ├── gleam.toml │ │ ├── manifest.toml │ │ ├── src │ │ │ └── main.gleam │ │ └── your_program.sh │ │ ├── diff │ │ └── src │ │ │ └── main.gleam.diff │ │ └── explanation.md ├── go │ └── 01-cq2 │ │ ├── code │ │ ├── .codecrafters │ │ │ ├── compile.sh │ │ │ └── run.sh │ │ ├── .gitattributes │ │ ├── README.md │ │ ├── app │ │ │ └── main.go │ │ ├── codecrafters.yml │ │ ├── go.mod │ │ ├── go.sum │ │ └── your_program.sh │ │ ├── diff │ │ └── app │ │ │ └── main.go.diff │ │ └── explanation.md ├── haskell │ └── 01-cq2 │ │ ├── code │ │ ├── .codecrafters │ │ │ ├── compile.sh │ │ │ └── run.sh │ │ ├── .gitattributes │ │ ├── .gitignore │ │ ├── README.md │ │ ├── app │ │ │ └── Main.hs │ │ ├── codecrafters.yml │ │ ├── package.yaml │ │ ├── stack.yaml │ │ ├── stack.yaml.lock │ │ └── your_program.sh │ │ ├── diff │ │ └── app │ │ │ └── Main.hs.diff │ │ └── explanation.md ├── java │ └── 01-cq2 │ │ ├── code │ │ ├── .codecrafters │ │ │ ├── compile.sh │ │ │ └── run.sh │ │ ├── .gitattributes │ │ ├── .gitignore │ │ ├── README.md │ │ ├── codecrafters.yml │ │ ├── pom.xml │ │ ├── src │ │ │ └── main │ │ │ │ └── java │ │ │ │ └── Main.java │ │ └── your_program.sh │ │ ├── diff │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── Main.java.diff │ │ └── explanation.md ├── javascript │ └── 01-cq2 │ │ ├── code │ │ ├── .codecrafters │ │ │ ├── compile.sh │ │ │ └── run.sh │ │ ├── .gitattributes │ │ ├── .gitignore │ │ ├── README.md │ │ ├── app │ │ │ └── main.js │ │ ├── codecrafters.yml │ │ ├── package-lock.json │ │ ├── package.json │ │ └── your_program.sh │ │ ├── diff │ │ └── app │ │ │ └── main.js.diff │ │ └── explanation.md ├── kotlin │ └── 01-cq2 │ │ ├── code │ │ ├── .codecrafters │ │ │ ├── compile.sh │ │ │ └── run.sh │ │ ├── .gitattributes │ │ ├── .gitignore │ │ ├── README.md │ │ ├── codecrafters.yml │ │ ├── pom.xml │ │ ├── src │ │ │ └── main │ │ │ │ └── kotlin │ │ │ │ └── Main.kt │ │ └── your_program.sh │ │ ├── diff │ │ └── src │ │ │ └── main │ │ │ └── kotlin │ │ │ └── Main.kt.diff │ │ └── explanation.md ├── php │ └── 01-cq2 │ │ ├── code │ │ ├── .codecrafters │ │ │ ├── compile.sh │ │ │ └── run.sh │ │ ├── .gitattributes │ │ ├── README.md │ │ ├── app │ │ │ └── main.php │ │ ├── codecrafters.yml │ │ └── your_program.sh │ │ ├── diff │ │ └── app │ │ │ └── main.php.diff │ │ └── explanation.md ├── python │ └── 01-cq2 │ │ ├── code │ │ ├── .codecrafters │ │ │ ├── compile.sh │ │ │ └── run.sh │ │ ├── .gitattributes │ │ ├── .gitignore │ │ ├── Pipfile │ │ ├── Pipfile.lock │ │ ├── README.md │ │ ├── app │ │ │ └── main.py │ │ ├── codecrafters.yml │ │ └── your_program.sh │ │ ├── diff │ │ └── app │ │ │ └── main.py.diff │ │ └── explanation.md ├── ruby │ └── 01-cq2 │ │ ├── code │ │ ├── .codecrafters │ │ │ ├── compile.sh │ │ │ └── run.sh │ │ ├── .gitattributes │ │ ├── Gemfile │ │ ├── Gemfile.lock │ │ ├── README.md │ │ ├── app │ │ │ └── main.rb │ │ ├── codecrafters.yml │ │ └── your_program.sh │ │ ├── diff │ │ └── app │ │ │ └── main.rb.diff │ │ └── explanation.md ├── rust │ └── 01-cq2 │ │ ├── code │ │ ├── .codecrafters │ │ │ ├── compile.sh │ │ │ └── run.sh │ │ ├── .gitattributes │ │ ├── .gitignore │ │ ├── Cargo.lock │ │ ├── Cargo.toml │ │ ├── README.md │ │ ├── codecrafters.yml │ │ ├── src │ │ │ └── main.rs │ │ └── your_program.sh │ │ ├── diff │ │ └── src │ │ │ └── main.rs.diff │ │ └── explanation.md ├── typescript │ └── 01-cq2 │ │ ├── code │ │ ├── .codecrafters │ │ │ ├── compile.sh │ │ │ └── run.sh │ │ ├── .gitattributes │ │ ├── .gitignore │ │ ├── README.md │ │ ├── app │ │ │ └── main.ts │ │ ├── bun.lockb │ │ ├── codecrafters.yml │ │ ├── package.json │ │ ├── tsconfig.json │ │ └── your_program.sh │ │ ├── diff │ │ └── app │ │ │ └── main.ts.diff │ │ └── explanation.md └── zig │ └── 01-cq2 │ ├── code │ ├── .codecrafters │ │ ├── compile.sh │ │ └── run.sh │ ├── .gitattributes │ ├── .gitignore │ ├── README.md │ ├── build.zig │ ├── build.zig.zon │ ├── codecrafters.yml │ ├── src │ │ └── main.zig │ └── your_program.sh │ ├── diff │ └── src │ │ └── main.zig.diff │ └── explanation.md └── starter_templates ├── all └── code │ ├── .gitattributes │ ├── README.md │ └── codecrafters.yml ├── cpp ├── code │ ├── .codecrafters │ │ ├── compile.sh │ │ └── run.sh │ ├── .gitignore │ ├── CMakeLists.txt │ ├── src │ │ └── Server.cpp │ ├── vcpkg-configuration.json │ └── vcpkg.json └── config.yml ├── csharp ├── code │ ├── .codecrafters │ │ ├── compile.sh │ │ └── run.sh │ ├── .gitignore │ ├── codecrafters-grep.csproj │ ├── codecrafters-grep.sln │ └── src │ │ └── Program.cs └── config.yml ├── gleam ├── code │ ├── .codecrafters │ │ ├── compile.sh │ │ └── run.sh │ ├── .gitignore │ ├── gleam.toml │ ├── manifest.toml │ └── src │ │ └── main.gleam └── config.yml ├── go ├── code │ ├── .codecrafters │ │ ├── compile.sh │ │ └── run.sh │ ├── app │ │ └── main.go │ ├── go.mod │ └── go.sum └── config.yml ├── haskell ├── code │ ├── .codecrafters │ │ ├── compile.sh │ │ └── run.sh │ ├── .gitignore │ ├── app │ │ └── Main.hs │ ├── package.yaml │ ├── stack.yaml │ └── stack.yaml.lock └── config.yml ├── java ├── code │ ├── .codecrafters │ │ ├── compile.sh │ │ └── run.sh │ ├── .gitignore │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── Main.java └── config.yml ├── javascript ├── code │ ├── .codecrafters │ │ ├── compile.sh │ │ └── run.sh │ ├── .gitignore │ ├── app │ │ └── main.js │ ├── package-lock.json │ └── package.json └── config.yml ├── kotlin ├── code │ ├── .codecrafters │ │ ├── compile.sh │ │ └── run.sh │ ├── .gitignore │ ├── pom.xml │ └── src │ │ └── main │ │ └── kotlin │ │ └── Main.kt └── config.yml ├── php ├── code │ ├── .codecrafters │ │ ├── compile.sh │ │ └── run.sh │ └── app │ │ └── main.php └── config.yml ├── python ├── code │ ├── .codecrafters │ │ ├── compile.sh │ │ └── run.sh │ ├── .gitignore │ ├── Pipfile │ ├── Pipfile.lock │ └── app │ │ └── main.py └── config.yml ├── ruby ├── code │ ├── .codecrafters │ │ ├── compile.sh │ │ └── run.sh │ ├── Gemfile │ ├── Gemfile.lock │ └── app │ │ └── main.rb └── config.yml ├── rust ├── code │ ├── .codecrafters │ │ ├── compile.sh │ │ └── run.sh │ ├── .gitignore │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ └── main.rs └── config.yml ├── typescript ├── code │ ├── .codecrafters │ │ ├── compile.sh │ │ └── run.sh │ ├── .gitignore │ ├── app │ │ └── main.ts │ ├── bun.lockb │ ├── package.json │ └── tsconfig.json └── config.yml └── zig ├── code ├── .codecrafters │ ├── compile.sh │ └── run.sh ├── .gitignore ├── build.zig ├── build.zig.zon └── src │ └── main.zig └── config.yml /.github/workflows/post-diffs-in-pr.yml: -------------------------------------------------------------------------------- 1 | name: Post diffs 2 | 3 | on: 4 | pull_request: 5 | 6 | concurrency: 7 | group: ${{ github.workflow }}-${{ github.ref }} 8 | cancel-in-progress: true 9 | 10 | jobs: 11 | post_diffs: 12 | uses: codecrafters-io/course-sdk/.github/workflows/post-diffs-in-pr.yml@main 13 | with: 14 | sdkRef: main 15 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: [main] 7 | 8 | concurrency: 9 | group: ${{ github.workflow }}-${{ github.ref }} 10 | cancel-in-progress: true 11 | 12 | jobs: 13 | test_course_definition: 14 | uses: codecrafters-io/course-sdk/.github/workflows/test-course-definition.yml@main 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | course-definition-tester 2 | .history/ 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 CodeCrafters 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # build-your-own-grep 2 | 3 | Content for the "Build your own Grep" challenge 4 | 5 | ### Setup 6 | 7 | This challenge is developed using https://github.com/codecrafters-io/course-sdk. Read the README there for information 8 | on how to contribute language support & submit solutions. -------------------------------------------------------------------------------- /compiled_starters/cpp/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake 12 | cmake --build ./build 13 | -------------------------------------------------------------------------------- /compiled_starters/cpp/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec ./build/exe "$@" 12 | -------------------------------------------------------------------------------- /compiled_starters/cpp/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /compiled_starters/cpp/.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | server 34 | 35 | # CMake 36 | CMakeLists.txt.user 37 | CMakeCache.txt 38 | CMakeFiles 39 | CMakeScripts 40 | Testing 41 | Makefile 42 | cmake_install.cmake 43 | install_manifest.txt 44 | compile_commands.json 45 | CTestTestfile.cmake 46 | _deps 47 | 48 | build/ 49 | vcpkg_installed -------------------------------------------------------------------------------- /compiled_starters/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | project(grep-starter-cpp) 4 | 5 | set(CMAKE_CXX_STANDARD 23) # Enable the C++23 standard 6 | 7 | file(GLOB_RECURSE SOURCE_FILES src/*.cpp src/*.hpp) 8 | 9 | add_executable(exe ${SOURCE_FILES}) -------------------------------------------------------------------------------- /compiled_starters/cpp/codecrafters.yml: -------------------------------------------------------------------------------- 1 | # Set this to true if you want debug logs. 2 | # 3 | # These can be VERY verbose, so we suggest turning them off 4 | # unless you really need them. 5 | debug: false 6 | 7 | # Use this to change the C++ version used to run your code 8 | # on Codecrafters. 9 | # 10 | # Available versions: cpp-23 11 | language_pack: cpp-23 12 | -------------------------------------------------------------------------------- /compiled_starters/cpp/vcpkg-configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "default-registry": { 3 | "kind": "git", 4 | "baseline": "c4af3593e1f1aa9e14a560a09e45ea2cb0dfd74d", 5 | "repository": "https://github.com/microsoft/vcpkg" 6 | }, 7 | "registries": [ 8 | { 9 | "kind": "artifact", 10 | "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip", 11 | "name": "microsoft" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /compiled_starters/cpp/vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": [] 3 | } -------------------------------------------------------------------------------- /compiled_starters/cpp/your_program.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Use this script to run your program LOCALLY. 4 | # 5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program. 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit early if any commands fail 10 | 11 | # Copied from .codecrafters/compile.sh 12 | # 13 | # - Edit this to change how your program compiles locally 14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely 15 | ( 16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory 17 | cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake 18 | cmake --build ./build 19 | ) 20 | 21 | # Copied from .codecrafters/run.sh 22 | # 23 | # - Edit this to change how your program runs locally 24 | # - Edit .codecrafters/run.sh to change how your program runs remotely 25 | exec ./build/exe "$@" 26 | -------------------------------------------------------------------------------- /compiled_starters/csharp/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | dotnet build --configuration Release --output /tmp/codecrafters-build-grep-csharp codecrafters-grep.csproj 12 | -------------------------------------------------------------------------------- /compiled_starters/csharp/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec /tmp/codecrafters-build-grep-csharp/codecrafters-grep "$@" -------------------------------------------------------------------------------- /compiled_starters/csharp/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /compiled_starters/csharp/codecrafters-grep.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | codecrafters_grep 7 | enable 8 | enable 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /compiled_starters/csharp/codecrafters-grep.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.31903.59 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "codecrafters-grep", "codecrafters-grep.csproj", "{5647EB94-C939-4AAF-BDC4-807AA270FCF0}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(SolutionProperties) = preSolution 14 | HideSolutionNode = FALSE 15 | EndGlobalSection 16 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 17 | {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 18 | {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Debug|Any CPU.Build.0 = Debug|Any CPU 19 | {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Release|Any CPU.ActiveCfg = Release|Any CPU 20 | {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Release|Any CPU.Build.0 = Release|Any CPU 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /compiled_starters/csharp/codecrafters.yml: -------------------------------------------------------------------------------- 1 | # Set this to true if you want debug logs. 2 | # 3 | # These can be VERY verbose, so we suggest turning them off 4 | # unless you really need them. 5 | debug: false 6 | 7 | # Use this to change the C# version used to run your code 8 | # on Codecrafters. 9 | # 10 | # Available versions: dotnet-9.0 11 | language_pack: dotnet-9.0 12 | -------------------------------------------------------------------------------- /compiled_starters/csharp/src/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | static bool MatchPattern(string inputLine, string pattern) 5 | { 6 | if (pattern.Length == 1) 7 | { 8 | return inputLine.Contains(pattern); 9 | } 10 | else 11 | { 12 | throw new ArgumentException($"Unhandled pattern: {pattern}"); 13 | } 14 | } 15 | 16 | if (args[0] != "-E") 17 | { 18 | Console.WriteLine("Expected first argument to be '-E'"); 19 | Environment.Exit(2); 20 | } 21 | 22 | string pattern = args[1]; 23 | string inputLine = Console.In.ReadToEnd(); 24 | 25 | // You can use print statements as follows for debugging, they'll be visible when running tests. 26 | Console.Error.WriteLine("Logs from your program will appear here!"); 27 | 28 | // Uncomment this block to pass the first stage 29 | // 30 | // if (MatchPattern(inputLine, pattern)) 31 | // { 32 | // Environment.Exit(0); 33 | // } 34 | // else 35 | // { 36 | // Environment.Exit(1); 37 | // } 38 | -------------------------------------------------------------------------------- /compiled_starters/csharp/your_program.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Use this script to run your program LOCALLY. 4 | # 5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program. 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit early if any commands fail 10 | 11 | # Copied from .codecrafters/compile.sh 12 | # 13 | # - Edit this to change how your program compiles locally 14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely 15 | ( 16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory 17 | dotnet build --configuration Release --output /tmp/codecrafters-build-grep-csharp codecrafters-grep.csproj 18 | ) 19 | 20 | # Copied from .codecrafters/run.sh 21 | # 22 | # - Edit this to change how your program runs locally 23 | # - Edit .codecrafters/run.sh to change how your program runs remotely 24 | exec /tmp/codecrafters-build-grep-csharp/codecrafters-grep "$@" 25 | -------------------------------------------------------------------------------- /compiled_starters/gleam/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | gleam build 12 | -------------------------------------------------------------------------------- /compiled_starters/gleam/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec gleam run --module main -- "$@" 12 | -------------------------------------------------------------------------------- /compiled_starters/gleam/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /compiled_starters/gleam/.gitignore: -------------------------------------------------------------------------------- 1 | *.beam 2 | *.ez 3 | /build 4 | erl_crash.dump 5 | -------------------------------------------------------------------------------- /compiled_starters/gleam/codecrafters.yml: -------------------------------------------------------------------------------- 1 | # Set this to true if you want debug logs. 2 | # 3 | # These can be VERY verbose, so we suggest turning them off 4 | # unless you really need them. 5 | debug: false 6 | 7 | # Use this to change the Gleam version used to run your code 8 | # on Codecrafters. 9 | # 10 | # Available versions: gleam-1.9 11 | language_pack: gleam-1.9 12 | -------------------------------------------------------------------------------- /compiled_starters/gleam/gleam.toml: -------------------------------------------------------------------------------- 1 | name = "codecrafters_grep" 2 | version = "1.0.0" 3 | 4 | # For a full reference of all the available options, you can have a look at 5 | # https://gleam.run/writing-gleam/gleam-toml/. 6 | 7 | [dependencies] 8 | argv = ">= 1.0.2 and < 2.0.0" 9 | gleam_erlang = "~> 0.25" 10 | gleam_stdlib = "~> 0.34 or ~> 1.0" 11 | 12 | [dev-dependencies] 13 | gleeunit = "~> 1.0" -------------------------------------------------------------------------------- /compiled_starters/gleam/manifest.toml: -------------------------------------------------------------------------------- 1 | # This file was generated by Gleam 2 | # You typically do not need to edit this file 3 | 4 | packages = [ 5 | { name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" }, 6 | { name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" }, 7 | { name = "gleam_stdlib", version = "0.38.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "663CF11861179AF415A625307447775C09404E752FF99A24E2057C835319F1BE" }, 8 | { name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" }, 9 | ] 10 | 11 | [requirements] 12 | argv = { version = ">= 1.0.2 and < 2.0.0" } 13 | gleam_erlang = { version = "~> 0.25" } 14 | gleam_stdlib = { version = "~> 0.34 or ~> 1.0" } 15 | gleeunit = { version = "~> 1.0" } 16 | -------------------------------------------------------------------------------- /compiled_starters/gleam/src/main.gleam: -------------------------------------------------------------------------------- 1 | import argv 2 | import gleam/erlang 3 | import gleam/io 4 | import gleam/string 5 | 6 | pub fn main() { 7 | // You can use print statements as follows for debugging, they'll be visible when running tests. 8 | io.print_error("Logs from your program will appear here!") 9 | 10 | let args = argv.load().arguments 11 | let assert Ok(input_line) = erlang.get_line("") 12 | 13 | // Uncomment this to pass the first stage 14 | // case args { 15 | // ["-E", pattern, ..] -> { 16 | // case match_pattern(input_line, pattern) { 17 | // True -> exit(0) 18 | // False -> exit(1) 19 | // } 20 | // } 21 | // _ -> { 22 | // io.println("Expected first argument to be '-E'") 23 | // exit(1) 24 | // } 25 | // } 26 | } 27 | 28 | fn match_pattern(input_line: String, pattern: String) -> Bool { 29 | case string.length(pattern) { 30 | 1 -> string.contains(input_line, pattern) 31 | _ -> { 32 | io.println("Unhandled pattern: " <> pattern) 33 | False 34 | } 35 | } 36 | } 37 | 38 | @external(erlang, "erlang", "halt") 39 | pub fn exit(code: Int) -> Int 40 | -------------------------------------------------------------------------------- /compiled_starters/gleam/your_program.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Use this script to run your program LOCALLY. 4 | # 5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program. 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit early if any commands fail 10 | 11 | # Copied from .codecrafters/compile.sh 12 | # 13 | # - Edit this to change how your program compiles locally 14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely 15 | ( 16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory 17 | gleam build 18 | ) 19 | 20 | # Copied from .codecrafters/run.sh 21 | # 22 | # - Edit this to change how your program runs locally 23 | # - Edit .codecrafters/run.sh to change how your program runs remotely 24 | exec gleam run --module main -- "$@" 25 | -------------------------------------------------------------------------------- /compiled_starters/go/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | go build -o /tmp/codecrafters-build-grep-go app/*.go 12 | -------------------------------------------------------------------------------- /compiled_starters/go/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec /tmp/codecrafters-build-grep-go "$@" 12 | -------------------------------------------------------------------------------- /compiled_starters/go/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /compiled_starters/go/codecrafters.yml: -------------------------------------------------------------------------------- 1 | # Set this to true if you want debug logs. 2 | # 3 | # These can be VERY verbose, so we suggest turning them off 4 | # unless you really need them. 5 | debug: false 6 | 7 | # Use this to change the Go version used to run your code 8 | # on Codecrafters. 9 | # 10 | # Available versions: go-1.24 11 | language_pack: go-1.24 12 | -------------------------------------------------------------------------------- /compiled_starters/go/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/codecrafters-io/grep-starter-go 2 | 3 | go 1.24.0 4 | -------------------------------------------------------------------------------- /compiled_starters/go/go.sum: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codecrafters-io/build-your-own-grep/05cb8cdb45b2e3f0b39762f7077146c0f3ff32d7/compiled_starters/go/go.sum -------------------------------------------------------------------------------- /compiled_starters/go/your_program.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Use this script to run your program LOCALLY. 4 | # 5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program. 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit early if any commands fail 10 | 11 | # Copied from .codecrafters/compile.sh 12 | # 13 | # - Edit this to change how your program compiles locally 14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely 15 | ( 16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory 17 | go build -o /tmp/codecrafters-build-grep-go app/*.go 18 | ) 19 | 20 | # Copied from .codecrafters/run.sh 21 | # 22 | # - Edit this to change how your program runs locally 23 | # - Edit .codecrafters/run.sh to change how your program runs remotely 24 | exec /tmp/codecrafters-build-grep-go "$@" 25 | -------------------------------------------------------------------------------- /compiled_starters/haskell/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | # This compiles the program into $(stack path --local-install-root)/bin/codecrafters-grep-exe. 12 | stack build 13 | -------------------------------------------------------------------------------- /compiled_starters/haskell/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec $(stack path --local-install-root)/bin/codecrafters-grep-exe "$@" -------------------------------------------------------------------------------- /compiled_starters/haskell/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /compiled_starters/haskell/.gitignore: -------------------------------------------------------------------------------- 1 | codecrafters-grep.cabal 2 | *~ 3 | dist 4 | dist-* 5 | cabal-dev 6 | *.o 7 | *.hi 8 | *.hie 9 | *.chi 10 | *.chs.h 11 | *.dyn_o 12 | *.dyn_hi 13 | .hpc 14 | .hsenv 15 | .cabal-sandbox/ 16 | cabal.sandbox.config 17 | *.prof 18 | *.aux 19 | *.hp 20 | *.eventlog 21 | .stack/ 22 | .stack-work/ 23 | cabal.project.local 24 | cabal.project.local~ 25 | .HTF/ 26 | .ghc.environment.* -------------------------------------------------------------------------------- /compiled_starters/haskell/app/Main.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import System.Environment 4 | import System.Exit 5 | import System.IO (hPutStrLn, hSetBuffering, stdout, stderr, BufferMode (NoBuffering)) 6 | 7 | matchPattern :: String -> String -> Bool 8 | matchPattern pattern input = do 9 | if length pattern == 1 10 | then head pattern `elem` input 11 | else error $ "Unhandled pattern: " ++ pattern 12 | 13 | main :: IO () 14 | main = do 15 | -- Disable output buffering 16 | hSetBuffering stdout NoBuffering 17 | hSetBuffering stderr NoBuffering 18 | 19 | args <- getArgs 20 | let pattern = args !! 1 21 | input_line <- getLine 22 | 23 | -- You can use print statements as follows for debugging, they'll be visible when running tests. 24 | hPutStrLn stderr "Logs from your program will appear here" 25 | 26 | -- Uncomment this block to pass stage 1 27 | -- if head args /= "-E" 28 | -- then do 29 | -- putStrLn "Expected first argument to be '-E'" 30 | -- exitFailure 31 | -- else do if matchPattern pattern input_line 32 | -- then exitSuccess 33 | -- else exitFailure 34 | -------------------------------------------------------------------------------- /compiled_starters/haskell/codecrafters.yml: -------------------------------------------------------------------------------- 1 | # Set this to true if you want debug logs. 2 | # 3 | # These can be VERY verbose, so we suggest turning them off 4 | # unless you really need them. 5 | debug: false 6 | 7 | # Use this to change the Haskell version used to run your code 8 | # on Codecrafters. 9 | # 10 | # Available versions: haskell-9.8 11 | language_pack: haskell-9.8 12 | -------------------------------------------------------------------------------- /compiled_starters/haskell/package.yaml: -------------------------------------------------------------------------------- 1 | name: codecrafters-grep 2 | version: 0.1.0.0 3 | license: BSD3 4 | 5 | dependencies: 6 | - base >= 4.19 && < 5 7 | - megaparsec # can help when implementing the parser 8 | - parser-combinators # extends megaparsec 9 | - containers # Set, Map, Seq 10 | - unordered-containers # HashSet, HashMap 11 | - hashable # when using your own data types with unordered-containers 12 | - mtl # monad transformers to help with nested monads 13 | 14 | default-extensions: 15 | - BlockArguments 16 | - ImportQualifiedPost 17 | - LambdaCase 18 | - NamedFieldPuns 19 | - RecordWildCards 20 | 21 | executables: 22 | codecrafters-grep-exe: 23 | main: Main.hs 24 | source-dirs: app 25 | ghc-options: 26 | - -threaded 27 | - -rtsopts 28 | - -with-rtsopts=-N 29 | -------------------------------------------------------------------------------- /compiled_starters/haskell/stack.yaml: -------------------------------------------------------------------------------- 1 | resolver: lts-23.18 2 | 3 | packages: 4 | - . 5 | -------------------------------------------------------------------------------- /compiled_starters/haskell/stack.yaml.lock: -------------------------------------------------------------------------------- 1 | # This file was autogenerated by Stack. 2 | # You should not edit this file by hand. 3 | # For more information, please see the documentation at: 4 | # https://docs.haskellstack.org/en/stable/lock_files 5 | 6 | packages: [] 7 | snapshots: 8 | - completed: 9 | sha256: d133abe75e408a407cce3f032c96ac1bbadf474a93b5156ebf4135b53382d56b 10 | size: 683827 11 | url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/23/18.yaml 12 | original: lts-23.18 13 | -------------------------------------------------------------------------------- /compiled_starters/haskell/your_program.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Use this script to run your program LOCALLY. 4 | # 5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program. 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit early if any commands fail 10 | 11 | # Copied from .codecrafters/compile.sh 12 | # 13 | # - Edit this to change how your program compiles locally 14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely 15 | ( 16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory 17 | stack build 18 | ) 19 | 20 | # Copied from .codecrafters/run.sh 21 | # 22 | # - Edit this to change how your program runs locally 23 | # - Edit .codecrafters/run.sh to change how your program runs remotely 24 | exec $(stack path --local-install-root)/bin/codecrafters-grep-exe "$@" 25 | -------------------------------------------------------------------------------- /compiled_starters/java/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | mvn -B package -Ddir=/tmp/codecrafters-build-grep-java 12 | -------------------------------------------------------------------------------- /compiled_starters/java/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec java -jar /tmp/codecrafters-build-grep-java/codecrafters-grep.jar "$@" 12 | -------------------------------------------------------------------------------- /compiled_starters/java/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /compiled_starters/java/.gitignore: -------------------------------------------------------------------------------- 1 | *.jar 2 | target/ 3 | .idea/ 4 | -------------------------------------------------------------------------------- /compiled_starters/java/codecrafters.yml: -------------------------------------------------------------------------------- 1 | # Set this to true if you want debug logs. 2 | # 3 | # These can be VERY verbose, so we suggest turning them off 4 | # unless you really need them. 5 | debug: false 6 | 7 | # Use this to change the Java version used to run your code 8 | # on Codecrafters. 9 | # 10 | # Available versions: java-23 11 | language_pack: java-23 12 | -------------------------------------------------------------------------------- /compiled_starters/java/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | import java.io.IOException; 2 | import java.util.Scanner; 3 | 4 | public class Main { 5 | public static void main(String[] args){ 6 | if (args.length != 2 || !args[0].equals("-E")) { 7 | System.out.println("Usage: ./your_program.sh -E "); 8 | System.exit(1); 9 | } 10 | 11 | String pattern = args[1]; 12 | Scanner scanner = new Scanner(System.in); 13 | String inputLine = scanner.nextLine(); 14 | 15 | // You can use print statements as follows for debugging, they'll be visible when running tests. 16 | System.err.println("Logs from your program will appear here!"); 17 | 18 | // Uncomment this block to pass the first stage 19 | // 20 | // if (matchPattern(inputLine, pattern)) { 21 | // System.exit(0); 22 | // } else { 23 | // System.exit(1); 24 | // } 25 | } 26 | 27 | public static boolean matchPattern(String inputLine, String pattern) { 28 | if (pattern.length() == 1) { 29 | return inputLine.contains(pattern); 30 | } else { 31 | throw new RuntimeException("Unhandled pattern: " + pattern); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /compiled_starters/java/your_program.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Use this script to run your program LOCALLY. 4 | # 5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program. 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit early if any commands fail 10 | 11 | # Copied from .codecrafters/compile.sh 12 | # 13 | # - Edit this to change how your program compiles locally 14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely 15 | ( 16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory 17 | mvn -B package -Ddir=/tmp/codecrafters-build-grep-java 18 | ) 19 | 20 | # Copied from .codecrafters/run.sh 21 | # 22 | # - Edit this to change how your program runs locally 23 | # - Edit .codecrafters/run.sh to change how your program runs remotely 24 | exec java -jar /tmp/codecrafters-build-grep-java/codecrafters-grep.jar "$@" 25 | -------------------------------------------------------------------------------- /compiled_starters/javascript/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | # (This file is empty since JavaScript programs don't use a compile step) 12 | -------------------------------------------------------------------------------- /compiled_starters/javascript/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec node app/main.js "$@" 12 | -------------------------------------------------------------------------------- /compiled_starters/javascript/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /compiled_starters/javascript/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /compiled_starters/javascript/app/main.js: -------------------------------------------------------------------------------- 1 | function matchPattern(inputLine, pattern) { 2 | if (pattern.length === 1) { 3 | return inputLine.includes(pattern); 4 | } else { 5 | throw new Error(`Unhandled pattern ${pattern}`); 6 | } 7 | } 8 | 9 | function main() { 10 | const pattern = process.argv[3]; 11 | const inputLine = require("fs").readFileSync(0, "utf-8").trim(); 12 | 13 | if (process.argv[2] !== "-E") { 14 | console.log("Expected first argument to be '-E'"); 15 | process.exit(1); 16 | } 17 | 18 | // You can use print statements as follows for debugging, they'll be visible when running tests. 19 | console.error("Logs from your program will appear here"); 20 | 21 | // Uncomment this block to pass the first stage 22 | // if (matchPattern(inputLine, pattern)) { 23 | // process.exit(0); 24 | // } else { 25 | // process.exit(1); 26 | // } 27 | } 28 | 29 | main(); 30 | -------------------------------------------------------------------------------- /compiled_starters/javascript/codecrafters.yml: -------------------------------------------------------------------------------- 1 | # Set this to true if you want debug logs. 2 | # 3 | # These can be VERY verbose, so we suggest turning them off 4 | # unless you really need them. 5 | debug: false 6 | 7 | # Use this to change the JavaScript version used to run your code 8 | # on Codecrafters. 9 | # 10 | # Available versions: nodejs-21 11 | language_pack: nodejs-21 12 | -------------------------------------------------------------------------------- /compiled_starters/javascript/package-lock.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "name": "@codecrafters/build-your-own-grep", 4 | "version": "1.0.0", 5 | "lockfileVersion": 3, 6 | "requires": true, 7 | "packages": { 8 | "": { 9 | "name": "@codecrafters/build-your-own-grep", 10 | "version": "1.0.0", 11 | "license": "MIT" 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /compiled_starters/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@codecrafters/build-your-own-grep", 3 | "version": "1.0.0", 4 | "description": "Build your own Grep challenge, from CodeCrafters", 5 | "main": "main.js", 6 | "scripts": { 7 | "dev": "node app/main.js" 8 | }, 9 | "keywords": [ 10 | "build-your-own-x" 11 | ], 12 | "author": "", 13 | "license": "MIT", 14 | "dependencies": {} 15 | } -------------------------------------------------------------------------------- /compiled_starters/javascript/your_program.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Use this script to run your program LOCALLY. 4 | # 5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program. 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit early if any commands fail 10 | 11 | # Copied from .codecrafters/run.sh 12 | # 13 | # - Edit this to change how your program runs locally 14 | # - Edit .codecrafters/run.sh to change how your program runs remotely 15 | exec node app/main.js "$@" 16 | -------------------------------------------------------------------------------- /compiled_starters/kotlin/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | mvn -B package -Ddir=/tmp/codecrafters-build-grep-kotlin 12 | -------------------------------------------------------------------------------- /compiled_starters/kotlin/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec java -jar /tmp/codecrafters-build-grep-kotlin/build-your-own-grep.jar "$@" 12 | -------------------------------------------------------------------------------- /compiled_starters/kotlin/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /compiled_starters/kotlin/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .idea/ -------------------------------------------------------------------------------- /compiled_starters/kotlin/codecrafters.yml: -------------------------------------------------------------------------------- 1 | # Set this to true if you want debug logs. 2 | # 3 | # These can be VERY verbose, so we suggest turning them off 4 | # unless you really need them. 5 | debug: false 6 | 7 | # Use this to change the Kotlin version used to run your code 8 | # on Codecrafters. 9 | # 10 | # Available versions: kotlin-2.0 11 | language_pack: kotlin-2.0 12 | -------------------------------------------------------------------------------- /compiled_starters/kotlin/src/main/kotlin/Main.kt: -------------------------------------------------------------------------------- 1 | import kotlin.system.exitProcess 2 | 3 | fun main(args: Array) { 4 | if (args.size != 2 || args[0] != "-E") { 5 | println("Usage: ./your_program.sh -E ") 6 | exitProcess(1) 7 | } 8 | 9 | val pattern = args[1] 10 | val inputLine = System.`in`.bufferedReader().readText() 11 | 12 | // You can use print statements as follows for debugging, they'll be visible when running tests. 13 | System.err.println("Logs from your program will appear here!") 14 | 15 | // Uncomment this block to pass the first stage 16 | // if (matchPattern(inputLine, pattern)) { 17 | // exitProcess(0) 18 | // } else { 19 | // exitProcess(1) 20 | // } 21 | } 22 | 23 | fun matchPattern(inputLine: String, pattern: String): Boolean { 24 | return if (pattern.length == 1) { 25 | pattern in inputLine 26 | } else { 27 | throw RuntimeException("Unhandled pattern: $pattern") 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /compiled_starters/kotlin/your_program.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Use this script to run your program LOCALLY. 4 | # 5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program. 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit early if any commands fail 10 | 11 | # Copied from .codecrafters/compile.sh 12 | # 13 | # - Edit this to change how your program compiles locally 14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely 15 | ( 16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory 17 | mvn -B package -Ddir=/tmp/codecrafters-build-grep-kotlin 18 | ) 19 | 20 | # Copied from .codecrafters/run.sh 21 | # 22 | # - Edit this to change how your program runs locally 23 | # - Edit .codecrafters/run.sh to change how your program runs remotely 24 | exec java -jar /tmp/codecrafters-build-grep-kotlin/build-your-own-grep.jar "$@" 25 | -------------------------------------------------------------------------------- /compiled_starters/php/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | # (This file is empty since PHP programs don't use a compile step) -------------------------------------------------------------------------------- /compiled_starters/php/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec php app/main.php "$@" 12 | -------------------------------------------------------------------------------- /compiled_starters/php/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /compiled_starters/php/app/main.php: -------------------------------------------------------------------------------- 1 | "] 5 | edition = "2021" 6 | rust-version = "1.80" 7 | 8 | [dependencies] 9 | anyhow = "1.0.68" # error handling 10 | bytes = "1.3.0" # helps manage buffers 11 | thiserror = "1.0.38" # error handling 12 | -------------------------------------------------------------------------------- /compiled_starters/rust/codecrafters.yml: -------------------------------------------------------------------------------- 1 | # Set this to true if you want debug logs. 2 | # 3 | # These can be VERY verbose, so we suggest turning them off 4 | # unless you really need them. 5 | debug: false 6 | 7 | # Use this to change the Rust version used to run your code 8 | # on Codecrafters. 9 | # 10 | # Available versions: rust-1.86 11 | language_pack: rust-1.86 12 | -------------------------------------------------------------------------------- /compiled_starters/rust/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | use std::io; 3 | use std::process; 4 | 5 | fn match_pattern(input_line: &str, pattern: &str) -> bool { 6 | if pattern.chars().count() == 1 { 7 | return input_line.contains(pattern); 8 | } else { 9 | panic!("Unhandled pattern: {}", pattern) 10 | } 11 | } 12 | 13 | // Usage: echo | your_program.sh -E 14 | fn main() { 15 | // You can use print statements as follows for debugging, they'll be visible when running tests. 16 | eprintln!("Logs from your program will appear here!"); 17 | 18 | if env::args().nth(1).unwrap() != "-E" { 19 | println!("Expected first argument to be '-E'"); 20 | process::exit(1); 21 | } 22 | 23 | let pattern = env::args().nth(2).unwrap(); 24 | let mut input_line = String::new(); 25 | 26 | io::stdin().read_line(&mut input_line).unwrap(); 27 | 28 | // Uncomment this block to pass the first stage 29 | // if match_pattern(&input_line, &pattern) { 30 | // process::exit(0) 31 | // } else { 32 | // process::exit(1) 33 | // } 34 | } 35 | -------------------------------------------------------------------------------- /compiled_starters/rust/your_program.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Use this script to run your program LOCALLY. 4 | # 5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program. 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit early if any commands fail 10 | 11 | # Copied from .codecrafters/compile.sh 12 | # 13 | # - Edit this to change how your program compiles locally 14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely 15 | ( 16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory 17 | cargo build --release --target-dir=/tmp/codecrafters-build-grep-rust --manifest-path Cargo.toml 18 | ) 19 | 20 | # Copied from .codecrafters/run.sh 21 | # 22 | # - Edit this to change how your program runs locally 23 | # - Edit .codecrafters/run.sh to change how your program runs remotely 24 | exec /tmp/codecrafters-build-grep-rust/release/codecrafters-grep "$@" 25 | -------------------------------------------------------------------------------- /compiled_starters/typescript/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | # (This file is empty since TypeScript programs don't use a compile step) 12 | -------------------------------------------------------------------------------- /compiled_starters/typescript/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec bun run $(dirname $0)/app/main.ts "$@" 12 | -------------------------------------------------------------------------------- /compiled_starters/typescript/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /compiled_starters/typescript/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /compiled_starters/typescript/app/main.ts: -------------------------------------------------------------------------------- 1 | const args = process.argv; 2 | const pattern = args[3]; 3 | 4 | const inputLine: string = await Bun.stdin.text(); 5 | 6 | function matchPattern(inputLine: string, pattern: string): boolean { 7 | if (pattern.length === 1) { 8 | return inputLine.includes(pattern); 9 | } else { 10 | throw new Error(`Unhandled pattern: ${pattern}`); 11 | } 12 | } 13 | 14 | if (args[2] !== "-E") { 15 | console.log("Expected first argument to be '-E'"); 16 | process.exit(1); 17 | } 18 | 19 | // You can use print statements as follows for debugging, they'll be visible when running tests. 20 | console.error("Logs from your program will appear here!"); 21 | 22 | // Uncomment this block to pass the first stage 23 | // if (matchPattern(inputLine, pattern)) { 24 | // process.exit(0); 25 | // } else { 26 | // process.exit(1); 27 | // } 28 | -------------------------------------------------------------------------------- /compiled_starters/typescript/bun.lockb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codecrafters-io/build-your-own-grep/05cb8cdb45b2e3f0b39762f7077146c0f3ff32d7/compiled_starters/typescript/bun.lockb -------------------------------------------------------------------------------- /compiled_starters/typescript/codecrafters.yml: -------------------------------------------------------------------------------- 1 | # Set this to true if you want debug logs. 2 | # 3 | # These can be VERY verbose, so we suggest turning them off 4 | # unless you really need them. 5 | debug: false 6 | 7 | # Use this to change the TypeScript version used to run your code 8 | # on Codecrafters. 9 | # 10 | # Available versions: bun-1.2 11 | language_pack: bun-1.2 12 | -------------------------------------------------------------------------------- /compiled_starters/typescript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@codecrafters/grep", 3 | "description": "Build your own grep challenge, from CodeCrafters", 4 | "type": "module", 5 | "scripts": { 6 | "dev": "bun run app/main.ts" 7 | }, 8 | "devDependencies": { 9 | "@types/bun": "latest" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /compiled_starters/typescript/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | // Enable latest features 4 | "lib": ["ESNext", "DOM"], 5 | "target": "ESNext", 6 | "module": "ESNext", 7 | "moduleDetection": "force", 8 | "jsx": "react-jsx", 9 | "allowJs": true, 10 | 11 | // Bundler mode 12 | "moduleResolution": "bundler", 13 | "allowImportingTsExtensions": true, 14 | "verbatimModuleSyntax": true, 15 | "noEmit": true, 16 | 17 | // Best practices 18 | "strict": true, 19 | "skipLibCheck": true, 20 | "noFallthroughCasesInSwitch": true, 21 | 22 | // Some stricter flags (disabled by default) 23 | "noUnusedLocals": false, 24 | "noUnusedParameters": false, 25 | "noPropertyAccessFromIndexSignature": false 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /compiled_starters/typescript/your_program.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Use this script to run your program LOCALLY. 4 | # 5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program. 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit early if any commands fail 10 | 11 | # Copied from .codecrafters/run.sh 12 | # 13 | # - Edit this to change how your program runs locally 14 | # - Edit .codecrafters/run.sh to change how your program runs remotely 15 | exec bun run $(dirname $0)/app/main.ts "$@" 16 | -------------------------------------------------------------------------------- /compiled_starters/zig/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | zig build 12 | -------------------------------------------------------------------------------- /compiled_starters/zig/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec "$(dirname "$0")"/zig-out/bin/main "$@" 12 | -------------------------------------------------------------------------------- /compiled_starters/zig/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /compiled_starters/zig/.gitignore: -------------------------------------------------------------------------------- 1 | # Zig build artifacts 2 | main 3 | zig-cache/ 4 | .zig-cache/ 5 | zig-out/ 6 | 7 | # Compiled binary output 8 | bin/ 9 | !bin/.gitkeep 10 | 11 | # Ignore any .o or .h files generated during build 12 | *.o 13 | *.h 14 | 15 | # Ignore OS and editor specific files 16 | **/.DS_Store 17 | *.swp 18 | *~ 19 | -------------------------------------------------------------------------------- /compiled_starters/zig/codecrafters.yml: -------------------------------------------------------------------------------- 1 | # Set this to true if you want debug logs. 2 | # 3 | # These can be VERY verbose, so we suggest turning them off 4 | # unless you really need them. 5 | debug: false 6 | 7 | # Use this to change the Zig version used to run your code 8 | # on Codecrafters. 9 | # 10 | # Available versions: zig-0.14 11 | language_pack: zig-0.14 12 | -------------------------------------------------------------------------------- /compiled_starters/zig/your_program.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Use this script to run your program LOCALLY. 4 | # 5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program. 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit early if any commands fail 10 | 11 | # Copied from .codecrafters/compile.sh 12 | # 13 | # - Edit this to change how your program compiles locally 14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely 15 | ( 16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory 17 | zig build 18 | ) 19 | 20 | # Copied from .codecrafters/run.sh 21 | # 22 | # - Edit this to change how your program runs locally 23 | # - Edit .codecrafters/run.sh to change how your program runs remotely 24 | exec "$(dirname "$0")"/zig-out/bin/main "$@" 25 | -------------------------------------------------------------------------------- /dockerfiles/bun-1.1.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.7-labs 2 | FROM oven/bun:1.1-alpine 3 | 4 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="package.json,bun.lockb" 5 | 6 | WORKDIR /app 7 | 8 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses 9 | COPY --exclude=.git --exclude=README.md . /app 10 | 11 | # For reproducible builds. 12 | # This will install the exact versions of each package specified in the lockfile. 13 | # If package.json disagrees with bun.lockb, Bun will exit with an error. The lockfile will not be updated. 14 | RUN bun install --frozen-lockfile 15 | 16 | # If the node_modules directory exists, move it to /app-cached 17 | RUN mkdir -p /app-cached 18 | RUN if [ -d "/app/node_modules" ]; then mv /app/node_modules /app-cached; fi 19 | -------------------------------------------------------------------------------- /dockerfiles/bun-1.2.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.7-labs 2 | FROM oven/bun:1.2-alpine 3 | 4 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="package.json,bun.lockb" 5 | 6 | WORKDIR /app 7 | 8 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses 9 | COPY --exclude=.git --exclude=README.md . /app 10 | 11 | # For reproducible builds. 12 | # This will install the exact versions of each package specified in the lockfile. 13 | # If package.json disagrees with bun.lockb, Bun will exit with an error. The lockfile will not be updated. 14 | RUN bun install --frozen-lockfile 15 | 16 | # If the node_modules directory exists, move it to /app-cached 17 | RUN mkdir -p /app-cached 18 | RUN if [ -d "/app/node_modules" ]; then mv /app/node_modules /app-cached; fi 19 | -------------------------------------------------------------------------------- /dockerfiles/cpp-20.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM gcc:12.2.0-bullseye 2 | 3 | RUN apt-get update && \ 4 | apt-get install --no-install-recommends -y cmake=3.18.* && \ 5 | apt-get clean && \ 6 | rm -rf /var/lib/apt/lists/* 7 | -------------------------------------------------------------------------------- /dockerfiles/dotnet-8.0.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine 2 | 3 | COPY codecrafters-grep.csproj /app/codecrafters-grep.csproj 4 | COPY codecrafters-grep.sln /app/codecrafters-grep.sln 5 | 6 | RUN mkdir /app/src 7 | 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 8 | 9 | WORKDIR /app 10 | 11 | # This saves nuget packages to ~/.nuget 12 | RUN dotnet build --configuration Release . 13 | 14 | # Overwrite Program.cs to remove the echoed line 15 | RUN rm /app/src/Program.cs 16 | 17 | # This seems to cause a caching issue with the dotnet build command, where contents from the removed /src/Program.cs are used 18 | RUN rm -rf /app/obj 19 | RUN rm -rf /app/bin 20 | 21 | RUN echo "cd \${CODECRAFTERS_REPOSITORY_DIR} && dotnet build --configuration Release ." > /codecrafters-precompile.sh 22 | RUN chmod +x /codecrafters-precompile.sh 23 | 24 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="codecrafters-grep.csproj,codecrafters-grep.sln" 25 | -------------------------------------------------------------------------------- /dockerfiles/dotnet-9.0.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/dotnet/sdk:9.0-alpine 2 | 3 | COPY codecrafters-grep.csproj /app/codecrafters-grep.csproj 4 | COPY codecrafters-grep.sln /app/codecrafters-grep.sln 5 | 6 | RUN mkdir /app/src 7 | 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 8 | 9 | WORKDIR /app 10 | 11 | # This saves nuget packages to ~/.nuget 12 | RUN dotnet build --configuration Release . 13 | 14 | # Overwrite Program.cs to remove the echoed line 15 | RUN rm /app/src/Program.cs 16 | 17 | # This seems to cause a caching issue with the dotnet build command, where contents from the removed /src/Program.cs are used 18 | RUN rm -rf /app/obj 19 | RUN rm -rf /app/bin 20 | 21 | RUN echo "cd \${CODECRAFTERS_REPOSITORY_DIR} && dotnet build --configuration Release ." > /codecrafters-precompile.sh 22 | RUN chmod +x /codecrafters-precompile.sh 23 | 24 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="codecrafters-grep.csproj,codecrafters-grep.sln" 25 | -------------------------------------------------------------------------------- /dockerfiles/gleam-1.0.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ghcr.io/gleam-lang/gleam:v1.0.0-erlang-alpine 2 | 3 | # Pre-compile steps 4 | RUN printf "cd \${CODECRAFTERS_REPOSITORY_DIR} && gleam build" > /codecrafters-precompile.sh 5 | RUN chmod +x /codecrafters-precompile.sh 6 | -------------------------------------------------------------------------------- /dockerfiles/gleam-1.4.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.7-labs 2 | FROM ghcr.io/gleam-lang/gleam:v1.4.1-erlang-alpine 3 | 4 | # Rebuild if gleam.toml or manifest.toml change 5 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="gleam.toml,manifest.toml" 6 | 7 | WORKDIR /app 8 | 9 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses 10 | COPY --exclude=.git --exclude=README.md . /app 11 | 12 | # Force deps to be downloaded 13 | RUN gleam build 14 | 15 | # Cache build directory 16 | RUN mkdir -p /app-cached 17 | RUN mv build /app-cached/build 18 | -------------------------------------------------------------------------------- /dockerfiles/gleam-1.6.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.7-labs 2 | FROM ghcr.io/gleam-lang/gleam:v1.6.3-erlang-alpine 3 | 4 | # Rebuild if gleam.toml or manifest.toml change 5 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="gleam.toml,manifest.toml" 6 | 7 | WORKDIR /app 8 | 9 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses 10 | COPY --exclude=.git --exclude=README.md . /app 11 | 12 | # Force deps to be downloaded 13 | RUN gleam build 14 | 15 | # Cache build directory 16 | RUN mkdir -p /app-cached 17 | RUN mv build /app-cached/build 18 | -------------------------------------------------------------------------------- /dockerfiles/gleam-1.9.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.7-labs 2 | FROM ghcr.io/gleam-lang/gleam:v1.9.1-erlang-alpine 3 | 4 | # Rebuild if gleam.toml or manifest.toml change 5 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="gleam.toml,manifest.toml" 6 | 7 | WORKDIR /app 8 | 9 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses 10 | COPY --exclude=.git --exclude=README.md . /app 11 | 12 | # Force deps to be downloaded 13 | RUN gleam build 14 | 15 | # Cache build directory 16 | RUN mkdir -p /app-cached 17 | RUN mv build /app-cached/build 18 | -------------------------------------------------------------------------------- /dockerfiles/go-1.19.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.19-alpine 2 | 3 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="go.mod,go.sum" 4 | 5 | WORKDIR /app 6 | 7 | COPY go.mod go.sum ./ 8 | 9 | RUN go mod download 10 | -------------------------------------------------------------------------------- /dockerfiles/go-1.21.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.21-alpine 2 | 3 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="go.mod,go.sum" 4 | 5 | WORKDIR /app 6 | 7 | COPY go.mod go.sum ./ 8 | 9 | # Starting from Go 1.20, the go standard library is no loger compiled 10 | # setting the GODEBUG environment to "installgoroot=all" restores the old behavior 11 | RUN GODEBUG="installgoroot=all" go install std 12 | 13 | RUN go mod download 14 | -------------------------------------------------------------------------------- /dockerfiles/go-1.22.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.7-labs 2 | FROM golang:1.22-alpine 3 | 4 | # Ensures the container is re-built if go.mod or go.sum changes 5 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="go.mod,go.sum" 6 | 7 | WORKDIR /app 8 | 9 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses 10 | COPY --exclude=.git --exclude=README.md . /app 11 | 12 | # Starting from Go 1.20, the go standard library is no loger compiled. 13 | # Setting GODEBUG to "installgoroot=all" restores the old behavior 14 | RUN GODEBUG="installgoroot=all" go install std 15 | 16 | RUN go mod download 17 | -------------------------------------------------------------------------------- /dockerfiles/go-1.24.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.7-labs 2 | FROM golang:1.24-alpine 3 | 4 | # Ensures the container is re-built if go.mod or go.sum changes 5 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="go.mod,go.sum" 6 | 7 | WORKDIR /app 8 | 9 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses 10 | COPY --exclude=.git --exclude=README.md . /app 11 | 12 | # Starting from Go 1.20, the go standard library is no loger compiled. 13 | # Setting GODEBUG to "installgoroot=all" restores the old behavior 14 | RUN GODEBUG="installgoroot=all" go install std 15 | 16 | RUN go mod download 17 | -------------------------------------------------------------------------------- /dockerfiles/haskell-9.2.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM haskell:9.2.5-buster 2 | 3 | WORKDIR /app 4 | 5 | RUN mkdir -p /etc/stack 6 | 7 | # Absence of this causes `stack run` to raise a permissions error 8 | RUN echo "allow-different-user: true" >> /etc/stack/config.yaml 9 | 10 | # Force usage of the system GHC installation 11 | RUN echo "install-ghc: false" >> /etc/stack/config.yaml 12 | RUN echo "system-ghc: true" >> /etc/stack/config.yaml 13 | 14 | COPY stack.yaml package.yaml stack.yaml.lock /app/ 15 | 16 | # Dummy static content to circumvent the /app doesn't exist warning 17 | RUN mkdir /app/src 18 | RUN mkdir /app/app 19 | RUN echo 'main :: IO ()' >> /app/app/Main.hs 20 | RUN echo 'main = putStrLn "Hello, World!"' >> /app/app/Main.hs 21 | 22 | RUN stack build 23 | RUN stack clean hs-grep-clone 24 | RUN cp -r .stack-work /tmp/ 25 | 26 | RUN rm -rf /app/app 27 | RUN rm -rf /app/src 28 | 29 | RUN echo "cd \${CODECRAFTERS_REPOSITORY_DIR} && cp -r /tmp/.stack-work . && stack build" > /codecrafters-precompile.sh 30 | RUN chmod +x /codecrafters-precompile.sh 31 | 32 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="stack.yaml,package.yaml,stack.yaml.lock" -------------------------------------------------------------------------------- /dockerfiles/haskell-9.8.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM haskell:9.8.4-bullseye 2 | 3 | # Ensures the container is re-built if go.mod or go.sum changes 4 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="stack.yaml,package.yaml,stack.yaml.lock" 5 | 6 | RUN mkdir -p /etc/stack 7 | 8 | # Absence of this causes `stack run` to raise a permissions error 9 | RUN echo "allow-different-user: true" >> /etc/stack/config.yaml 10 | 11 | # Force usage of the system GHC installation 12 | RUN echo "install-ghc: false" >> /etc/stack/config.yaml 13 | RUN echo "system-ghc: true" >> /etc/stack/config.yaml 14 | 15 | WORKDIR /app 16 | 17 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses 18 | COPY . /app/ 19 | RUN rm -rf /app/.git /app/README.md 20 | 21 | ENV STACK_ROOT=/app/.stack 22 | RUN stack build 23 | RUN stack clean codecrafters-grep 24 | 25 | RUN mkdir /app-cached 26 | RUN mv .stack-work /app-cached/.stack-work 27 | RUN mv .stack /app-cached/.stack 28 | RUN rm -rf /app/app 29 | -------------------------------------------------------------------------------- /dockerfiles/java-23.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.7-labs 2 | FROM maven:3.9.9-eclipse-temurin-23-alpine 3 | 4 | # Ensures the container is re-built if dependency files change 5 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="pom.xml" 6 | 7 | WORKDIR /app 8 | 9 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses 10 | COPY --exclude=.git --exclude=README.md . /app 11 | 12 | # Install language-specific dependencies 13 | RUN .codecrafters/compile.sh 14 | -------------------------------------------------------------------------------- /dockerfiles/kotlin-2.0.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.7-labs 2 | FROM maven:3.9.8-eclipse-temurin-22-alpine 3 | 4 | # Ensures the container is re-built if pom.xml changes 5 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="pom.xml" 6 | 7 | WORKDIR /app 8 | 9 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses 10 | COPY --exclude=.git --exclude=README.md . /app 11 | 12 | # Cache dependencies 13 | RUN mvn -B package -Ddir=/tmp/codecrafters-build-grep-kotlin 14 | -------------------------------------------------------------------------------- /dockerfiles/nodejs-18.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:18.18.0-alpine3.17 -------------------------------------------------------------------------------- /dockerfiles/nodejs-21.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:21.7-alpine3.19 2 | 3 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="package.json,package-lock.json" 4 | 5 | WORKDIR /app 6 | 7 | COPY package.json ./ 8 | COPY package-lock.json ./ 9 | 10 | # If dependencies in the package lock do not match those in package.json, instead of updating the package lock, npm ci will exit with an error. 11 | RUN npm ci 12 | 13 | RUN mkdir -p /app-cached 14 | # If the node_modules directory exists, move it to /app-cached 15 | RUN if [ -d "/app/node_modules" ]; then mv /app/node_modules /app-cached; fi 16 | -------------------------------------------------------------------------------- /dockerfiles/php-8.4.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.7-labs 2 | FROM php:8.4.2RC1-cli-alpine3.20 3 | -------------------------------------------------------------------------------- /dockerfiles/python-3.10.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.10-alpine 2 | 3 | RUN pip install --no-cache-dir "pipenv>=2023.12.1" 4 | 5 | COPY Pipfile /app/Pipfile 6 | COPY Pipfile.lock /app/Pipfile.lock 7 | 8 | WORKDIR /app 9 | 10 | ENV WORKON_HOME=/venvs 11 | 12 | RUN pipenv install 13 | 14 | # Force environment creation 15 | RUN pipenv run python3 -c "1+1" 16 | 17 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Pipfile,Pipfile.lock" 18 | -------------------------------------------------------------------------------- /dockerfiles/python-3.11.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.11-alpine 2 | 3 | RUN pip install --no-cache-dir "pipenv>=2023.12.1" 4 | 5 | COPY Pipfile /app/Pipfile 6 | COPY Pipfile.lock /app/Pipfile.lock 7 | 8 | WORKDIR /app 9 | 10 | ENV WORKON_HOME=/venvs 11 | 12 | RUN pipenv install 13 | 14 | # Force environment creation 15 | RUN pipenv run python3 -c "1+1" 16 | 17 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Pipfile,Pipfile.lock" 18 | -------------------------------------------------------------------------------- /dockerfiles/python-3.12.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.12-alpine 2 | 3 | RUN pip install --no-cache-dir "pipenv>=2023.12.1" 4 | 5 | COPY Pipfile /app/Pipfile 6 | COPY Pipfile.lock /app/Pipfile.lock 7 | 8 | WORKDIR /app 9 | 10 | ENV WORKON_HOME=/venvs 11 | 12 | RUN pipenv install 13 | 14 | # Force environment creation 15 | RUN pipenv run python3 -c "1+1" 16 | 17 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Pipfile,Pipfile.lock" 18 | -------------------------------------------------------------------------------- /dockerfiles/python-3.13.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.13-alpine 2 | 3 | RUN pip install --no-cache-dir "pipenv>=2024.4.0" 4 | 5 | COPY Pipfile /app/Pipfile 6 | COPY Pipfile.lock /app/Pipfile.lock 7 | 8 | WORKDIR /app 9 | 10 | ENV WORKON_HOME=/venvs 11 | 12 | RUN pipenv install 13 | 14 | # Force environment creation 15 | RUN pipenv run python3 -c "1+1" 16 | 17 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Pipfile,Pipfile.lock" 18 | -------------------------------------------------------------------------------- /dockerfiles/ruby-2.7.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ruby:2.7-alpine 2 | 3 | RUN apk add --no-cache --upgrade 'curl>=7.66' 4 | RUN apk add --no-cache --upgrade 'curl-dev>=7.66' 5 | 6 | WORKDIR /app 7 | -------------------------------------------------------------------------------- /dockerfiles/ruby-3.2.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ruby:3.2-alpine 2 | 3 | RUN apk add --no-cache --upgrade 'curl>=7.66' 4 | RUN apk add --no-cache --upgrade 'curl-dev>=7.66' 5 | 6 | WORKDIR /app 7 | -------------------------------------------------------------------------------- /dockerfiles/ruby-3.3.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ruby:3.3-alpine 2 | 3 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Gemfile,Gemfile.lock" 4 | 5 | WORKDIR /app 6 | 7 | COPY Gemfile Gemfile.lock ./ 8 | 9 | RUN bundle install --verbose 10 | -------------------------------------------------------------------------------- /dockerfiles/rust-1.62.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM rust:1.62-buster 2 | 3 | COPY Cargo.toml /app/Cargo.toml 4 | COPY Cargo.lock /app/Cargo.lock 5 | 6 | RUN mkdir /app/src 7 | RUN echo 'fn main() { println!("Hello World!"); }' > /app/src/main.rs 8 | 9 | WORKDIR /app 10 | RUN cargo build --release --target-dir=/tmp/codecrafters-grep-target 11 | 12 | RUN cargo clean -p grep-starter-rust --release --target-dir=/tmp/codecrafters-grep-target 13 | 14 | RUN rm -rf /app/src 15 | 16 | RUN echo "cd \${CODECRAFTERS_REPOSITORY_DIR} && cargo build --release --target-dir=/tmp/codecrafters-grep-target --manifest-path Cargo.toml" > /codecrafters-precompile.sh 17 | RUN chmod +x /codecrafters-precompile.sh 18 | 19 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock" 20 | -------------------------------------------------------------------------------- /dockerfiles/rust-1.68.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM rust:1.68-buster 2 | 3 | COPY Cargo.toml /app/Cargo.toml 4 | COPY Cargo.lock /app/Cargo.lock 5 | 6 | RUN mkdir /app/src 7 | RUN echo 'fn main() { println!("Hello World!"); }' > /app/src/main.rs 8 | 9 | WORKDIR /app 10 | RUN cargo build --release --target-dir=/tmp/codecrafters-grep-target 11 | 12 | RUN cargo clean -p grep-starter-rust --release --target-dir=/tmp/codecrafters-grep-target 13 | 14 | RUN rm -rf /app/src 15 | 16 | RUN echo "cd \${CODECRAFTERS_REPOSITORY_DIR} && cargo build --release --target-dir=/tmp/codecrafters-grep-target --manifest-path Cargo.toml" > /codecrafters-precompile.sh 17 | RUN chmod +x /codecrafters-precompile.sh 18 | 19 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock" 20 | -------------------------------------------------------------------------------- /dockerfiles/rust-1.70.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM rust:1.70-buster 2 | 3 | COPY Cargo.toml /app/Cargo.toml 4 | COPY Cargo.lock /app/Cargo.lock 5 | 6 | RUN mkdir /app/src 7 | RUN echo 'fn main() { println!("Hello World!"); }' > /app/src/main.rs 8 | 9 | WORKDIR /app 10 | RUN cargo build --release --target-dir=/tmp/codecrafters-grep-target 11 | 12 | RUN cargo clean -p grep-starter-rust --release --target-dir=/tmp/codecrafters-grep-target 13 | 14 | RUN rm -rf /app/src 15 | 16 | RUN echo "cd \${CODECRAFTERS_REPOSITORY_DIR} && cargo build --release --target-dir=/tmp/codecrafters-grep-target --manifest-path Cargo.toml" > /codecrafters-precompile.sh 17 | RUN chmod +x /codecrafters-precompile.sh 18 | 19 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock" 20 | -------------------------------------------------------------------------------- /dockerfiles/rust-1.76.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM rust:1.76-buster 2 | 3 | COPY Cargo.toml /app/Cargo.toml 4 | COPY Cargo.lock /app/Cargo.lock 5 | 6 | RUN mkdir /app/src 7 | RUN echo 'fn main() { println!("Hello World!"); }' > /app/src/main.rs 8 | 9 | WORKDIR /app 10 | RUN cargo build --release --target-dir=/tmp/codecrafters-grep-target 11 | 12 | RUN cargo clean -p grep-starter-rust --release --target-dir=/tmp/codecrafters-grep-target 13 | 14 | RUN rm -rf /app/src 15 | 16 | RUN echo "cd \${CODECRAFTERS_REPOSITORY_DIR} && cargo build --release --target-dir=/tmp/codecrafters-grep-target --manifest-path Cargo.toml" > /codecrafters-precompile.sh 17 | RUN chmod +x /codecrafters-precompile.sh 18 | 19 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock" 20 | -------------------------------------------------------------------------------- /dockerfiles/rust-1.77.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.7-labs 2 | FROM rust:1.77-buster 3 | 4 | WORKDIR /app 5 | 6 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses 7 | COPY --exclude=.git --exclude=README.md . /app 8 | 9 | RUN cargo build --release --target-dir=/tmp/codecrafters-grep-target 10 | 11 | RUN cargo clean -p grep-starter-rust --release --target-dir=/tmp/codecrafters-grep-target 12 | 13 | RUN rm -rf /app/src 14 | 15 | RUN echo "cd \${CODECRAFTERS_REPOSITORY_DIR} && cargo build --release --target-dir=/tmp/codecrafters-grep-target --manifest-path Cargo.toml" > /codecrafters-precompile.sh 16 | RUN chmod +x /codecrafters-precompile.sh 17 | 18 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock" 19 | -------------------------------------------------------------------------------- /dockerfiles/rust-1.80.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.7-labs 2 | FROM rust:1.80-bookworm 3 | 4 | # Rebuild the container if these files change 5 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock" 6 | 7 | WORKDIR /app 8 | 9 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses 10 | COPY --exclude=.git --exclude=README.md . /app 11 | 12 | # This runs cargo build 13 | RUN .codecrafters/compile.sh 14 | -------------------------------------------------------------------------------- /dockerfiles/rust-1.82.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.7-labs 2 | FROM rust:1.82-bookworm 3 | 4 | # Rebuild the container if these files change 5 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock" 6 | 7 | WORKDIR /app 8 | 9 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses 10 | COPY --exclude=.git --exclude=README.md . /app 11 | 12 | # This runs cargo build 13 | RUN .codecrafters/compile.sh 14 | -------------------------------------------------------------------------------- /dockerfiles/rust-1.85.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.7-labs 2 | FROM rust:1.85-bookworm 3 | 4 | # Rebuild the container if these files change 5 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock" 6 | 7 | WORKDIR /app 8 | 9 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses 10 | COPY --exclude=.git --exclude=README.md . /app 11 | 12 | # This runs cargo build 13 | RUN .codecrafters/compile.sh 14 | -------------------------------------------------------------------------------- /dockerfiles/rust-1.86.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.7-labs 2 | FROM rust:1.86-bookworm 3 | 4 | # Rebuild the container if these files change 5 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock" 6 | 7 | WORKDIR /app 8 | 9 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses 10 | COPY --exclude=.git --exclude=README.md . /app 11 | 12 | # This runs cargo build 13 | RUN .codecrafters/compile.sh 14 | -------------------------------------------------------------------------------- /dockerfiles/zig-0.14.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.7-labs 2 | FROM alpine:3.20 3 | 4 | RUN apk add --no-cache 'xz>=5.6' 'curl>=8.9' 5 | 6 | # Download and install Zig 7 | RUN curl -O https://ziglang.org/download/0.14.0/zig-linux-x86_64-0.14.0.tar.xz \ 8 | && tar -xf zig-linux-x86_64-0.14.0.tar.xz \ 9 | && mv zig-linux-x86_64-0.14.0 /usr/local/zig \ 10 | && rm zig-linux-x86_64-0.14.0.tar.xz 11 | 12 | # Add Zig to PATH 13 | ENV PATH="/usr/local/zig:${PATH}" 14 | 15 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="build.zig,build.zig.zon" 16 | 17 | WORKDIR /app 18 | 19 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses 20 | COPY --exclude=.git --exclude=README.md . /app 21 | 22 | # This runs zig build 23 | RUN .codecrafters/compile.sh 24 | 25 | # Cache build directory 26 | RUN mkdir -p /app-cached 27 | RUN mv /app/.zig-cache /app-cached/.zig-cache || true 28 | -------------------------------------------------------------------------------- /solutions/cpp/01-cq2/code/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake 12 | cmake --build ./build 13 | -------------------------------------------------------------------------------- /solutions/cpp/01-cq2/code/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec ./build/exe "$@" 12 | -------------------------------------------------------------------------------- /solutions/cpp/01-cq2/code/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /solutions/cpp/01-cq2/code/.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | server 34 | 35 | # CMake 36 | CMakeLists.txt.user 37 | CMakeCache.txt 38 | CMakeFiles 39 | CMakeScripts 40 | Testing 41 | Makefile 42 | cmake_install.cmake 43 | install_manifest.txt 44 | compile_commands.json 45 | CTestTestfile.cmake 46 | _deps 47 | 48 | build/ 49 | vcpkg_installed -------------------------------------------------------------------------------- /solutions/cpp/01-cq2/code/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | project(grep-starter-cpp) 4 | 5 | set(CMAKE_CXX_STANDARD 23) # Enable the C++23 standard 6 | 7 | file(GLOB_RECURSE SOURCE_FILES src/*.cpp src/*.hpp) 8 | 9 | add_executable(exe ${SOURCE_FILES}) -------------------------------------------------------------------------------- /solutions/cpp/01-cq2/code/codecrafters.yml: -------------------------------------------------------------------------------- 1 | # Set this to true if you want debug logs. 2 | # 3 | # These can be VERY verbose, so we suggest turning them off 4 | # unless you really need them. 5 | debug: false 6 | 7 | # Use this to change the C++ version used to run your code 8 | # on Codecrafters. 9 | # 10 | # Available versions: cpp-23 11 | language_pack: cpp-23 12 | -------------------------------------------------------------------------------- /solutions/cpp/01-cq2/code/src/Server.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | bool match_pattern(const std::string& input_line, const std::string& pattern) { 5 | if (pattern.length() == 1) { 6 | return input_line.find(pattern) != std::string::npos; 7 | } 8 | else { 9 | throw std::runtime_error("Unhandled pattern " + pattern); 10 | } 11 | } 12 | 13 | int main(int argc, char* argv[]) { 14 | // Flush after every std::cout / std::cerr 15 | std::cout << std::unitbuf; 16 | std::cerr << std::unitbuf; 17 | 18 | if (argc != 3) { 19 | std::cerr << "Expected two arguments" << std::endl; 20 | return 1; 21 | } 22 | 23 | std::string flag = argv[1]; 24 | std::string pattern = argv[2]; 25 | 26 | if (flag != "-E") { 27 | std::cerr << "Expected first argument to be '-E'" << std::endl; 28 | return 1; 29 | } 30 | 31 | std::string input_line; 32 | std::getline(std::cin, input_line); 33 | 34 | try { 35 | if (match_pattern(input_line, pattern)) { 36 | return 0; 37 | } else { 38 | return 1; 39 | } 40 | } catch (const std::runtime_error& e) { 41 | std::cerr << e.what() << std::endl; 42 | return 1; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /solutions/cpp/01-cq2/code/vcpkg-configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "default-registry": { 3 | "kind": "git", 4 | "baseline": "c4af3593e1f1aa9e14a560a09e45ea2cb0dfd74d", 5 | "repository": "https://github.com/microsoft/vcpkg" 6 | }, 7 | "registries": [ 8 | { 9 | "kind": "artifact", 10 | "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip", 11 | "name": "microsoft" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /solutions/cpp/01-cq2/code/vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": [] 3 | } -------------------------------------------------------------------------------- /solutions/cpp/01-cq2/code/your_program.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Use this script to run your program LOCALLY. 4 | # 5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program. 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit early if any commands fail 10 | 11 | # Copied from .codecrafters/compile.sh 12 | # 13 | # - Edit this to change how your program compiles locally 14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely 15 | ( 16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory 17 | cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake 18 | cmake --build ./build 19 | ) 20 | 21 | # Copied from .codecrafters/run.sh 22 | # 23 | # - Edit this to change how your program runs locally 24 | # - Edit .codecrafters/run.sh to change how your program runs remotely 25 | exec ./build/exe "$@" 26 | -------------------------------------------------------------------------------- /solutions/cpp/01-cq2/explanation.md: -------------------------------------------------------------------------------- 1 | The entry point for your grep implementation is in `src/Server.cpp`. 2 | 3 | Study and uncomment the relevant code: 4 | 5 | ```cpp 6 | // Uncomment this block to pass the first stage 7 | 8 | std::string input_line; 9 | std::getline(std::cin, input_line); 10 | 11 | try { 12 | if (match_pattern(input_line, pattern)) { 13 | return 0; 14 | } else { 15 | return 1; 16 | } 17 | } catch (const std::runtime_error& e) { 18 | std::cerr << e.what() << std::endl; 19 | return 1; 20 | } 21 | ``` 22 | 23 | Push your changes to pass the first stage: 24 | 25 | ``` 26 | git add . 27 | git commit -m "pass 1st stage" # any msg 28 | git push origin master 29 | ``` 30 | -------------------------------------------------------------------------------- /solutions/csharp/01-cq2/code/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | dotnet build --configuration Release --output /tmp/codecrafters-build-grep-csharp codecrafters-grep.csproj 12 | -------------------------------------------------------------------------------- /solutions/csharp/01-cq2/code/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec /tmp/codecrafters-build-grep-csharp/codecrafters-grep "$@" -------------------------------------------------------------------------------- /solutions/csharp/01-cq2/code/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /solutions/csharp/01-cq2/code/codecrafters-grep.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | codecrafters_grep 7 | enable 8 | enable 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /solutions/csharp/01-cq2/code/codecrafters-grep.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.31903.59 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "codecrafters-grep", "codecrafters-grep.csproj", "{5647EB94-C939-4AAF-BDC4-807AA270FCF0}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(SolutionProperties) = preSolution 14 | HideSolutionNode = FALSE 15 | EndGlobalSection 16 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 17 | {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 18 | {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Debug|Any CPU.Build.0 = Debug|Any CPU 19 | {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Release|Any CPU.ActiveCfg = Release|Any CPU 20 | {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Release|Any CPU.Build.0 = Release|Any CPU 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /solutions/csharp/01-cq2/code/codecrafters.yml: -------------------------------------------------------------------------------- 1 | # Set this to true if you want debug logs. 2 | # 3 | # These can be VERY verbose, so we suggest turning them off 4 | # unless you really need them. 5 | debug: false 6 | 7 | # Use this to change the C# version used to run your code 8 | # on Codecrafters. 9 | # 10 | # Available versions: dotnet-9.0 11 | language_pack: dotnet-9.0 12 | -------------------------------------------------------------------------------- /solutions/csharp/01-cq2/code/src/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | static bool MatchPattern(string inputLine, string pattern) 5 | { 6 | if (pattern.Length == 1) 7 | { 8 | return inputLine.Contains(pattern); 9 | } 10 | else 11 | { 12 | throw new ArgumentException($"Unhandled pattern: {pattern}"); 13 | } 14 | } 15 | 16 | if (args[0] != "-E") 17 | { 18 | Console.WriteLine("Expected first argument to be '-E'"); 19 | Environment.Exit(2); 20 | } 21 | 22 | string pattern = args[1]; 23 | string inputLine = Console.In.ReadToEnd(); 24 | 25 | if (MatchPattern(inputLine, pattern)) 26 | { 27 | Environment.Exit(0); 28 | } 29 | else 30 | { 31 | Environment.Exit(1); 32 | } 33 | -------------------------------------------------------------------------------- /solutions/csharp/01-cq2/code/your_program.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Use this script to run your program LOCALLY. 4 | # 5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program. 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit early if any commands fail 10 | 11 | # Copied from .codecrafters/compile.sh 12 | # 13 | # - Edit this to change how your program compiles locally 14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely 15 | ( 16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory 17 | dotnet build --configuration Release --output /tmp/codecrafters-build-grep-csharp codecrafters-grep.csproj 18 | ) 19 | 20 | # Copied from .codecrafters/run.sh 21 | # 22 | # - Edit this to change how your program runs locally 23 | # - Edit .codecrafters/run.sh to change how your program runs remotely 24 | exec /tmp/codecrafters-build-grep-csharp/codecrafters-grep "$@" 25 | -------------------------------------------------------------------------------- /solutions/csharp/01-cq2/diff/src/Program.cs.diff: -------------------------------------------------------------------------------- 1 | @@ -1,37 +1,32 @@ 2 | using System; 3 | using System.IO; 4 | 5 | static bool MatchPattern(string inputLine, string pattern) 6 | { 7 | if (pattern.Length == 1) 8 | { 9 | return inputLine.Contains(pattern); 10 | } 11 | else 12 | { 13 | throw new ArgumentException($"Unhandled pattern: {pattern}"); 14 | } 15 | } 16 | 17 | if (args[0] != "-E") 18 | { 19 | Console.WriteLine("Expected first argument to be '-E'"); 20 | Environment.Exit(2); 21 | } 22 | 23 | string pattern = args[1]; 24 | string inputLine = Console.In.ReadToEnd(); 25 | 26 | -// You can use print statements as follows for debugging, they'll be visible when running tests. 27 | -Console.Error.WriteLine("Logs from your program will appear here!"); 28 | - 29 | -// Uncomment this block to pass the first stage 30 | -// 31 | -// if (MatchPattern(inputLine, pattern)) 32 | -// { 33 | -// Environment.Exit(0); 34 | -// } 35 | -// else 36 | -// { 37 | -// Environment.Exit(1); 38 | -// } 39 | +if (MatchPattern(inputLine, pattern)) 40 | +{ 41 | + Environment.Exit(0); 42 | +} 43 | +else 44 | +{ 45 | + Environment.Exit(1); 46 | +} 47 | -------------------------------------------------------------------------------- /solutions/csharp/01-cq2/explanation.md: -------------------------------------------------------------------------------- 1 | The entry point for your grep implementation is in `src/Program.cs`. 2 | 3 | Study and uncomment the relevant code: 4 | 5 | ```csharp 6 | // Uncomment this block to pass the first stage 7 | 8 | if (MatchPattern(inputLine, pattern)) 9 | { 10 | Environment.Exit(0); 11 | } 12 | else 13 | { 14 | Environment.Exit(1); 15 | } 16 | ``` 17 | 18 | Push your changes to pass the first stage: 19 | 20 | ``` 21 | git add . 22 | git commit -m "pass 1st stage" # any msg 23 | git push origin master 24 | ``` 25 | -------------------------------------------------------------------------------- /solutions/gleam/01-cq2/code/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | gleam build 12 | -------------------------------------------------------------------------------- /solutions/gleam/01-cq2/code/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec gleam run --module main -- "$@" 12 | -------------------------------------------------------------------------------- /solutions/gleam/01-cq2/code/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /solutions/gleam/01-cq2/code/.gitignore: -------------------------------------------------------------------------------- 1 | *.beam 2 | *.ez 3 | /build 4 | erl_crash.dump 5 | -------------------------------------------------------------------------------- /solutions/gleam/01-cq2/code/codecrafters.yml: -------------------------------------------------------------------------------- 1 | # Set this to true if you want debug logs. 2 | # 3 | # These can be VERY verbose, so we suggest turning them off 4 | # unless you really need them. 5 | debug: false 6 | 7 | # Use this to change the Gleam version used to run your code 8 | # on Codecrafters. 9 | # 10 | # Available versions: gleam-1.9 11 | language_pack: gleam-1.9 12 | -------------------------------------------------------------------------------- /solutions/gleam/01-cq2/code/gleam.toml: -------------------------------------------------------------------------------- 1 | name = "codecrafters_grep" 2 | version = "1.0.0" 3 | 4 | # For a full reference of all the available options, you can have a look at 5 | # https://gleam.run/writing-gleam/gleam-toml/. 6 | 7 | [dependencies] 8 | argv = ">= 1.0.2 and < 2.0.0" 9 | gleam_erlang = "~> 0.25" 10 | gleam_stdlib = "~> 0.34 or ~> 1.0" 11 | 12 | [dev-dependencies] 13 | gleeunit = "~> 1.0" -------------------------------------------------------------------------------- /solutions/gleam/01-cq2/code/manifest.toml: -------------------------------------------------------------------------------- 1 | # This file was generated by Gleam 2 | # You typically do not need to edit this file 3 | 4 | packages = [ 5 | { name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" }, 6 | { name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" }, 7 | { name = "gleam_stdlib", version = "0.38.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "663CF11861179AF415A625307447775C09404E752FF99A24E2057C835319F1BE" }, 8 | { name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" }, 9 | ] 10 | 11 | [requirements] 12 | argv = { version = ">= 1.0.2 and < 2.0.0" } 13 | gleam_erlang = { version = "~> 0.25" } 14 | gleam_stdlib = { version = "~> 0.34 or ~> 1.0" } 15 | gleeunit = { version = "~> 1.0" } 16 | -------------------------------------------------------------------------------- /solutions/gleam/01-cq2/code/src/main.gleam: -------------------------------------------------------------------------------- 1 | import argv 2 | import gleam/erlang 3 | import gleam/io 4 | import gleam/string 5 | 6 | pub fn main() { 7 | let args = argv.load().arguments 8 | let assert Ok(input_line) = erlang.get_line("") 9 | 10 | case args { 11 | ["-E", pattern, ..] -> { 12 | case match_pattern(input_line, pattern) { 13 | True -> exit(0) 14 | False -> exit(1) 15 | } 16 | } 17 | _ -> { 18 | io.println("Expected first argument to be '-E'") 19 | exit(1) 20 | } 21 | } 22 | } 23 | 24 | fn match_pattern(input_line: String, pattern: String) -> Bool { 25 | case string.length(pattern) { 26 | 1 -> string.contains(input_line, pattern) 27 | _ -> { 28 | io.println("Unhandled pattern: " <> pattern) 29 | False 30 | } 31 | } 32 | } 33 | 34 | @external(erlang, "erlang", "halt") 35 | pub fn exit(code: Int) -> Int 36 | -------------------------------------------------------------------------------- /solutions/gleam/01-cq2/code/your_program.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Use this script to run your program LOCALLY. 4 | # 5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program. 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit early if any commands fail 10 | 11 | # Copied from .codecrafters/compile.sh 12 | # 13 | # - Edit this to change how your program compiles locally 14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely 15 | ( 16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory 17 | gleam build 18 | ) 19 | 20 | # Copied from .codecrafters/run.sh 21 | # 22 | # - Edit this to change how your program runs locally 23 | # - Edit .codecrafters/run.sh to change how your program runs remotely 24 | exec gleam run --module main -- "$@" 25 | -------------------------------------------------------------------------------- /solutions/gleam/01-cq2/explanation.md: -------------------------------------------------------------------------------- 1 | The entry point for your grep implementation is in `src/main.gleam`. 2 | 3 | Study and uncomment the relevant code: 4 | 5 | ```gleam 6 | // Uncomment this to pass the first stage 7 | case args { 8 | ["-E", pattern, ..] -> { 9 | case match_pattern(input_line, pattern) { 10 | True -> exit(0) 11 | False -> exit(1) 12 | } 13 | } 14 | _ -> { 15 | io.println("Expected first argument to be '-E'") 16 | exit(1) 17 | } 18 | } 19 | ``` 20 | 21 | Push your changes to pass the first stage: 22 | 23 | ``` 24 | git add . 25 | git commit -m "pass 1st stage" # any msg 26 | git push origin master 27 | ``` 28 | -------------------------------------------------------------------------------- /solutions/go/01-cq2/code/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | go build -o /tmp/codecrafters-build-grep-go app/*.go 12 | -------------------------------------------------------------------------------- /solutions/go/01-cq2/code/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec /tmp/codecrafters-build-grep-go "$@" 12 | -------------------------------------------------------------------------------- /solutions/go/01-cq2/code/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /solutions/go/01-cq2/code/app/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "io" 7 | "os" 8 | "unicode/utf8" 9 | ) 10 | 11 | // Ensures gofmt doesn't remove the "bytes" import above (feel free to remove this!) 12 | var _ = bytes.ContainsAny 13 | 14 | // Usage: echo | your_program.sh -E 15 | func main() { 16 | if len(os.Args) < 3 || os.Args[1] != "-E" { 17 | fmt.Fprintf(os.Stderr, "usage: mygrep -E \n") 18 | os.Exit(2) // 1 means no lines were selected, >1 means error 19 | } 20 | 21 | pattern := os.Args[2] 22 | 23 | line, err := io.ReadAll(os.Stdin) // assume we're only dealing with a single line 24 | if err != nil { 25 | fmt.Fprintf(os.Stderr, "error: read input text: %v\n", err) 26 | os.Exit(2) 27 | } 28 | 29 | ok, err := matchLine(line, pattern) 30 | if err != nil { 31 | fmt.Fprintf(os.Stderr, "error: %v\n", err) 32 | os.Exit(2) 33 | } 34 | 35 | if !ok { 36 | os.Exit(1) 37 | } 38 | 39 | // default exit code is 0 which means success 40 | } 41 | 42 | func matchLine(line []byte, pattern string) (bool, error) { 43 | if utf8.RuneCountInString(pattern) != 1 { 44 | return false, fmt.Errorf("unsupported pattern: %q", pattern) 45 | } 46 | 47 | var ok bool 48 | 49 | ok = bytes.ContainsAny(line, pattern) 50 | 51 | return ok, nil 52 | } 53 | -------------------------------------------------------------------------------- /solutions/go/01-cq2/code/codecrafters.yml: -------------------------------------------------------------------------------- 1 | # Set this to true if you want debug logs. 2 | # 3 | # These can be VERY verbose, so we suggest turning them off 4 | # unless you really need them. 5 | debug: false 6 | 7 | # Use this to change the Go version used to run your code 8 | # on Codecrafters. 9 | # 10 | # Available versions: go-1.24 11 | language_pack: go-1.24 12 | -------------------------------------------------------------------------------- /solutions/go/01-cq2/code/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/codecrafters-io/grep-starter-go 2 | 3 | go 1.24.0 4 | -------------------------------------------------------------------------------- /solutions/go/01-cq2/code/go.sum: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codecrafters-io/build-your-own-grep/05cb8cdb45b2e3f0b39762f7077146c0f3ff32d7/solutions/go/01-cq2/code/go.sum -------------------------------------------------------------------------------- /solutions/go/01-cq2/code/your_program.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Use this script to run your program LOCALLY. 4 | # 5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program. 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit early if any commands fail 10 | 11 | # Copied from .codecrafters/compile.sh 12 | # 13 | # - Edit this to change how your program compiles locally 14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely 15 | ( 16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory 17 | go build -o /tmp/codecrafters-build-grep-go app/*.go 18 | ) 19 | 20 | # Copied from .codecrafters/run.sh 21 | # 22 | # - Edit this to change how your program runs locally 23 | # - Edit .codecrafters/run.sh to change how your program runs remotely 24 | exec /tmp/codecrafters-build-grep-go "$@" 25 | -------------------------------------------------------------------------------- /solutions/go/01-cq2/diff/app/main.go.diff: -------------------------------------------------------------------------------- 1 | @@ -24,33 +24,29 @@ 2 | if err != nil { 3 | fmt.Fprintf(os.Stderr, "error: read input text: %v\n", err) 4 | os.Exit(2) 5 | } 6 | 7 | ok, err := matchLine(line, pattern) 8 | if err != nil { 9 | fmt.Fprintf(os.Stderr, "error: %v\n", err) 10 | os.Exit(2) 11 | } 12 | 13 | if !ok { 14 | os.Exit(1) 15 | } 16 | 17 | // default exit code is 0 which means success 18 | } 19 | 20 | func matchLine(line []byte, pattern string) (bool, error) { 21 | if utf8.RuneCountInString(pattern) != 1 { 22 | return false, fmt.Errorf("unsupported pattern: %q", pattern) 23 | } 24 | 25 | var ok bool 26 | 27 | - // You can use print statements as follows for debugging, they'll be visible when running tests. 28 | - fmt.Fprintln(os.Stderr, "Logs from your program will appear here!") 29 | - 30 | - // Uncomment this to pass the first stage 31 | - // ok = bytes.ContainsAny(line, pattern) 32 | + ok = bytes.ContainsAny(line, pattern) 33 | 34 | return ok, nil 35 | } 36 | -------------------------------------------------------------------------------- /solutions/go/01-cq2/explanation.md: -------------------------------------------------------------------------------- 1 | The entry point for your grep implementation is in `app/main.go`. 2 | 3 | Study and uncomment the relevant code: 4 | 5 | ```go 6 | // Uncomment this to pass the first stage 7 | ok = bytes.ContainsAny(line, pattern) 8 | ``` 9 | 10 | Push your changes to pass the first stage: 11 | 12 | ``` 13 | git add . 14 | git commit -m "pass 1st stage" # any msg 15 | git push origin master 16 | ``` 17 | -------------------------------------------------------------------------------- /solutions/haskell/01-cq2/code/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | # This compiles the program into $(stack path --local-install-root)/bin/codecrafters-grep-exe. 12 | stack build 13 | -------------------------------------------------------------------------------- /solutions/haskell/01-cq2/code/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec $(stack path --local-install-root)/bin/codecrafters-grep-exe "$@" -------------------------------------------------------------------------------- /solutions/haskell/01-cq2/code/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /solutions/haskell/01-cq2/code/.gitignore: -------------------------------------------------------------------------------- 1 | codecrafters-grep.cabal 2 | *~ 3 | dist 4 | dist-* 5 | cabal-dev 6 | *.o 7 | *.hi 8 | *.hie 9 | *.chi 10 | *.chs.h 11 | *.dyn_o 12 | *.dyn_hi 13 | .hpc 14 | .hsenv 15 | .cabal-sandbox/ 16 | cabal.sandbox.config 17 | *.prof 18 | *.aux 19 | *.hp 20 | *.eventlog 21 | .stack/ 22 | .stack-work/ 23 | cabal.project.local 24 | cabal.project.local~ 25 | .HTF/ 26 | .ghc.environment.* -------------------------------------------------------------------------------- /solutions/haskell/01-cq2/code/app/Main.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import System.Environment 4 | import System.Exit 5 | import System.IO (hPutStrLn, hSetBuffering, stdout, stderr, BufferMode (NoBuffering)) 6 | 7 | matchPattern :: String -> String -> Bool 8 | matchPattern pattern input = do 9 | if length pattern == 1 10 | then head pattern `elem` input 11 | else error $ "Unhandled pattern: " ++ pattern 12 | 13 | main :: IO () 14 | main = do 15 | -- Disable output buffering 16 | hSetBuffering stdout NoBuffering 17 | hSetBuffering stderr NoBuffering 18 | 19 | args <- getArgs 20 | let pattern = args !! 1 21 | input_line <- getLine 22 | 23 | if head args /= "-E" 24 | then do 25 | putStrLn "Expected first argument to be '-E'" 26 | exitFailure 27 | else do if matchPattern pattern input_line 28 | then exitSuccess 29 | else exitFailure 30 | -------------------------------------------------------------------------------- /solutions/haskell/01-cq2/code/codecrafters.yml: -------------------------------------------------------------------------------- 1 | # Set this to true if you want debug logs. 2 | # 3 | # These can be VERY verbose, so we suggest turning them off 4 | # unless you really need them. 5 | debug: false 6 | 7 | # Use this to change the Haskell version used to run your code 8 | # on Codecrafters. 9 | # 10 | # Available versions: haskell-9.8 11 | language_pack: haskell-9.8 12 | -------------------------------------------------------------------------------- /solutions/haskell/01-cq2/code/package.yaml: -------------------------------------------------------------------------------- 1 | name: codecrafters-grep 2 | version: 0.1.0.0 3 | license: BSD3 4 | 5 | dependencies: 6 | - base >= 4.19 && < 5 7 | - megaparsec # can help when implementing the parser 8 | - parser-combinators # extends megaparsec 9 | - containers # Set, Map, Seq 10 | - unordered-containers # HashSet, HashMap 11 | - hashable # when using your own data types with unordered-containers 12 | - mtl # monad transformers to help with nested monads 13 | 14 | default-extensions: 15 | - BlockArguments 16 | - ImportQualifiedPost 17 | - LambdaCase 18 | - NamedFieldPuns 19 | - RecordWildCards 20 | 21 | executables: 22 | codecrafters-grep-exe: 23 | main: Main.hs 24 | source-dirs: app 25 | ghc-options: 26 | - -threaded 27 | - -rtsopts 28 | - -with-rtsopts=-N 29 | -------------------------------------------------------------------------------- /solutions/haskell/01-cq2/code/stack.yaml: -------------------------------------------------------------------------------- 1 | resolver: lts-23.18 2 | 3 | packages: 4 | - . 5 | -------------------------------------------------------------------------------- /solutions/haskell/01-cq2/code/stack.yaml.lock: -------------------------------------------------------------------------------- 1 | # This file was autogenerated by Stack. 2 | # You should not edit this file by hand. 3 | # For more information, please see the documentation at: 4 | # https://docs.haskellstack.org/en/stable/lock_files 5 | 6 | packages: [] 7 | snapshots: 8 | - completed: 9 | sha256: d133abe75e408a407cce3f032c96ac1bbadf474a93b5156ebf4135b53382d56b 10 | size: 683827 11 | url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/23/18.yaml 12 | original: lts-23.18 13 | -------------------------------------------------------------------------------- /solutions/haskell/01-cq2/code/your_program.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Use this script to run your program LOCALLY. 4 | # 5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program. 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit early if any commands fail 10 | 11 | # Copied from .codecrafters/compile.sh 12 | # 13 | # - Edit this to change how your program compiles locally 14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely 15 | ( 16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory 17 | stack build 18 | ) 19 | 20 | # Copied from .codecrafters/run.sh 21 | # 22 | # - Edit this to change how your program runs locally 23 | # - Edit .codecrafters/run.sh to change how your program runs remotely 24 | exec $(stack path --local-install-root)/bin/codecrafters-grep-exe "$@" 25 | -------------------------------------------------------------------------------- /solutions/haskell/01-cq2/explanation.md: -------------------------------------------------------------------------------- 1 | The entry point for your grep implementation is in `app/Main.hs`. 2 | 3 | Study and uncomment the relevant code: 4 | 5 | ```haskell 6 | -- Uncomment this block to pass stage 1 7 | if head args /= "-E" 8 | then do 9 | putStrLn "Expected first argument to be '-E'" 10 | exitFailure 11 | else do if matchPattern pattern input_line 12 | then exitSuccess 13 | else exitFailure 14 | ``` 15 | 16 | Push your changes to pass the first stage: 17 | 18 | ``` 19 | git add . 20 | git commit -m "pass 1st stage" # any msg 21 | git push origin master 22 | ``` 23 | -------------------------------------------------------------------------------- /solutions/java/01-cq2/code/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | mvn -B package -Ddir=/tmp/codecrafters-build-grep-java 12 | -------------------------------------------------------------------------------- /solutions/java/01-cq2/code/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec java -jar /tmp/codecrafters-build-grep-java/codecrafters-grep.jar "$@" 12 | -------------------------------------------------------------------------------- /solutions/java/01-cq2/code/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /solutions/java/01-cq2/code/.gitignore: -------------------------------------------------------------------------------- 1 | *.jar 2 | target/ 3 | .idea/ 4 | -------------------------------------------------------------------------------- /solutions/java/01-cq2/code/codecrafters.yml: -------------------------------------------------------------------------------- 1 | # Set this to true if you want debug logs. 2 | # 3 | # These can be VERY verbose, so we suggest turning them off 4 | # unless you really need them. 5 | debug: false 6 | 7 | # Use this to change the Java version used to run your code 8 | # on Codecrafters. 9 | # 10 | # Available versions: java-23 11 | language_pack: java-23 12 | -------------------------------------------------------------------------------- /solutions/java/01-cq2/code/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | import java.io.IOException; 2 | import java.util.Scanner; 3 | 4 | public class Main { 5 | public static void main(String[] args){ 6 | if (args.length != 2 || !args[0].equals("-E")) { 7 | System.out.println("Usage: ./your_program.sh -E "); 8 | System.exit(1); 9 | } 10 | 11 | String pattern = args[1]; 12 | Scanner scanner = new Scanner(System.in); 13 | String inputLine = scanner.nextLine(); 14 | 15 | if (matchPattern(inputLine, pattern)) { 16 | System.exit(0); 17 | } else { 18 | System.exit(1); 19 | } 20 | } 21 | 22 | public static boolean matchPattern(String inputLine, String pattern) { 23 | if (pattern.length() == 1) { 24 | return inputLine.contains(pattern); 25 | } else { 26 | throw new RuntimeException("Unhandled pattern: " + pattern); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /solutions/java/01-cq2/code/your_program.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Use this script to run your program LOCALLY. 4 | # 5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program. 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit early if any commands fail 10 | 11 | # Copied from .codecrafters/compile.sh 12 | # 13 | # - Edit this to change how your program compiles locally 14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely 15 | ( 16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory 17 | mvn -B package -Ddir=/tmp/codecrafters-build-grep-java 18 | ) 19 | 20 | # Copied from .codecrafters/run.sh 21 | # 22 | # - Edit this to change how your program runs locally 23 | # - Edit .codecrafters/run.sh to change how your program runs remotely 24 | exec java -jar /tmp/codecrafters-build-grep-java/codecrafters-grep.jar "$@" 25 | -------------------------------------------------------------------------------- /solutions/java/01-cq2/explanation.md: -------------------------------------------------------------------------------- 1 | The entry point for your grep implementation is in `src/main/java/Main.java`. 2 | 3 | Study and uncomment the relevant code: 4 | 5 | ```java 6 | // Uncomment this block to pass the first stage 7 | 8 | if (matchPattern(inputLine, pattern)) { 9 | System.exit(0); 10 | } else { 11 | System.exit(1); 12 | } 13 | ``` 14 | 15 | Push your changes to pass the first stage: 16 | 17 | ``` 18 | git add . 19 | git commit -m "pass 1st stage" # any msg 20 | git push origin master 21 | ``` 22 | -------------------------------------------------------------------------------- /solutions/javascript/01-cq2/code/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | # (This file is empty since JavaScript programs don't use a compile step) 12 | -------------------------------------------------------------------------------- /solutions/javascript/01-cq2/code/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec node app/main.js "$@" 12 | -------------------------------------------------------------------------------- /solutions/javascript/01-cq2/code/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /solutions/javascript/01-cq2/code/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /solutions/javascript/01-cq2/code/app/main.js: -------------------------------------------------------------------------------- 1 | function matchPattern(inputLine, pattern) { 2 | if (pattern.length === 1) { 3 | return inputLine.includes(pattern); 4 | } else { 5 | throw new Error(`Unhandled pattern ${pattern}`); 6 | } 7 | } 8 | 9 | function main() { 10 | const pattern = process.argv[3]; 11 | const inputLine = require("fs").readFileSync(0, "utf-8").trim(); 12 | 13 | if (process.argv[2] !== "-E") { 14 | console.log("Expected first argument to be '-E'"); 15 | process.exit(1); 16 | } 17 | 18 | if (matchPattern(inputLine, pattern)) { 19 | process.exit(0); 20 | } else { 21 | process.exit(1); 22 | } 23 | } 24 | 25 | main(); 26 | -------------------------------------------------------------------------------- /solutions/javascript/01-cq2/code/codecrafters.yml: -------------------------------------------------------------------------------- 1 | # Set this to true if you want debug logs. 2 | # 3 | # These can be VERY verbose, so we suggest turning them off 4 | # unless you really need them. 5 | debug: false 6 | 7 | # Use this to change the JavaScript version used to run your code 8 | # on Codecrafters. 9 | # 10 | # Available versions: nodejs-21 11 | language_pack: nodejs-21 12 | -------------------------------------------------------------------------------- /solutions/javascript/01-cq2/code/package-lock.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "name": "@codecrafters/build-your-own-grep", 4 | "version": "1.0.0", 5 | "lockfileVersion": 3, 6 | "requires": true, 7 | "packages": { 8 | "": { 9 | "name": "@codecrafters/build-your-own-grep", 10 | "version": "1.0.0", 11 | "license": "MIT" 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /solutions/javascript/01-cq2/code/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@codecrafters/build-your-own-grep", 3 | "version": "1.0.0", 4 | "description": "Build your own Grep challenge, from CodeCrafters", 5 | "main": "main.js", 6 | "scripts": { 7 | "dev": "node app/main.js" 8 | }, 9 | "keywords": [ 10 | "build-your-own-x" 11 | ], 12 | "author": "", 13 | "license": "MIT", 14 | "dependencies": {} 15 | } -------------------------------------------------------------------------------- /solutions/javascript/01-cq2/code/your_program.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Use this script to run your program LOCALLY. 4 | # 5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program. 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit early if any commands fail 10 | 11 | # Copied from .codecrafters/run.sh 12 | # 13 | # - Edit this to change how your program runs locally 14 | # - Edit .codecrafters/run.sh to change how your program runs remotely 15 | exec node app/main.js "$@" 16 | -------------------------------------------------------------------------------- /solutions/javascript/01-cq2/diff/app/main.js.diff: -------------------------------------------------------------------------------- 1 | @@ -1,29 +1,25 @@ 2 | function matchPattern(inputLine, pattern) { 3 | if (pattern.length === 1) { 4 | return inputLine.includes(pattern); 5 | } else { 6 | throw new Error(`Unhandled pattern ${pattern}`); 7 | } 8 | } 9 | 10 | function main() { 11 | const pattern = process.argv[3]; 12 | const inputLine = require("fs").readFileSync(0, "utf-8").trim(); 13 | 14 | if (process.argv[2] !== "-E") { 15 | console.log("Expected first argument to be '-E'"); 16 | process.exit(1); 17 | } 18 | 19 | - // You can use print statements as follows for debugging, they'll be visible when running tests. 20 | - console.error("Logs from your program will appear here"); 21 | - 22 | - // Uncomment this block to pass the first stage 23 | - // if (matchPattern(inputLine, pattern)) { 24 | - // process.exit(0); 25 | - // } else { 26 | - // process.exit(1); 27 | - // } 28 | + if (matchPattern(inputLine, pattern)) { 29 | + process.exit(0); 30 | + } else { 31 | + process.exit(1); 32 | + } 33 | } 34 | 35 | main(); 36 | -------------------------------------------------------------------------------- /solutions/javascript/01-cq2/explanation.md: -------------------------------------------------------------------------------- 1 | The entry point for your grep implementation is in `app/main.js`. 2 | 3 | Study and uncomment the relevant code: 4 | 5 | ```javascript 6 | // Uncomment this block to pass the first stage 7 | if (matchPattern(inputLine, pattern)) { 8 | process.exit(0); 9 | } else { 10 | process.exit(1); 11 | } 12 | ``` 13 | 14 | Push your changes to pass the first stage: 15 | 16 | ``` 17 | git add . 18 | git commit -m "pass 1st stage" # any msg 19 | git push origin master 20 | ``` 21 | -------------------------------------------------------------------------------- /solutions/kotlin/01-cq2/code/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | mvn -B package -Ddir=/tmp/codecrafters-build-grep-kotlin 12 | -------------------------------------------------------------------------------- /solutions/kotlin/01-cq2/code/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec java -jar /tmp/codecrafters-build-grep-kotlin/build-your-own-grep.jar "$@" 12 | -------------------------------------------------------------------------------- /solutions/kotlin/01-cq2/code/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /solutions/kotlin/01-cq2/code/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .idea/ -------------------------------------------------------------------------------- /solutions/kotlin/01-cq2/code/codecrafters.yml: -------------------------------------------------------------------------------- 1 | # Set this to true if you want debug logs. 2 | # 3 | # These can be VERY verbose, so we suggest turning them off 4 | # unless you really need them. 5 | debug: false 6 | 7 | # Use this to change the Kotlin version used to run your code 8 | # on Codecrafters. 9 | # 10 | # Available versions: kotlin-2.0 11 | language_pack: kotlin-2.0 12 | -------------------------------------------------------------------------------- /solutions/kotlin/01-cq2/code/src/main/kotlin/Main.kt: -------------------------------------------------------------------------------- 1 | import kotlin.system.exitProcess 2 | 3 | fun main(args: Array) { 4 | if (args.size != 2 || args[0] != "-E") { 5 | println("Usage: ./your_program.sh -E ") 6 | exitProcess(1) 7 | } 8 | 9 | val pattern = args[1] 10 | val inputLine = System.`in`.bufferedReader().readText() 11 | 12 | if (matchPattern(inputLine, pattern)) { 13 | exitProcess(0) 14 | } else { 15 | exitProcess(1) 16 | } 17 | } 18 | 19 | fun matchPattern(inputLine: String, pattern: String): Boolean { 20 | return if (pattern.length == 1) { 21 | pattern in inputLine 22 | } else { 23 | throw RuntimeException("Unhandled pattern: $pattern") 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /solutions/kotlin/01-cq2/code/your_program.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Use this script to run your program LOCALLY. 4 | # 5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program. 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit early if any commands fail 10 | 11 | # Copied from .codecrafters/compile.sh 12 | # 13 | # - Edit this to change how your program compiles locally 14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely 15 | ( 16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory 17 | mvn -B package -Ddir=/tmp/codecrafters-build-grep-kotlin 18 | ) 19 | 20 | # Copied from .codecrafters/run.sh 21 | # 22 | # - Edit this to change how your program runs locally 23 | # - Edit .codecrafters/run.sh to change how your program runs remotely 24 | exec java -jar /tmp/codecrafters-build-grep-kotlin/build-your-own-grep.jar "$@" 25 | -------------------------------------------------------------------------------- /solutions/kotlin/01-cq2/diff/src/main/kotlin/Main.kt.diff: -------------------------------------------------------------------------------- 1 | @@ -1,29 +1,25 @@ 2 | import kotlin.system.exitProcess 3 | 4 | fun main(args: Array) { 5 | if (args.size != 2 || args[0] != "-E") { 6 | println("Usage: ./your_program.sh -E ") 7 | exitProcess(1) 8 | } 9 | 10 | val pattern = args[1] 11 | val inputLine = System.`in`.bufferedReader().readText() 12 | 13 | - // You can use print statements as follows for debugging, they'll be visible when running tests. 14 | - System.err.println("Logs from your program will appear here!") 15 | - 16 | - // Uncomment this block to pass the first stage 17 | - // if (matchPattern(inputLine, pattern)) { 18 | - // exitProcess(0) 19 | - // } else { 20 | - // exitProcess(1) 21 | - // } 22 | + if (matchPattern(inputLine, pattern)) { 23 | + exitProcess(0) 24 | + } else { 25 | + exitProcess(1) 26 | + } 27 | } 28 | 29 | fun matchPattern(inputLine: String, pattern: String): Boolean { 30 | return if (pattern.length == 1) { 31 | pattern in inputLine 32 | } else { 33 | throw RuntimeException("Unhandled pattern: $pattern") 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /solutions/kotlin/01-cq2/explanation.md: -------------------------------------------------------------------------------- 1 | The entry point for your grep implementation is in `src/main/kotlin/Main.kt`. 2 | 3 | Study and uncomment the relevant code: 4 | 5 | ```kotlin 6 | // Uncomment this block to pass the first stage 7 | if (matchPattern(inputLine, pattern)) { 8 | exitProcess(0) 9 | } else { 10 | exitProcess(1) 11 | } 12 | ``` 13 | 14 | Push your changes to pass the first stage: 15 | 16 | ``` 17 | git add . 18 | git commit -m "pass 1st stage" # any msg 19 | git push origin master 20 | ``` 21 | -------------------------------------------------------------------------------- /solutions/php/01-cq2/code/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | # (This file is empty since PHP programs don't use a compile step) -------------------------------------------------------------------------------- /solutions/php/01-cq2/code/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec php app/main.php "$@" 12 | -------------------------------------------------------------------------------- /solutions/php/01-cq2/code/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /solutions/php/01-cq2/code/app/main.php: -------------------------------------------------------------------------------- 1 | "] 5 | edition = "2021" 6 | rust-version = "1.80" 7 | 8 | [dependencies] 9 | anyhow = "1.0.68" # error handling 10 | bytes = "1.3.0" # helps manage buffers 11 | thiserror = "1.0.38" # error handling 12 | -------------------------------------------------------------------------------- /solutions/rust/01-cq2/code/codecrafters.yml: -------------------------------------------------------------------------------- 1 | # Set this to true if you want debug logs. 2 | # 3 | # These can be VERY verbose, so we suggest turning them off 4 | # unless you really need them. 5 | debug: false 6 | 7 | # Use this to change the Rust version used to run your code 8 | # on Codecrafters. 9 | # 10 | # Available versions: rust-1.86 11 | language_pack: rust-1.86 12 | -------------------------------------------------------------------------------- /solutions/rust/01-cq2/code/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | use std::io; 3 | use std::process; 4 | 5 | fn match_pattern(input_line: &str, pattern: &str) -> bool { 6 | if pattern.chars().count() == 1 { 7 | return input_line.contains(pattern); 8 | } else { 9 | panic!("Unhandled pattern: {}", pattern) 10 | } 11 | } 12 | 13 | // Usage: echo | your_program.sh -E 14 | fn main() { 15 | if env::args().nth(1).unwrap() != "-E" { 16 | println!("Expected first argument to be '-E'"); 17 | process::exit(1); 18 | } 19 | 20 | let pattern = env::args().nth(2).unwrap(); 21 | let mut input_line = String::new(); 22 | 23 | io::stdin().read_line(&mut input_line).unwrap(); 24 | 25 | if match_pattern(&input_line, &pattern) { 26 | process::exit(0) 27 | } else { 28 | process::exit(1) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /solutions/rust/01-cq2/code/your_program.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Use this script to run your program LOCALLY. 4 | # 5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program. 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit early if any commands fail 10 | 11 | # Copied from .codecrafters/compile.sh 12 | # 13 | # - Edit this to change how your program compiles locally 14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely 15 | ( 16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory 17 | cargo build --release --target-dir=/tmp/codecrafters-build-grep-rust --manifest-path Cargo.toml 18 | ) 19 | 20 | # Copied from .codecrafters/run.sh 21 | # 22 | # - Edit this to change how your program runs locally 23 | # - Edit .codecrafters/run.sh to change how your program runs remotely 24 | exec /tmp/codecrafters-build-grep-rust/release/codecrafters-grep "$@" 25 | -------------------------------------------------------------------------------- /solutions/rust/01-cq2/diff/src/main.rs.diff: -------------------------------------------------------------------------------- 1 | @@ -1,34 +1,30 @@ 2 | use std::env; 3 | use std::io; 4 | use std::process; 5 | 6 | fn match_pattern(input_line: &str, pattern: &str) -> bool { 7 | if pattern.chars().count() == 1 { 8 | return input_line.contains(pattern); 9 | } else { 10 | panic!("Unhandled pattern: {}", pattern) 11 | } 12 | } 13 | 14 | // Usage: echo | your_program.sh -E 15 | fn main() { 16 | - // You can use print statements as follows for debugging, they'll be visible when running tests. 17 | - eprintln!("Logs from your program will appear here!"); 18 | - 19 | if env::args().nth(1).unwrap() != "-E" { 20 | println!("Expected first argument to be '-E'"); 21 | process::exit(1); 22 | } 23 | 24 | let pattern = env::args().nth(2).unwrap(); 25 | let mut input_line = String::new(); 26 | 27 | io::stdin().read_line(&mut input_line).unwrap(); 28 | 29 | - // Uncomment this block to pass the first stage 30 | - // if match_pattern(&input_line, &pattern) { 31 | - // process::exit(0) 32 | - // } else { 33 | - // process::exit(1) 34 | - // } 35 | + if match_pattern(&input_line, &pattern) { 36 | + process::exit(0) 37 | + } else { 38 | + process::exit(1) 39 | + } 40 | } 41 | -------------------------------------------------------------------------------- /solutions/rust/01-cq2/explanation.md: -------------------------------------------------------------------------------- 1 | The entry point for your grep implementation is in `src/main.rs`. 2 | 3 | Study and uncomment the relevant code: 4 | 5 | ```rust 6 | // Uncomment this block to pass the first stage 7 | if match_pattern(&input_line, &pattern) { 8 | process::exit(0) 9 | } else { 10 | process::exit(1) 11 | } 12 | ``` 13 | 14 | Push your changes to pass the first stage: 15 | 16 | ``` 17 | git add . 18 | git commit -m "pass 1st stage" # any msg 19 | git push origin master 20 | ``` 21 | -------------------------------------------------------------------------------- /solutions/typescript/01-cq2/code/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | # (This file is empty since TypeScript programs don't use a compile step) 12 | -------------------------------------------------------------------------------- /solutions/typescript/01-cq2/code/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec bun run $(dirname $0)/app/main.ts "$@" 12 | -------------------------------------------------------------------------------- /solutions/typescript/01-cq2/code/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /solutions/typescript/01-cq2/code/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /solutions/typescript/01-cq2/code/app/main.ts: -------------------------------------------------------------------------------- 1 | const args = process.argv; 2 | const pattern = args[3]; 3 | 4 | const inputLine: string = await Bun.stdin.text(); 5 | 6 | function matchPattern(inputLine: string, pattern: string): boolean { 7 | if (pattern.length === 1) { 8 | return inputLine.includes(pattern); 9 | } else { 10 | throw new Error(`Unhandled pattern: ${pattern}`); 11 | } 12 | } 13 | 14 | if (args[2] !== "-E") { 15 | console.log("Expected first argument to be '-E'"); 16 | process.exit(1); 17 | } 18 | 19 | if (matchPattern(inputLine, pattern)) { 20 | process.exit(0); 21 | } else { 22 | process.exit(1); 23 | } 24 | -------------------------------------------------------------------------------- /solutions/typescript/01-cq2/code/bun.lockb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codecrafters-io/build-your-own-grep/05cb8cdb45b2e3f0b39762f7077146c0f3ff32d7/solutions/typescript/01-cq2/code/bun.lockb -------------------------------------------------------------------------------- /solutions/typescript/01-cq2/code/codecrafters.yml: -------------------------------------------------------------------------------- 1 | # Set this to true if you want debug logs. 2 | # 3 | # These can be VERY verbose, so we suggest turning them off 4 | # unless you really need them. 5 | debug: false 6 | 7 | # Use this to change the TypeScript version used to run your code 8 | # on Codecrafters. 9 | # 10 | # Available versions: bun-1.2 11 | language_pack: bun-1.2 12 | -------------------------------------------------------------------------------- /solutions/typescript/01-cq2/code/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@codecrafters/grep", 3 | "description": "Build your own grep challenge, from CodeCrafters", 4 | "type": "module", 5 | "scripts": { 6 | "dev": "bun run app/main.ts" 7 | }, 8 | "devDependencies": { 9 | "@types/bun": "latest" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /solutions/typescript/01-cq2/code/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | // Enable latest features 4 | "lib": ["ESNext", "DOM"], 5 | "target": "ESNext", 6 | "module": "ESNext", 7 | "moduleDetection": "force", 8 | "jsx": "react-jsx", 9 | "allowJs": true, 10 | 11 | // Bundler mode 12 | "moduleResolution": "bundler", 13 | "allowImportingTsExtensions": true, 14 | "verbatimModuleSyntax": true, 15 | "noEmit": true, 16 | 17 | // Best practices 18 | "strict": true, 19 | "skipLibCheck": true, 20 | "noFallthroughCasesInSwitch": true, 21 | 22 | // Some stricter flags (disabled by default) 23 | "noUnusedLocals": false, 24 | "noUnusedParameters": false, 25 | "noPropertyAccessFromIndexSignature": false 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /solutions/typescript/01-cq2/code/your_program.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Use this script to run your program LOCALLY. 4 | # 5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program. 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit early if any commands fail 10 | 11 | # Copied from .codecrafters/run.sh 12 | # 13 | # - Edit this to change how your program runs locally 14 | # - Edit .codecrafters/run.sh to change how your program runs remotely 15 | exec bun run $(dirname $0)/app/main.ts "$@" 16 | -------------------------------------------------------------------------------- /solutions/typescript/01-cq2/diff/app/main.ts.diff: -------------------------------------------------------------------------------- 1 | @@ -1,27 +1,23 @@ 2 | const args = process.argv; 3 | const pattern = args[3]; 4 | 5 | const inputLine: string = await Bun.stdin.text(); 6 | 7 | function matchPattern(inputLine: string, pattern: string): boolean { 8 | if (pattern.length === 1) { 9 | return inputLine.includes(pattern); 10 | } else { 11 | throw new Error(`Unhandled pattern: ${pattern}`); 12 | } 13 | } 14 | 15 | if (args[2] !== "-E") { 16 | console.log("Expected first argument to be '-E'"); 17 | process.exit(1); 18 | } 19 | 20 | -// You can use print statements as follows for debugging, they'll be visible when running tests. 21 | -console.error("Logs from your program will appear here!"); 22 | - 23 | -// Uncomment this block to pass the first stage 24 | -// if (matchPattern(inputLine, pattern)) { 25 | -// process.exit(0); 26 | -// } else { 27 | -// process.exit(1); 28 | -// } 29 | +if (matchPattern(inputLine, pattern)) { 30 | + process.exit(0); 31 | +} else { 32 | + process.exit(1); 33 | +} 34 | -------------------------------------------------------------------------------- /solutions/typescript/01-cq2/explanation.md: -------------------------------------------------------------------------------- 1 | The entry point for your grep implementation is in `app/main.ts`. 2 | 3 | Study and uncomment the relevant code: 4 | 5 | ```typescript 6 | // Uncomment this block to pass the first stage 7 | if (matchPattern(inputLine, pattern)) { 8 | process.exit(0); 9 | } else { 10 | process.exit(1); 11 | } 12 | ``` 13 | 14 | Push your changes to pass the first stage: 15 | 16 | ``` 17 | git add . 18 | git commit -m "pass 1st stage" # any msg 19 | git push origin master 20 | ``` 21 | -------------------------------------------------------------------------------- /solutions/zig/01-cq2/code/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | zig build 12 | -------------------------------------------------------------------------------- /solutions/zig/01-cq2/code/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec "$(dirname "$0")"/zig-out/bin/main "$@" 12 | -------------------------------------------------------------------------------- /solutions/zig/01-cq2/code/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /solutions/zig/01-cq2/code/.gitignore: -------------------------------------------------------------------------------- 1 | # Zig build artifacts 2 | main 3 | zig-cache/ 4 | .zig-cache/ 5 | zig-out/ 6 | 7 | # Compiled binary output 8 | bin/ 9 | !bin/.gitkeep 10 | 11 | # Ignore any .o or .h files generated during build 12 | *.o 13 | *.h 14 | 15 | # Ignore OS and editor specific files 16 | **/.DS_Store 17 | *.swp 18 | *~ 19 | -------------------------------------------------------------------------------- /solutions/zig/01-cq2/code/codecrafters.yml: -------------------------------------------------------------------------------- 1 | # Set this to true if you want debug logs. 2 | # 3 | # These can be VERY verbose, so we suggest turning them off 4 | # unless you really need them. 5 | debug: false 6 | 7 | # Use this to change the Zig version used to run your code 8 | # on Codecrafters. 9 | # 10 | # Available versions: zig-0.14 11 | language_pack: zig-0.14 12 | -------------------------------------------------------------------------------- /solutions/zig/01-cq2/code/src/main.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | 3 | fn matchPattern(input_line: []const u8, pattern: []const u8) bool { 4 | if (pattern.len == 1) { 5 | return std.mem.indexOf(u8, input_line, pattern) != null; 6 | } else { 7 | @panic("Unhandled pattern"); 8 | } 9 | } 10 | 11 | pub fn main() !void { 12 | var buffer: [1024]u8 = undefined; 13 | var fba = std.heap.FixedBufferAllocator.init(&buffer); 14 | const allocator = fba.allocator(); 15 | 16 | const args = try std.process.argsAlloc(allocator); 17 | defer std.process.argsFree(allocator, args); 18 | 19 | if (args.len < 3 or !std.mem.eql(u8, args[1], "-E")) { 20 | std.debug.print("Expected first argument to be '-E'\n", .{}); 21 | std.process.exit(1); 22 | } 23 | 24 | const pattern = args[2]; 25 | var input_line: [1024]u8 = undefined; 26 | const input_len = try std.io.getStdIn().reader().read(&input_line); 27 | const input_slice = input_line[0..input_len]; 28 | if (matchPattern(input_slice, pattern)) { 29 | std.process.exit(0); 30 | } else { 31 | std.process.exit(1); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /solutions/zig/01-cq2/code/your_program.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Use this script to run your program LOCALLY. 4 | # 5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program. 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit early if any commands fail 10 | 11 | # Copied from .codecrafters/compile.sh 12 | # 13 | # - Edit this to change how your program compiles locally 14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely 15 | ( 16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory 17 | zig build 18 | ) 19 | 20 | # Copied from .codecrafters/run.sh 21 | # 22 | # - Edit this to change how your program runs locally 23 | # - Edit .codecrafters/run.sh to change how your program runs remotely 24 | exec "$(dirname "$0")"/zig-out/bin/main "$@" 25 | -------------------------------------------------------------------------------- /solutions/zig/01-cq2/explanation.md: -------------------------------------------------------------------------------- 1 | The entry point for your grep implementation is in `src/main.zig`. 2 | 3 | Study and uncomment the relevant code: 4 | 5 | ```zig 6 | // Uncomment this block to pass the first stage 7 | 8 | const pattern = args[2]; 9 | var input_line: [1024]u8 = undefined; 10 | const input_len = try std.io.getStdIn().reader().read(&input_line); 11 | const input_slice = input_line[0..input_len]; 12 | if (matchPattern(input_slice, pattern)) { 13 | std.process.exit(0); 14 | } else { 15 | std.process.exit(1); 16 | } 17 | ``` 18 | 19 | Push your changes to pass the first stage: 20 | 21 | ``` 22 | git add . 23 | git commit -m "pass 1st stage" # any msg 24 | git push origin master 25 | ``` 26 | -------------------------------------------------------------------------------- /starter_templates/all/code/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /starter_templates/all/code/codecrafters.yml: -------------------------------------------------------------------------------- 1 | # Set this to true if you want debug logs. 2 | # 3 | # These can be VERY verbose, so we suggest turning them off 4 | # unless you really need them. 5 | debug: false 6 | 7 | # Use this to change the {{language_name}} version used to run your code 8 | # on Codecrafters. 9 | # 10 | # Available versions: {{language_pack_with_version}} 11 | language_pack: {{language_pack_with_version}} 12 | -------------------------------------------------------------------------------- /starter_templates/cpp/code/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake 12 | cmake --build ./build 13 | -------------------------------------------------------------------------------- /starter_templates/cpp/code/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec ./build/exe "$@" 12 | -------------------------------------------------------------------------------- /starter_templates/cpp/code/.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | server 34 | 35 | # CMake 36 | CMakeLists.txt.user 37 | CMakeCache.txt 38 | CMakeFiles 39 | CMakeScripts 40 | Testing 41 | Makefile 42 | cmake_install.cmake 43 | install_manifest.txt 44 | compile_commands.json 45 | CTestTestfile.cmake 46 | _deps 47 | 48 | build/ 49 | vcpkg_installed -------------------------------------------------------------------------------- /starter_templates/cpp/code/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | project(grep-starter-cpp) 4 | 5 | set(CMAKE_CXX_STANDARD 23) # Enable the C++23 standard 6 | 7 | file(GLOB_RECURSE SOURCE_FILES src/*.cpp src/*.hpp) 8 | 9 | add_executable(exe ${SOURCE_FILES}) -------------------------------------------------------------------------------- /starter_templates/cpp/code/vcpkg-configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "default-registry": { 3 | "kind": "git", 4 | "baseline": "c4af3593e1f1aa9e14a560a09e45ea2cb0dfd74d", 5 | "repository": "https://github.com/microsoft/vcpkg" 6 | }, 7 | "registries": [ 8 | { 9 | "kind": "artifact", 10 | "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip", 11 | "name": "microsoft" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /starter_templates/cpp/code/vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": [] 3 | } -------------------------------------------------------------------------------- /starter_templates/cpp/config.yml: -------------------------------------------------------------------------------- 1 | attributes: 2 | required_executable: cmake 3 | user_editable_file: src/Server.cpp 4 | -------------------------------------------------------------------------------- /starter_templates/csharp/code/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | dotnet build --configuration Release --output /tmp/codecrafters-build-grep-csharp codecrafters-grep.csproj 12 | -------------------------------------------------------------------------------- /starter_templates/csharp/code/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec /tmp/codecrafters-build-grep-csharp/codecrafters-grep "$@" -------------------------------------------------------------------------------- /starter_templates/csharp/code/codecrafters-grep.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | codecrafters_grep 7 | enable 8 | enable 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /starter_templates/csharp/code/codecrafters-grep.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.31903.59 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "codecrafters-grep", "codecrafters-grep.csproj", "{5647EB94-C939-4AAF-BDC4-807AA270FCF0}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(SolutionProperties) = preSolution 14 | HideSolutionNode = FALSE 15 | EndGlobalSection 16 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 17 | {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 18 | {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Debug|Any CPU.Build.0 = Debug|Any CPU 19 | {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Release|Any CPU.ActiveCfg = Release|Any CPU 20 | {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Release|Any CPU.Build.0 = Release|Any CPU 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /starter_templates/csharp/code/src/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | static bool MatchPattern(string inputLine, string pattern) 5 | { 6 | if (pattern.Length == 1) 7 | { 8 | return inputLine.Contains(pattern); 9 | } 10 | else 11 | { 12 | throw new ArgumentException($"Unhandled pattern: {pattern}"); 13 | } 14 | } 15 | 16 | if (args[0] != "-E") 17 | { 18 | Console.WriteLine("Expected first argument to be '-E'"); 19 | Environment.Exit(2); 20 | } 21 | 22 | string pattern = args[1]; 23 | string inputLine = Console.In.ReadToEnd(); 24 | 25 | // You can use print statements as follows for debugging, they'll be visible when running tests. 26 | Console.Error.WriteLine("Logs from your program will appear here!"); 27 | 28 | // Uncomment this block to pass the first stage 29 | // 30 | // if (MatchPattern(inputLine, pattern)) 31 | // { 32 | // Environment.Exit(0); 33 | // } 34 | // else 35 | // { 36 | // Environment.Exit(1); 37 | // } 38 | -------------------------------------------------------------------------------- /starter_templates/csharp/config.yml: -------------------------------------------------------------------------------- 1 | attributes: 2 | required_executable: dotnet (9.0) 3 | user_editable_file: src/Program.cs 4 | -------------------------------------------------------------------------------- /starter_templates/gleam/code/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | gleam build 12 | -------------------------------------------------------------------------------- /starter_templates/gleam/code/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec gleam run --module main -- "$@" 12 | -------------------------------------------------------------------------------- /starter_templates/gleam/code/.gitignore: -------------------------------------------------------------------------------- 1 | *.beam 2 | *.ez 3 | /build 4 | erl_crash.dump 5 | -------------------------------------------------------------------------------- /starter_templates/gleam/code/gleam.toml: -------------------------------------------------------------------------------- 1 | name = "codecrafters_grep" 2 | version = "1.0.0" 3 | 4 | # For a full reference of all the available options, you can have a look at 5 | # https://gleam.run/writing-gleam/gleam-toml/. 6 | 7 | [dependencies] 8 | argv = ">= 1.0.2 and < 2.0.0" 9 | gleam_erlang = "~> 0.25" 10 | gleam_stdlib = "~> 0.34 or ~> 1.0" 11 | 12 | [dev-dependencies] 13 | gleeunit = "~> 1.0" -------------------------------------------------------------------------------- /starter_templates/gleam/code/manifest.toml: -------------------------------------------------------------------------------- 1 | # This file was generated by Gleam 2 | # You typically do not need to edit this file 3 | 4 | packages = [ 5 | { name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" }, 6 | { name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" }, 7 | { name = "gleam_stdlib", version = "0.38.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "663CF11861179AF415A625307447775C09404E752FF99A24E2057C835319F1BE" }, 8 | { name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" }, 9 | ] 10 | 11 | [requirements] 12 | argv = { version = ">= 1.0.2 and < 2.0.0" } 13 | gleam_erlang = { version = "~> 0.25" } 14 | gleam_stdlib = { version = "~> 0.34 or ~> 1.0" } 15 | gleeunit = { version = "~> 1.0" } 16 | -------------------------------------------------------------------------------- /starter_templates/gleam/code/src/main.gleam: -------------------------------------------------------------------------------- 1 | import argv 2 | import gleam/erlang 3 | import gleam/io 4 | import gleam/string 5 | 6 | pub fn main() { 7 | // You can use print statements as follows for debugging, they'll be visible when running tests. 8 | io.print_error("Logs from your program will appear here!") 9 | 10 | let args = argv.load().arguments 11 | let assert Ok(input_line) = erlang.get_line("") 12 | 13 | // Uncomment this to pass the first stage 14 | // case args { 15 | // ["-E", pattern, ..] -> { 16 | // case match_pattern(input_line, pattern) { 17 | // True -> exit(0) 18 | // False -> exit(1) 19 | // } 20 | // } 21 | // _ -> { 22 | // io.println("Expected first argument to be '-E'") 23 | // exit(1) 24 | // } 25 | // } 26 | } 27 | 28 | fn match_pattern(input_line: String, pattern: String) -> Bool { 29 | case string.length(pattern) { 30 | 1 -> string.contains(input_line, pattern) 31 | _ -> { 32 | io.println("Unhandled pattern: " <> pattern) 33 | False 34 | } 35 | } 36 | } 37 | 38 | @external(erlang, "erlang", "halt") 39 | pub fn exit(code: Int) -> Int 40 | -------------------------------------------------------------------------------- /starter_templates/gleam/config.yml: -------------------------------------------------------------------------------- 1 | attributes: 2 | required_executable: gleam (1.9.1) 3 | user_editable_file: src/main.gleam 4 | -------------------------------------------------------------------------------- /starter_templates/go/code/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | go build -o /tmp/codecrafters-build-grep-go app/*.go 12 | -------------------------------------------------------------------------------- /starter_templates/go/code/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec /tmp/codecrafters-build-grep-go "$@" 12 | -------------------------------------------------------------------------------- /starter_templates/go/code/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/codecrafters-io/grep-starter-go 2 | 3 | go 1.24.0 4 | -------------------------------------------------------------------------------- /starter_templates/go/code/go.sum: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codecrafters-io/build-your-own-grep/05cb8cdb45b2e3f0b39762f7077146c0f3ff32d7/starter_templates/go/code/go.sum -------------------------------------------------------------------------------- /starter_templates/go/config.yml: -------------------------------------------------------------------------------- 1 | attributes: 2 | required_executable: go (1.24) 3 | user_editable_file: app/main.go 4 | -------------------------------------------------------------------------------- /starter_templates/haskell/code/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | # This compiles the program into $(stack path --local-install-root)/bin/codecrafters-grep-exe. 12 | stack build 13 | -------------------------------------------------------------------------------- /starter_templates/haskell/code/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec $(stack path --local-install-root)/bin/codecrafters-grep-exe "$@" -------------------------------------------------------------------------------- /starter_templates/haskell/code/.gitignore: -------------------------------------------------------------------------------- 1 | codecrafters-grep.cabal 2 | *~ 3 | dist 4 | dist-* 5 | cabal-dev 6 | *.o 7 | *.hi 8 | *.hie 9 | *.chi 10 | *.chs.h 11 | *.dyn_o 12 | *.dyn_hi 13 | .hpc 14 | .hsenv 15 | .cabal-sandbox/ 16 | cabal.sandbox.config 17 | *.prof 18 | *.aux 19 | *.hp 20 | *.eventlog 21 | .stack/ 22 | .stack-work/ 23 | cabal.project.local 24 | cabal.project.local~ 25 | .HTF/ 26 | .ghc.environment.* -------------------------------------------------------------------------------- /starter_templates/haskell/code/app/Main.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import System.Environment 4 | import System.Exit 5 | import System.IO (hPutStrLn, hSetBuffering, stdout, stderr, BufferMode (NoBuffering)) 6 | 7 | matchPattern :: String -> String -> Bool 8 | matchPattern pattern input = do 9 | if length pattern == 1 10 | then head pattern `elem` input 11 | else error $ "Unhandled pattern: " ++ pattern 12 | 13 | main :: IO () 14 | main = do 15 | -- Disable output buffering 16 | hSetBuffering stdout NoBuffering 17 | hSetBuffering stderr NoBuffering 18 | 19 | args <- getArgs 20 | let pattern = args !! 1 21 | input_line <- getLine 22 | 23 | -- You can use print statements as follows for debugging, they'll be visible when running tests. 24 | hPutStrLn stderr "Logs from your program will appear here" 25 | 26 | -- Uncomment this block to pass stage 1 27 | -- if head args /= "-E" 28 | -- then do 29 | -- putStrLn "Expected first argument to be '-E'" 30 | -- exitFailure 31 | -- else do if matchPattern pattern input_line 32 | -- then exitSuccess 33 | -- else exitFailure 34 | -------------------------------------------------------------------------------- /starter_templates/haskell/code/package.yaml: -------------------------------------------------------------------------------- 1 | name: codecrafters-grep 2 | version: 0.1.0.0 3 | license: BSD3 4 | 5 | dependencies: 6 | - base >= 4.19 && < 5 7 | - megaparsec # can help when implementing the parser 8 | - parser-combinators # extends megaparsec 9 | - containers # Set, Map, Seq 10 | - unordered-containers # HashSet, HashMap 11 | - hashable # when using your own data types with unordered-containers 12 | - mtl # monad transformers to help with nested monads 13 | 14 | default-extensions: 15 | - BlockArguments 16 | - ImportQualifiedPost 17 | - LambdaCase 18 | - NamedFieldPuns 19 | - RecordWildCards 20 | 21 | executables: 22 | codecrafters-grep-exe: 23 | main: Main.hs 24 | source-dirs: app 25 | ghc-options: 26 | - -threaded 27 | - -rtsopts 28 | - -with-rtsopts=-N 29 | -------------------------------------------------------------------------------- /starter_templates/haskell/code/stack.yaml: -------------------------------------------------------------------------------- 1 | resolver: lts-23.18 2 | 3 | packages: 4 | - . 5 | -------------------------------------------------------------------------------- /starter_templates/haskell/code/stack.yaml.lock: -------------------------------------------------------------------------------- 1 | # This file was autogenerated by Stack. 2 | # You should not edit this file by hand. 3 | # For more information, please see the documentation at: 4 | # https://docs.haskellstack.org/en/stable/lock_files 5 | 6 | packages: [] 7 | snapshots: 8 | - completed: 9 | sha256: d133abe75e408a407cce3f032c96ac1bbadf474a93b5156ebf4135b53382d56b 10 | size: 683827 11 | url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/23/18.yaml 12 | original: lts-23.18 13 | -------------------------------------------------------------------------------- /starter_templates/haskell/config.yml: -------------------------------------------------------------------------------- 1 | attributes: 2 | required_executable: stack (23.18) 3 | user_editable_file: app/Main.hs 4 | -------------------------------------------------------------------------------- /starter_templates/java/code/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | mvn -B package -Ddir=/tmp/codecrafters-build-grep-java 12 | -------------------------------------------------------------------------------- /starter_templates/java/code/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec java -jar /tmp/codecrafters-build-grep-java/codecrafters-grep.jar "$@" 12 | -------------------------------------------------------------------------------- /starter_templates/java/code/.gitignore: -------------------------------------------------------------------------------- 1 | *.jar 2 | target/ 3 | .idea/ 4 | -------------------------------------------------------------------------------- /starter_templates/java/code/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | import java.io.IOException; 2 | import java.util.Scanner; 3 | 4 | public class Main { 5 | public static void main(String[] args){ 6 | if (args.length != 2 || !args[0].equals("-E")) { 7 | System.out.println("Usage: ./your_program.sh -E "); 8 | System.exit(1); 9 | } 10 | 11 | String pattern = args[1]; 12 | Scanner scanner = new Scanner(System.in); 13 | String inputLine = scanner.nextLine(); 14 | 15 | // You can use print statements as follows for debugging, they'll be visible when running tests. 16 | System.err.println("Logs from your program will appear here!"); 17 | 18 | // Uncomment this block to pass the first stage 19 | // 20 | // if (matchPattern(inputLine, pattern)) { 21 | // System.exit(0); 22 | // } else { 23 | // System.exit(1); 24 | // } 25 | } 26 | 27 | public static boolean matchPattern(String inputLine, String pattern) { 28 | if (pattern.length() == 1) { 29 | return inputLine.contains(pattern); 30 | } else { 31 | throw new RuntimeException("Unhandled pattern: " + pattern); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /starter_templates/java/config.yml: -------------------------------------------------------------------------------- 1 | attributes: 2 | required_executable: mvn 3 | user_editable_file: src/main/java/Main.java 4 | -------------------------------------------------------------------------------- /starter_templates/javascript/code/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | # (This file is empty since JavaScript programs don't use a compile step) 12 | -------------------------------------------------------------------------------- /starter_templates/javascript/code/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec node app/main.js "$@" 12 | -------------------------------------------------------------------------------- /starter_templates/javascript/code/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /starter_templates/javascript/code/app/main.js: -------------------------------------------------------------------------------- 1 | function matchPattern(inputLine, pattern) { 2 | if (pattern.length === 1) { 3 | return inputLine.includes(pattern); 4 | } else { 5 | throw new Error(`Unhandled pattern ${pattern}`); 6 | } 7 | } 8 | 9 | function main() { 10 | const pattern = process.argv[3]; 11 | const inputLine = require("fs").readFileSync(0, "utf-8").trim(); 12 | 13 | if (process.argv[2] !== "-E") { 14 | console.log("Expected first argument to be '-E'"); 15 | process.exit(1); 16 | } 17 | 18 | // You can use print statements as follows for debugging, they'll be visible when running tests. 19 | console.error("Logs from your program will appear here"); 20 | 21 | // Uncomment this block to pass the first stage 22 | // if (matchPattern(inputLine, pattern)) { 23 | // process.exit(0); 24 | // } else { 25 | // process.exit(1); 26 | // } 27 | } 28 | 29 | main(); 30 | -------------------------------------------------------------------------------- /starter_templates/javascript/code/package-lock.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "name": "@codecrafters/build-your-own-grep", 4 | "version": "1.0.0", 5 | "lockfileVersion": 3, 6 | "requires": true, 7 | "packages": { 8 | "": { 9 | "name": "@codecrafters/build-your-own-grep", 10 | "version": "1.0.0", 11 | "license": "MIT" 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /starter_templates/javascript/code/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@codecrafters/build-your-own-grep", 3 | "version": "1.0.0", 4 | "description": "Build your own Grep challenge, from CodeCrafters", 5 | "main": "main.js", 6 | "scripts": { 7 | "dev": "node app/main.js" 8 | }, 9 | "keywords": [ 10 | "build-your-own-x" 11 | ], 12 | "author": "", 13 | "license": "MIT", 14 | "dependencies": {} 15 | } -------------------------------------------------------------------------------- /starter_templates/javascript/config.yml: -------------------------------------------------------------------------------- 1 | attributes: 2 | required_executable: node (21) 3 | user_editable_file: app/main.js 4 | -------------------------------------------------------------------------------- /starter_templates/kotlin/code/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | mvn -B package -Ddir=/tmp/codecrafters-build-grep-kotlin 12 | -------------------------------------------------------------------------------- /starter_templates/kotlin/code/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec java -jar /tmp/codecrafters-build-grep-kotlin/build-your-own-grep.jar "$@" 12 | -------------------------------------------------------------------------------- /starter_templates/kotlin/code/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .idea/ -------------------------------------------------------------------------------- /starter_templates/kotlin/code/src/main/kotlin/Main.kt: -------------------------------------------------------------------------------- 1 | import kotlin.system.exitProcess 2 | 3 | fun main(args: Array) { 4 | if (args.size != 2 || args[0] != "-E") { 5 | println("Usage: ./your_program.sh -E ") 6 | exitProcess(1) 7 | } 8 | 9 | val pattern = args[1] 10 | val inputLine = System.`in`.bufferedReader().readText() 11 | 12 | // You can use print statements as follows for debugging, they'll be visible when running tests. 13 | System.err.println("Logs from your program will appear here!") 14 | 15 | // Uncomment this block to pass the first stage 16 | // if (matchPattern(inputLine, pattern)) { 17 | // exitProcess(0) 18 | // } else { 19 | // exitProcess(1) 20 | // } 21 | } 22 | 23 | fun matchPattern(inputLine: String, pattern: String): Boolean { 24 | return if (pattern.length == 1) { 25 | pattern in inputLine 26 | } else { 27 | throw RuntimeException("Unhandled pattern: $pattern") 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /starter_templates/kotlin/config.yml: -------------------------------------------------------------------------------- 1 | attributes: 2 | required_executable: "kotlin (>=2.0)" 3 | user_editable_file: src/main/kotlin/Main.kt 4 | -------------------------------------------------------------------------------- /starter_templates/php/code/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | # (This file is empty since PHP programs don't use a compile step) -------------------------------------------------------------------------------- /starter_templates/php/code/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec php app/main.php "$@" 12 | -------------------------------------------------------------------------------- /starter_templates/php/code/app/main.php: -------------------------------------------------------------------------------- 1 | "] 5 | edition = "2021" 6 | rust-version = "1.80" 7 | 8 | [dependencies] 9 | anyhow = "1.0.68" # error handling 10 | bytes = "1.3.0" # helps manage buffers 11 | thiserror = "1.0.38" # error handling 12 | -------------------------------------------------------------------------------- /starter_templates/rust/code/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | use std::io; 3 | use std::process; 4 | 5 | fn match_pattern(input_line: &str, pattern: &str) -> bool { 6 | if pattern.chars().count() == 1 { 7 | return input_line.contains(pattern); 8 | } else { 9 | panic!("Unhandled pattern: {}", pattern) 10 | } 11 | } 12 | 13 | // Usage: echo | your_program.sh -E 14 | fn main() { 15 | // You can use print statements as follows for debugging, they'll be visible when running tests. 16 | eprintln!("Logs from your program will appear here!"); 17 | 18 | if env::args().nth(1).unwrap() != "-E" { 19 | println!("Expected first argument to be '-E'"); 20 | process::exit(1); 21 | } 22 | 23 | let pattern = env::args().nth(2).unwrap(); 24 | let mut input_line = String::new(); 25 | 26 | io::stdin().read_line(&mut input_line).unwrap(); 27 | 28 | // Uncomment this block to pass the first stage 29 | // if match_pattern(&input_line, &pattern) { 30 | // process::exit(0) 31 | // } else { 32 | // process::exit(1) 33 | // } 34 | } 35 | -------------------------------------------------------------------------------- /starter_templates/rust/config.yml: -------------------------------------------------------------------------------- 1 | attributes: 2 | required_executable: cargo (1.86) 3 | user_editable_file: src/main.rs 4 | -------------------------------------------------------------------------------- /starter_templates/typescript/code/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | # (This file is empty since TypeScript programs don't use a compile step) 12 | -------------------------------------------------------------------------------- /starter_templates/typescript/code/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec bun run $(dirname $0)/app/main.ts "$@" 12 | -------------------------------------------------------------------------------- /starter_templates/typescript/code/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /starter_templates/typescript/code/app/main.ts: -------------------------------------------------------------------------------- 1 | const args = process.argv; 2 | const pattern = args[3]; 3 | 4 | const inputLine: string = await Bun.stdin.text(); 5 | 6 | function matchPattern(inputLine: string, pattern: string): boolean { 7 | if (pattern.length === 1) { 8 | return inputLine.includes(pattern); 9 | } else { 10 | throw new Error(`Unhandled pattern: ${pattern}`); 11 | } 12 | } 13 | 14 | if (args[2] !== "-E") { 15 | console.log("Expected first argument to be '-E'"); 16 | process.exit(1); 17 | } 18 | 19 | // You can use print statements as follows for debugging, they'll be visible when running tests. 20 | console.error("Logs from your program will appear here!"); 21 | 22 | // Uncomment this block to pass the first stage 23 | // if (matchPattern(inputLine, pattern)) { 24 | // process.exit(0); 25 | // } else { 26 | // process.exit(1); 27 | // } 28 | -------------------------------------------------------------------------------- /starter_templates/typescript/code/bun.lockb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codecrafters-io/build-your-own-grep/05cb8cdb45b2e3f0b39762f7077146c0f3ff32d7/starter_templates/typescript/code/bun.lockb -------------------------------------------------------------------------------- /starter_templates/typescript/code/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@codecrafters/grep", 3 | "description": "Build your own grep challenge, from CodeCrafters", 4 | "type": "module", 5 | "scripts": { 6 | "dev": "bun run app/main.ts" 7 | }, 8 | "devDependencies": { 9 | "@types/bun": "latest" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /starter_templates/typescript/code/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | // Enable latest features 4 | "lib": ["ESNext", "DOM"], 5 | "target": "ESNext", 6 | "module": "ESNext", 7 | "moduleDetection": "force", 8 | "jsx": "react-jsx", 9 | "allowJs": true, 10 | 11 | // Bundler mode 12 | "moduleResolution": "bundler", 13 | "allowImportingTsExtensions": true, 14 | "verbatimModuleSyntax": true, 15 | "noEmit": true, 16 | 17 | // Best practices 18 | "strict": true, 19 | "skipLibCheck": true, 20 | "noFallthroughCasesInSwitch": true, 21 | 22 | // Some stricter flags (disabled by default) 23 | "noUnusedLocals": false, 24 | "noUnusedParameters": false, 25 | "noPropertyAccessFromIndexSignature": false 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /starter_templates/typescript/config.yml: -------------------------------------------------------------------------------- 1 | attributes: 2 | required_executable: bun (1.2) 3 | user_editable_file: app/main.ts 4 | -------------------------------------------------------------------------------- /starter_templates/zig/code/.codecrafters/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to compile your program on CodeCrafters 4 | # 5 | # This runs before .codecrafters/run.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | zig build 12 | -------------------------------------------------------------------------------- /starter_templates/zig/code/.codecrafters/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This script is used to run your program on CodeCrafters 4 | # 5 | # This runs after .codecrafters/compile.sh 6 | # 7 | # Learn more: https://codecrafters.io/program-interface 8 | 9 | set -e # Exit on failure 10 | 11 | exec "$(dirname "$0")"/zig-out/bin/main "$@" 12 | -------------------------------------------------------------------------------- /starter_templates/zig/code/.gitignore: -------------------------------------------------------------------------------- 1 | # Zig build artifacts 2 | main 3 | zig-cache/ 4 | .zig-cache/ 5 | zig-out/ 6 | 7 | # Compiled binary output 8 | bin/ 9 | !bin/.gitkeep 10 | 11 | # Ignore any .o or .h files generated during build 12 | *.o 13 | *.h 14 | 15 | # Ignore OS and editor specific files 16 | **/.DS_Store 17 | *.swp 18 | *~ 19 | -------------------------------------------------------------------------------- /starter_templates/zig/config.yml: -------------------------------------------------------------------------------- 1 | attributes: 2 | required_executable: zig (0.14) 3 | user_editable_file: src/main.zig 4 | --------------------------------------------------------------------------------