Skip to content

Commit 99ca937

Browse files
authored
Merge pull request #89 from codecrafters-io/add-kotlin
Add Kotlin starter templates for the "Build Your Own grep" challenge. The templates include the necessary files for compiling and running a Kotlin program on CodeCrafters. The Main.kt file contains the entry point for the grep implementation, and the pom.xml file specifies the project dependencies and build configuration. The .codecrafters/compile.sh and .codecrafters/run.sh scripts are used for compiling and running the program on CodeCrafters. The your_program.sh script is used for running the program locally. The codecrafters.yml file specifies the language pack and debug settings. The .gitignore file excludes the target/ and .idea/ directories from version control.
2 parents 2f92264 + d1ef161 commit 99ca937

File tree

28 files changed

+671
-8
lines changed

28 files changed

+671
-8
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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 "$@"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

compiled_starters/kotlin/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target/
2+
.idea/

compiled_starters/kotlin/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/grep.png)
2+
3+
This is a starting point for Kotlin solutions to the
4+
["Build Your Own grep" Challenge](https://app.codecrafters.io/courses/grep/overview).
5+
6+
[Regular expressions](https://en.wikipedia.org/wiki/Regular_expression)
7+
(Regexes, for short) are patterns used to match character combinations in
8+
strings. [`grep`](https://en.wikipedia.org/wiki/Grep) is a CLI tool for
9+
searching using Regexes.
10+
11+
In this challenge you'll build your own implementation of `grep`. Along the way
12+
we'll learn about Regex syntax, how parsers/lexers work, and how regular
13+
expressions are evaluated.
14+
15+
**Note**: If you're viewing this repo on GitHub, head over to
16+
[codecrafters.io](https://codecrafters.io) to try the challenge.
17+
18+
# Passing the first stage
19+
20+
The entry point for your `grep` implementation is in `src/main/kotlin/Main.kt`.
21+
Study and uncomment the relevant code, and push your changes to pass the first
22+
stage:
23+
24+
```sh
25+
git add .
26+
git commit -m "pass 1st stage" # any msg
27+
git push origin master
28+
```
29+
30+
Time to move on to the next stage!
31+
32+
# Stage 2 & beyond
33+
34+
Note: This section is for stages 2 and beyond.
35+
36+
1. Ensure you have `kotlin (>=2.0)` installed locally
37+
1. Run `./your_program.sh` to run your program, which is implemented in
38+
`src/main/kotlin/Main.kt`.
39+
1. Commit your changes and run `git push origin master` to submit your solution
40+
to CodeCrafters. Test output will be streamed to your terminal.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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

compiled_starters/kotlin/pom.xml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>io.codecrafters</groupId>
8+
<artifactId>build-your-own-grep</artifactId>
9+
<version>1.0</version>
10+
11+
<properties>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
<kotlin.code.style>official</kotlin.code.style>
14+
<kotlin.compiler.jvmTarget>21</kotlin.compiler.jvmTarget>
15+
<maven.compiler.source>21</maven.compiler.source>
16+
<maven.compiler.target>21</maven.compiler.target>
17+
<java.version>21</java.version>
18+
</properties>
19+
20+
<repositories>
21+
<repository>
22+
<id>mavenCentral</id>
23+
<url>https://repo1.maven.org/maven2/</url>
24+
</repository>
25+
</repositories>
26+
27+
<dependencyManagement>
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.jetbrains.kotlin</groupId>
31+
<artifactId>kotlin-bom</artifactId>
32+
<version>2.0.0</version>
33+
<type>pom</type>
34+
<scope>import</scope>
35+
</dependency>
36+
</dependencies>
37+
</dependencyManagement>
38+
39+
40+
<build>
41+
<sourceDirectory>src/main/kotlin</sourceDirectory>
42+
<plugins>
43+
<plugin>
44+
<groupId>org.jetbrains.kotlin</groupId>
45+
<artifactId>kotlin-maven-plugin</artifactId>
46+
<version>2.0.0</version>
47+
<executions>
48+
<execution>
49+
<id>compile</id>
50+
<phase>compile</phase>
51+
<goals>
52+
<goal>compile</goal>
53+
</goals>
54+
</execution>
55+
</executions>
56+
</plugin>
57+
<plugin>
58+
<groupId>org.apache.maven.plugins</groupId>
59+
<artifactId>maven-assembly-plugin</artifactId>
60+
<configuration>
61+
<finalName>${project.artifactId}</finalName> <!-- Please do not change this final artifact name-->
62+
<descriptorRefs>
63+
<descriptorRef>jar-with-dependencies</descriptorRef>
64+
</descriptorRefs>
65+
<appendAssemblyId>false</appendAssemblyId>
66+
<archive>
67+
<manifest>
68+
<addClasspath>true</addClasspath>
69+
<!-- This is the main class of your program which will be executed-->
70+
<mainClass>MainKt</mainClass>
71+
</manifest>
72+
</archive>
73+
<outputDirectory>${dir}</outputDirectory>
74+
</configuration>
75+
76+
<executions>
77+
<execution>
78+
<id>make-assembly</id>
79+
<phase>package</phase>
80+
<goals>
81+
<goal>single</goal>
82+
</goals>
83+
</execution>
84+
</executions>
85+
</plugin>
86+
</plugins>
87+
</build>
88+
89+
<dependencies>
90+
<dependency>
91+
<groupId>org.jetbrains.kotlin</groupId>
92+
<artifactId>kotlin-stdlib</artifactId>
93+
</dependency>
94+
</dependencies>
95+
</project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import kotlin.system.exitProcess
2+
3+
fun main(args: Array<String>) {
4+
if (args.size != 2 || args[0] != "-E") {
5+
println("Usage: ./your_program.sh -E <pattern>")
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+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 "$@"

course-definition.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,18 @@ completion_percentage: 30
1717

1818
languages:
1919
- slug: "cpp"
20+
- slug: "csharp"
21+
- slug: "gleam"
2022
- slug: "go"
2123
- slug: "haskell"
22-
release_status: "beta"
2324
- slug: "javascript"
25+
- slug: "kotlin"
2426
- slug: "python"
27+
- slug: "rust"
28+
- slug: "typescript"
2529
- slug: "ruby"
2630
release_status: "alpha"
2731
alpha_tester_usernames: ["rohitpaulk", "sreeram-venkitesh"]
28-
- slug: "rust"
29-
- slug: "csharp"
30-
release_status: "beta"
31-
- slug: "typescript"
32-
release_status: "beta"
33-
- slug: "gleam"
34-
release_status: "beta"
3532

3633
marketing:
3734
difficulty: medium

0 commit comments

Comments
 (0)