Skip to content

Write two with-transformed array reduction constraints from scratch

write-from-scratch / array

Reduction methods (sum(), product(), and(), or(), xor()) collapse an array to one value. With with (expr), they reduce the expression’s result for each element instead of the element itself; item names the element inside the expression.

That makes sum() with a counter: arr.sum() with (item == N ? 1 : 0) is the number of elements equal to N.

Fix the class below.

RequirementsEach a constraint using sum() with (…)

  1. Exactly 2 of the 8 elements in levels equal 3.
  2. Exactly 3 of the 8 elements in levels equal 0.

Source on GitHub

array_reduction_with.sv