SpinalHDL
1 / 1
Description
Waffle Choppers
Design a hardware module for the Waffle Choppers problem.
You are given a waffle grid h, a number of horizontal cuts r, and a number of vertical cuts c.
The goal is to decide whether the waffle can be split into (r + 1) * (c + 1) rectangular pieces so that every piece contains the same number of chocolate chips.
In this repository, output:
0if such a cut placement exists1otherwise
Hardware I/O Encoding
ris a scalar unsigned 32-bit integercis a scalar unsigned 32-bit integerhis a two-dimensional stream of unsigned 32-bit integers- a nonzero cell means that position contains a chocolate chip
- each row ends when
h.fragment.lastis asserted - the whole grid ends when
h.lastis asserted - the grid has at most
8rows and at most8columns - the output is one unsigned 32-bit integer
Examples
Example 1
- input
r = 1,c = 1,h = [[1, 1], [1, 1]] - output:
0
One horizontal and one vertical cut split the waffle into four 1x1 pieces, each with one chip.
Example 2
- input
r = 0,c = 1,h = [[1, 1]] - output:
0
One vertical cut makes two pieces, each with one chip.
Example 3
- input
r = 2,c = 3,h = [[1, 0, 1], [0, 1, 0], [1, 0, 1]] - output:
1
The total number of chips is not divisible across all required pieces.
Input
r
32-bit Unsigned IntegerNumber of horizontal cuts to make.
c
32-bit Unsigned IntegerNumber of vertical cuts to make.
h
2D Array of 32-bit Unsigned Integer (up to 8 elements)Waffle grid cells, where nonzero means a chocolate chip is present.
Output
32-bit Unsigned Integer
0 if the cuts can split chips evenly across all pieces, otherwise 1.