Forum Discussion

Patrick2788's avatar
Patrick2788
Silver Contributor
Oct 21, 2026

Halloween 2026 Scheduling Challenge 🎃

Happy Halloween!

You'll find the rules in the screen capture below and in the attached workbook.

 

 

Creative solutions are encouraged. Feel free to use any functions available in the Beta channel.

I won't post my solution immediately so submissions aren't influenced.

Enjoy!

1 Reply

  • djclements's avatar
    djclements
    Silver Contributor

    Thanks for the challenge. I'll bite...

    = LET(
        sch, SCAN(
            VALS3(HSTACK(available, treat)),
            SEQUENCE(SUM(ROUNDUP(available / items_per_turn, 0))),
            LAMBDA(acc,_,
                LET(
                    arr, SORTBY(acc(1), TAKE(acc(1), , 1) = 0),
                    bal, arr,
                    amt, MIN(bal, items_per_turn),
                    VALS3(SORTBY(IFNA(EXPAND(bal - amt, 2, 2), arr), rank = 1), amt, INDEX(arr, 1, 2))
                )
            )
        ),
        end, SCAN( , MAP(sch, LAMBDA(val, val(2))), SUM),
        VSTACK({"Treat","Start","Stop"}, HSTACK(MAP(sch, LAMBDA(val, val(3))), DROP(VSTACK(0, end), -1), end))
    )

    Where:

    VALS3 = LAMBDA([value1],[value2],[value3], LAMBDA(x, CHOOSE(x, value1, value2, value3)))

    It probably wouldn't perform all that great with a huge table/array of treats, due to the manipulation and indexing of the entire array at each iteration, but it works well for the dataset provided.

    A step-through is available in the attached workbook to review the accumulated items for any given iteration.

    Happy Halloween! 👻