// Three combinational implementations of the same total function on three bits.
module step5 #(parameter DIGIT = 1'b0) (input [2:0] r, output [2:0] y);
    wire [3:0] z = {r, DIGIT};
    wire [3:0] reduced = z >= 4'd5 ? z - 4'd5 : z;
    assign y = r < 3'd5 ? reduced[2:0] : r;
endmodule

module six(input [2:0] r, output [2:0] y);
    wire [2:0] a,b,c,d,e;
    step5 #(1'b1) s1(r,a);
    step5 #(1'b0) s2(a,b);
    step5 #(1'b1) s3(b,c);
    step5 #(1'b1) s4(c,d);
    step5 #(1'b0) s5(d,e);
    step5 #(1'b1) s6(e,y);
endmodule

module two(input [2:0] r, output [2:0] y);
    wire [2:0] a;
    step5 #(1'b0) s1(r,a);
    step5 #(1'b0) s2(a,y);
endmodule

module direct_table(input [2:0] r, output reg [2:0] y);
    always @* begin
        case (r)
            3'd0: y = 3'd0;
            3'd1: y = 3'd4;
            3'd2: y = 3'd3;
            3'd3: y = 3'd2;
            3'd4: y = 3'd1;
            default: y = r;
        endcase
    end
endmodule
