Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiled_starters/zig/codecrafters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ debug: false
# Use this to change the Zig version used to run your code
# on Codecrafters.
#
# Available versions: zig-0.15
buildpack: zig-0.15
# Available versions: zig-0.15.2
buildpack: zig-0.15.2
11 changes: 6 additions & 5 deletions compiled_starters/zig/src/main.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const std = @import("std");
var stdin = std.fs.File.stdin().readerStreaming(&.{});

var stdin_buffer: [4096]u8 = undefined;
var stdin_reader = std.fs.File.stdin().readerStreaming(&stdin_buffer);
const stdin = &stdin_reader.interface;

fn matchPattern(input_line: []const u8, pattern: []const u8) bool {
if (pattern.len == 1) {
Expand Down Expand Up @@ -27,12 +30,10 @@ pub fn main() !void {

// TODO: Uncomment the code below to pass the first stage
//
// var input_buffer: [1024]u8 = undefined;
// const input_len = try stdin.read(&input_buffer);
// const input_slice = input_buffer[0..input_len];
// const input_slice = try stdin.takeDelimiter('\n');
//
// const pattern = args[2];
// if (matchPattern(input_slice, pattern)) {
// if (matchPattern(input_slice.?, pattern)) {
// std.process.exit(0);
// } else {
// std.process.exit(1);
Expand Down
30 changes: 30 additions & 0 deletions dockerfiles/zig-0.15.2.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# syntax=docker/dockerfile:1.7-labs
FROM debian:bookworm

RUN apt-get update && \
apt-get install --no-install-recommends -y xz-utils=5.4.1-1 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Download and install Zig
RUN curl -O https://ziglang.org/download/0.15.2/zig-x86_64-linux-0.15.2.tar.xz \
&& tar -xf zig-x86_64-linux-0.15.2.tar.xz \
&& mv zig-x86_64-linux-0.15.2 /usr/local/zig \
&& rm zig-x86_64-linux-0.15.2.tar.xz

# Add Zig to PATH
ENV PATH="/usr/local/zig:${PATH}"

ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="build.zig,build.zig.zon"

WORKDIR /app

# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
COPY --exclude=.git --exclude=README.md . /app

# This runs zig build
RUN .codecrafters/compile.sh

# Cache build directory
RUN mkdir -p /app-cached
RUN mv /app/.zig-cache /app-cached/.zig-cache || true
4 changes: 2 additions & 2 deletions solutions/zig/01-cq2/code/codecrafters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ debug: false
# Use this to change the Zig version used to run your code
# on Codecrafters.
#
# Available versions: zig-0.15
buildpack: zig-0.15
# Available versions: zig-0.15.2
buildpack: zig-0.15.2
11 changes: 6 additions & 5 deletions solutions/zig/01-cq2/code/src/main.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const std = @import("std");
var stdin = std.fs.File.stdin().readerStreaming(&.{});

var stdin_buffer: [4096]u8 = undefined;
var stdin_reader = std.fs.File.stdin().readerStreaming(&stdin_buffer);
const stdin = &stdin_reader.interface;

fn matchPattern(input_line: []const u8, pattern: []const u8) bool {
if (pattern.len == 1) {
Expand All @@ -22,12 +25,10 @@ pub fn main() !void {
std.process.exit(1);
}

var input_buffer: [1024]u8 = undefined;
const input_len = try stdin.read(&input_buffer);
const input_slice = input_buffer[0..input_len];
const input_slice = try stdin.takeDelimiter('\n');

const pattern = args[2];
if (matchPattern(input_slice, pattern)) {
if (matchPattern(input_slice.?, pattern)) {
std.process.exit(0);
} else {
std.process.exit(1);
Expand Down
19 changes: 8 additions & 11 deletions solutions/zig/01-cq2/diff/src/main.zig.diff
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@@ -1,40 +1,35 @@
const std = @import("std");
var stdin = std.fs.File.stdin().readerStreaming(&.{});
@@ -3,39 +3,34 @@
var stdin_buffer: [4096]u8 = undefined;
var stdin_reader = std.fs.File.stdin().readerStreaming(&stdin_buffer);
const stdin = &stdin_reader.interface;

fn matchPattern(input_line: []const u8, pattern: []const u8) bool {
if (pattern.len == 1) {
Expand All @@ -25,24 +26,20 @@

- // You can use print statements as follows for debugging, they'll be visible when running tests.
- std.debug.print("Logs from your program will appear here!\n", .{});
+ var input_buffer: [1024]u8 = undefined;
+ const input_len = try stdin.read(&input_buffer);
+ const input_slice = input_buffer[0..input_len];
+ const input_slice = try stdin.takeDelimiter('\n');

- // TODO: Uncomment the code below to pass the first stage
- //
- // var input_buffer: [1024]u8 = undefined;
- // const input_len = try stdin.read(&input_buffer);
- // const input_slice = input_buffer[0..input_len];
- // const input_slice = try stdin.takeDelimiter('\n');
- //
- // const pattern = args[2];
- // if (matchPattern(input_slice, pattern)) {
- // if (matchPattern(input_slice.?, pattern)) {
- // std.process.exit(0);
- // } else {
- // std.process.exit(1);
- // }
+ const pattern = args[2];
+ if (matchPattern(input_slice, pattern)) {
+ if (matchPattern(input_slice.?, pattern)) {
+ std.process.exit(0);
+ } else {
+ std.process.exit(1);
Expand Down
11 changes: 6 additions & 5 deletions starter_templates/zig/code/src/main.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const std = @import("std");
var stdin = std.fs.File.stdin().readerStreaming(&.{});

var stdin_buffer: [4096]u8 = undefined;
var stdin_reader = std.fs.File.stdin().readerStreaming(&stdin_buffer);
const stdin = &stdin_reader.interface;

fn matchPattern(input_line: []const u8, pattern: []const u8) bool {
if (pattern.len == 1) {
Expand Down Expand Up @@ -27,12 +30,10 @@ pub fn main() !void {

// TODO: Uncomment the code below to pass the first stage
//
// var input_buffer: [1024]u8 = undefined;
// const input_len = try stdin.read(&input_buffer);
// const input_slice = input_buffer[0..input_len];
// const input_slice = try stdin.takeDelimiter('\n');
//
// const pattern = args[2];
// if (matchPattern(input_slice, pattern)) {
// if (matchPattern(input_slice.?, pattern)) {
// std.process.exit(0);
// } else {
// std.process.exit(1);
Expand Down
Loading