Count values in two groups.

group counts Grouping routes each value into one of several buckets.

Group Counts

cutoff
group_counts.lua
Replay: real traced execution (multi-file project)
local cutoff = 5
local small = 0
local large = 0

for _, value in ipairs({2, 5, 8}) do
  if value < cutoff then
    small = small + 1
  else
    large = large + 1
  end
end

print("cutoff=" .. cutoff)
print("small=" .. small)
print("large=" .. large)
local cutoff = 4
local small = 0
local large = 0

for _, value in ipairs({2, 5, 8}) do
  if value < cutoff then
    small = small + 1
  else
    large = large + 1
  end
end

print("cutoff=" .. cutoff)
print("small=" .. small)
print("large=" .. large)
local cutoff = 7
local small = 0
local large = 0

for _, value in ipairs({2, 5, 8}) do
  if value < cutoff then
    small = small + 1
  else
    large = large + 1
  end
end

print("cutoff=" .. cutoff)
print("small=" .. small)
print("large=" .. large)
  1. cutoff ← 5, small ← 0, large ← 0

    1local cutoff→ 5 = 5 --@cutoff=4, 72local small→ 0 = 03local large→ 0 = 0
  2. _, value in ipairs({2, 5, 8}) do

    pass 1 of 3
    5for _1, value2 in ipairs({2, 5, 8}) do6  if value < cutoff then7    small = small + 1
    All 3 passes — pass 1 is the card above
    pass_valuecutoffsmalllarge
    11250 1
    2250 1
    3381 2
  3. small ← 1

    5for _, value in ipairs({2, 5, 8}) do6  if value2 < cutoff5 then7    small→ 1 = small + 18  else
  4. large ← 1

    pass 1 of 2
    7  small = small + 18else9  large→ 1 = large + 110end
  5. large ← 2

    pass 2 of 2
    7  small = small + 18else9  large→ 2 = large + 110end
  6. print("cutoff=" .. cutoff)

    13print("cutoff=" .. cutoff5)14print("small=" .. small1)15print("large=" .. large2)
    outputcutoff=5
    small=1
    large=2
  1. cutoff ← 4, small ← 0, large ← 0

    1local cutoff→ 4 = 42local small→ 0 = 03local large→ 0 = 0
  2. _, value in ipairs({2, 5, 8}) do

    pass 1 of 3
    5for _1, value2 in ipairs({2, 5, 8}) do6  if value < cutoff then7    small = small + 1
    All 3 passes — pass 1 is the card above
    pass_valuecutoffsmalllarge
    11240 1
    2250 1
    3381 2
  3. small ← 1

    5for _, value in ipairs({2, 5, 8}) do6  if value2 < cutoff4 then7    small→ 1 = small + 18  else
  4. large ← 1

    pass 1 of 2
    7  small = small + 18else9  large→ 1 = large + 110end
  5. large ← 2

    pass 2 of 2
    7  small = small + 18else9  large→ 2 = large + 110end
  6. print("cutoff=" .. cutoff)

    13print("cutoff=" .. cutoff4)14print("small=" .. small1)15print("large=" .. large2)
    outputcutoff=4
    small=1
    large=2
  1. cutoff ← 7, small ← 0, large ← 0

    1local cutoff→ 7 = 72local small→ 0 = 03local large→ 0 = 0
  2. _, value in ipairs({2, 5, 8}) do

    pass 1 of 3
    5for _1, value2 in ipairs({2, 5, 8}) do6  if value < cutoff then7    small = small + 1
    All 3 passes — pass 1 is the card above
    pass_valuecutoffsmalllarge
    11270 1
    22571 2
    3380 1
  3. small ← 1

    pass 1 of 2
    5for _, value in ipairs({2, 5, 8}) do6  if value2 < cutoff7 then7    small→ 1 = small + 18  else
  4. small ← 2

    pass 2 of 2
    5for _, value in ipairs({2, 5, 8}) do6  if value5 < cutoff7 then7    small→ 2 = small + 18  else
  5. large ← 1

    7  small = small + 18else9  large→ 1 = large + 110end
  6. print("cutoff=" .. cutoff)

    13print("cutoff=" .. cutoff7)14print("small=" .. small2)15print("large=" .. large1)
    outputcutoff=7
    small=2
    large=1