Skip to content

Instantly share code, notes, and snippets.

@wrygiel
Created February 16, 2025 08:58
Show Gist options
  • Save wrygiel/6bdd8bf424ae23452001bb6f45c0ab2e to your computer and use it in GitHub Desktop.
Save wrygiel/6bdd8bf424ae23452001bb6f45c0ab2e to your computer and use it in GitHub Desktop.
timer T
// Inputs:
// A - current number of eggs in the chests *and* the burning inserters.
// B - number of wanted fresh eggs in the chests. (We might end up with slightly
// more than that, depending on the timing of the inserters.)
// C - maximum allowed age of eggs in the chests, in minutes. When setting
// this, remember that some eggs might get stuck in the input-inserters'
// hands, effectivelly doubling their "age before being burned" value.
// (We have no way to tell the inserters to finish inserting their current
// hand.)
//
// Outputs:
// X - 0 or 1. If 1 then burning inserts are active (the ones which empty the
// the chests). The idea is to empty all the chests so that A becomes 0.
// Y - 0 or 1. If 1 then egg producing is active. It will stop being active
// after A exceeds B.
// Initial state. Start burning.
10:
Y = 0
X = 1
=> 20
// Keep burning until all chests are empty.
20:
A == 0 => 30
// Chests just became empty.
30:
X = 0 // Stop burning.
reset T // Reset the timer to start measuring the new worst egg age.
=> 40 // Start filling them up.
// Start producing eggs and return to the main loop.
40:
Y = 1
=> 100
// Stop producing eggs and return to the main loop.
50:
Y = 0
=> 100
// The primary event loop.
100:
// If the oldest egg is deemed spoiled, burn them all.
T > C * 60 * 60 => 10
// If the number of eggs is higher than expected, stop inserting.
A > B - 1 => 50
// If the number of eggs is lower than expected, start inserting.
A < B => 40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment