rlopzc/protohackers_zig
Solving protohackers.com problems with Zig
refsI'm solving the protohackers in Zig to learn more about networking and continue learning Zig.
Each problem has it's corresponding file in src, e.g. src/01_smoke_test.zig. The common logic is extracted in
different files, e.g. src/tcp_server.zig.
I used CLI arguments to run a specific problem. To run the smoke test, run:
# Smoke test
zig build run -- 00
# Prime time
zig build run -- 01
I dockerized this project to be run in any server. The images are exposed in Github Container Registry here.
Building the images:
docker buildx build --platform linux/arm64,linux/amd64 -t ghcr.io/rlopzc/protohackers_zig:latest --push .
Create a server in a cloud provider (I used Hetzner)
Pull the image. You can either pull the latest, which should contain most solutions, or a specific tag with a solution.
docker pull ghcr.io/rlopzc/protohackers_zig:0_smoke
# or
docker pull ghcr.io/rlopzc/protohackers_zig:latest
Run the image. Remember to pass the problem number as an argument.
docker run --rm --name protohackers_zig -p 3000:3000 --init ghcr.io/rlopzc/protohackers_zig:latest 00
Run the protohacker test using their website!