←
Build the decisionSaved automatically
Medium · Grade 115. Cost and Reliability

Route payments using total expected cost across three online providers.

Scenario

All 3 providers are online, but differ in fees and reliability. Failures incur ₦5 penalties.

Problem statement

All three providers (A, B, C) are online, but they have different fee structures and reliability rates.

Provider A has the lowest base fee, but higher failure rates. Provider B offers the lowest overall expected cost when factoring in potential failure penalties.

Compare expected cost rather than raw base fee to keep total processing costs low.

The provider cards list calculated expected costs for A, B, and C. Provider B has the lowest expected cost.

Route through B: WHEN onlineB -> DO route-b.

What this teaches

Optimize overall cost using composite metrics (expectedCost) rather than raw fee in isolation.

Scroll down to build and test your solution.

Active controller

Apply & Run executes only the selected controller.

How a rule works

A rule has two parts:

WHEN <something is true> → DO <this action>

  • WHEN is a question about what is happening right now. For example: "Is it raining?" or "Is there a wall ahead?"
  • DO is what happens when the answer is yes.
  • The simulation runs one step at a time.
  • On each step, the rules are checked from top to bottom.
  • The first rule that is true wins. The rules below it are skipped for that step.
  • To change which rule wins, move it up or down the list.
  • If no rule is true, nothing happens on that step.
  • Some actions have more than one step, like "turn right, then move". You build these in the Functions tab.
  • Once a multi-step action starts, it finishes all its steps before the rules are checked again. It only stops early if the next step is not safe.
See an example

Two rules for deciding about an umbrella:

1  WHEN isRaining  → take an umbrella
2  WHEN always     → leave the umbrella at home
  • It is raining. Rule 1 is true, so you take an umbrella. Rule 2 is skipped.
  • It is sunny. Rule 1 is false, so rule 2 is checked next. Rule 2 is always true, so you leave the umbrella at home.
  • Order matters. If rule 2 were on top, it would be true every day, and you would never take an umbrella.

Rule folders

Categorise cards without changing their global execution order.

No rules yet. Nothing will happen until you add at least one rule.