Zig

Zig Practice

Learn Zig the way firmware is written: explicit integer widths and truncating division, switches over ranges, slices into a caller's buffer with no allocator, and one controller that turns a batch of raw sensor readings into a decision.

zigZig
Module 1

Values, Control Flow & Slices

Learn how to choose explicit integer widths, divide with truncation, switch over ranges, and pass slices through a caller's buffer with no allocator.

4
About this challenge

Convert a 12-bit ADC reading into tenths of a degree Celsius by widening before multiplying, and into Fahrenheit tenths with signed division that truncates toward zero.

About this challenge

Band a reading into cold, normal, hot or critical with a switch over ranges, and find the longest consecutive run of readings in one state so a single noisy sample cannot sound the alarm.

About this challenge

Copy the most recent readings into a caller-owned buffer and return the filled part of it, and report the batch's lowest and highest reading as an optional.

About this challenge

Turn one batch of raw ADC readings into a single cycle decision: current and average temperature, Fahrenheit, extremes, state, the recent window written into the caller's buffer, the heater call and the alarm.

Module 2

Functions, Bytes & Text

Learn how to slice text into a caller's buffer with no allocator, exclusive-or bytes and read hex by hand, parse decimals into optionals, and compose all three into one report.

4
About this challenge

Split a GPS NMEA sentence into comma-separated slices of itself inside a caller's buffer, dropping the dollar and checksum suffix and keeping empty fields.

About this challenge

Validate an NMEA sentence: exclusive-or the bytes it covers, read hex digits in either case, and reject a wrong or malformed checksum suffix.

About this challenge

Read the GPS speed field as tenths by hand, reject anything malformed or oversized, convert knots to km/h with integer arithmetic and label it into a caller's buffer.

About this challenge

Summarise a batch of GPS sentences: corrupted counts, valid counts, whether the last RMC had a fix, the highest speed and the last speed labelled into a caller's buffer.

Frequently asked questions

4

What will I practice in this path?

2 modules: Values, Control Flow & Slices and Functions, Bytes & Text.

How many challenges are there, and how hard are they?

8 challenges, all easy.

What does this path run on?

Challenges run on Zig.

Do I need to install anything?

No. Every challenge runs in a browser-based IDE with everything already set up, and your code is graded automatically against a test suite.

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.