← All problems

Divisible by 3

Medium · Sequential · SystemVerilog

Design a circuit that determines whether an input value is evenly divisible by three.

The input value is of unknown length and is left-shifted one bit at a time into the circuit via {din}. The circuit should output $1$ on {dout} if the current cumulative value is evenly divisible by three, and $0$ otherwise.

When {resetn} is asserted, all previous bits seen on the input are no longer considered. The $0$ seen during reset should not be included when calculating the next value. During reset, {dout} must be $0$.

This problem is tricky, so it may help to think in terms of modulus and remainder states.

Open this challenge in the editor →