Project P161

Subscription billing

An API plan whose quota resets on the 1st, invoiced over a cycle that starts on the billing day: a customer who never ran out of quota is billed for overage, and a steady use is over the quota in the 31-day months only.

2 modules · 2 recorded sessionstext-menu UI in the terminalupdated 2026-10-19

Every screen below was recorded under CPython. When this page was built, the EML interpreter replayed each session from the same input and printed the same bytes.

About

An API plan whose quota resets on the 1st, invoiced over a cycle that starts on the billing day, and two customers through 2027.

  • main.eml - the menu, the plan, the quota months, the invoices, the billing day, and a steady use of your own
  • billing.eml - the quota and its price, the calendar of 2027, the customers' calls day by day, the billing cycles, and what is over

How each part works:

  • The quota is 5,000,000 calls a calendar month, reset on the 1st; calls over it cost 0.40 for each 1,000 or part of 1,000. The invoice covers a cycle from the billing day to the day before it a month later.
  • As in the corpus case the-quota-renewed-monthly-and-the-billing-cycle-did-not, the two windows are both a month long and not the same month. The month-end customer runs jobs over the last 10 days of every other month and the first 14 of the next: no calendar month reaches the quota, and with the billing day on the 18th six of the eleven invoices are over it, 28,400,000 calls in all, because a cycle that holds the 1st holds two quota months and the invoice allows one. With the billing day on the 1st the cycles are the quota months and nothing is billed.
  • As in the-target-was-per-calendar-month-and-the-months-were-unequal, a monthly number is 28 to 31 days. The steady customer makes 165,000 calls every day: 4,620,000 in February, 5,115,000 in each 31-day month, over the quota in 7 of 12 months at the same use every day. A steady use stays under the quota every month up to 161,290 a day and is over it every month from 178,572.

What is checked: menu choices 1 to 6; a billing day from 1 to 28; a steady use of 1 to 999999 calls a day. An empty answer cancels.

Sessions: sessions/basic.in gives: - the plan, the quota months and the invoices with the billing day on the 18th; - the billing day moved to the 1st, and the invoices again; - steady uses of 165,000 and 170,000 calls a day.

sessions/bad-input.in gives: - menu choices 0 and x; - billing days: a cancel, 0, 29 and x; - steady uses: a cancel, 0, 1000000 and x; - steady uses of 161,290 and 161,291 calls a day, either side of the 31-day line.

Built on the verified corpus cases the-quota-renewed-monthly-and-the-billing-cycle-did-not (a quota reset on the 1st and a cycle from the 18th: two grants inside one invoice) and the-target-was-per-calendar-month-and-the-months-were-unequal (a monthly target met in July and missed in February at the same rate).

Recorded sessions

What the screen shows while someone uses the program. Each typed line appears after its prompt, the way a terminal shows it.

bad-input

interpreter: byte-equal
== Subscription billing ==
An API plan whose quota resets on the 1st, invoiced over a cycle that starts on the billing day.

1) the plan  2) quota months  3) invoices  4) billing day  5) a steady use of your own  6) quit
choice> 0
Pick a number from 1 to 6.

1) the plan  2) quota months  3) invoices  4) billing day  5) a steady use of your own  6) quit
choice> x
Pick a number from 1 to 6.

1) the plan  2) quota months  3) invoices  4) billing day  5) a steady use of your own  6) quit
choice> 4
billing day (1 to 28)> 
Cancelled.

1) the plan  2) quota months  3) invoices  4) billing day  5) a steady use of your own  6) quit
choice> 4
billing day (1 to 28)> 0
Type a whole number from 1 to 28.

1) the plan  2) quota months  3) invoices  4) billing day  5) a steady use of your own  6) quit
choice> 4
billing day (1 to 28)> 29
Type a whole number from 1 to 28.

1) the plan  2) quota months  3) invoices  4) billing day  5) a steady use of your own  6) quit
choice> 4
billing day (1 to 28)> x
Type a whole number from 1 to 28.

1) the plan  2) quota months  3) invoices  4) billing day  5) a steady use of your own  6) quit
choice> 5
calls a day (1 to 999999)> 
Cancelled.

1) the plan  2) quota months  3) invoices  4) billing day  5) a steady use of your own  6) quit
choice> 5
calls a day (1 to 999999)> 0
Type a whole number from 1 to 999999.

1) the plan  2) quota months  3) invoices  4) billing day  5) a steady use of your own  6) quit
choice> 5
calls a day (1 to 999999)> 1000000
Type a whole number from 1 to 999999.

1) the plan  2) quota months  3) invoices  4) billing day  5) a steady use of your own  6) quit
choice> 5
calls a day (1 to 999999)> x
Type a whole number from 1 to 999999.

1) the plan  2) quota months  3) invoices  4) billing day  5) a steady use of your own  6) quit
choice> 5
calls a day (1 to 999999)> 161290
At 161,290 calls a day: 4,516,120 in a 28-day month, 4,838,700 in 30 days, 4,999,990 in 31.
Over the quota in 0 of 12 months of 2027. With the billing day the 18th, over in 0 of 11 invoices, billed 0.00.
Under the quota every month up to 161,290 a day; over it every month from 178,572 a day.

1) the plan  2) quota months  3) invoices  4) billing day  5) a steady use of your own  6) quit
choice> 5
calls a day (1 to 999999)> 161291
At 161,291 calls a day: 4,516,148 in a 28-day month, 4,838,730 in 30 days, 5,000,021 in 31.
Over the quota in 7 of 12 months of 2027. With the billing day the 18th, over in 6 of 11 invoices, 126 calls in all, billed 2.40.
Under the quota every month up to 161,290 a day; over it every month from 178,572 a day.

1) the plan  2) quota months  3) invoices  4) billing day  5) a steady use of your own  6) quit
choice> 6
Bye.
What was typed (23 lines)
0
x
4

4
0
4
29
4
x
5

5
0
5
1000000
5
x
5
161290
5
161291
6

basic

interpreter: byte-equal
== Subscription billing ==
An API plan whose quota resets on the 1st, invoiced over a cycle that starts on the billing day.

1) the plan  2) quota months  3) invoices  4) billing day  5) a steady use of your own  6) quit
choice> 1
The plan: 5,000,000 calls a calendar month; the count resets at midnight on the 1st, and every response says how many are left.
Calls over the quota cost 0.40 for each 1,000 or part of 1,000.
The invoice covers a cycle from the billing day to the day before it a month later. The billing day is the 18th.
The customers, through 2027:
  steady     165,000 calls every day
  month-end  480,000 calls a day over the last 10 days of Jan, Mar, May, Jul, Sep and Nov,
             350,000 a day over the first 14 days of the month after, 5,000 a day otherwise

1) the plan  2) quota months  3) invoices  4) billing day  5) a steady use of your own  6) quit
choice> 2
Calls in each month of 2027, against the quota of 5,000,000 (* over it):
  month  days     steady     month-end
  Jan      31  5,115,000 *   4,905,000
  Feb      28  4,620,000     4,970,000
  Mar      31  5,115,000 *   4,905,000
  Apr      30  4,950,000     4,980,000
  May      31  5,115,000 *   4,905,000
  Jun      30  4,950,000     4,980,000
  Jul      31  5,115,000 *   4,905,000
  Aug      31  5,115,000 *   4,985,000
  Sep      30  4,950,000     4,900,000
  Oct      31  5,115,000 *   4,985,000
  Nov      30  4,950,000     4,900,000
  Dec      31  5,115,000 *   4,985,000
steady: over the quota in 7 of 12 months, all of them 31 days long, at the same 165,000 calls every day; February holds 4,620,000. A monthly quota is 28 to 31 days of use.
month-end: over the quota in 0 of 12 months; its busiest month holds 4,985,000. The header never showed its quota run out.

1) the plan  2) quota months  3) invoices  4) billing day  5) a steady use of your own  6) quit
choice> 3
Invoices with the billing day the 18th, for the 11 cycles inside 2027, each allowing 5,000,000:
  cycle            days  steady                        month-end
  Jan 18 - Feb 17    31   5,115,000, 115,000 over       9,735,000, 4,735,000 over
  Feb 18 - Mar 17    28   4,620,000                       140,000
  Mar 18 - Apr 17    31   5,115,000, 115,000 over       9,735,000, 4,735,000 over
  Apr 18 - May 17    30   4,950,000                       150,000
  May 18 - Jun 17    31   5,115,000, 115,000 over       9,735,000, 4,735,000 over
  Jun 18 - Jul 17    30   4,950,000                       150,000
  Jul 18 - Aug 17    31   5,115,000, 115,000 over       9,735,000, 4,735,000 over
  Aug 18 - Sep 17    31   5,115,000, 115,000 over         155,000
  Sep 18 - Oct 17    30   4,950,000                     9,730,000, 4,730,000 over
  Oct 18 - Nov 17    31   5,115,000, 115,000 over         155,000
  Nov 18 - Dec 17    30   4,950,000                     9,730,000, 4,730,000 over
steady: over in 6 of 11 invoices, 690,000 calls in all, billed 276.00.
month-end: over in 6 of 11 invoices, 28,400,000 calls in all, billed 11,360.00.
The month-end customer never ran out of quota: a cycle that holds the 1st holds two quota months, and the invoice allows one.

1) the plan  2) quota months  3) invoices  4) billing day  5) a steady use of your own  6) quit
choice> 4
billing day (1 to 28)> 1
The billing day is now the 1st.

1) the plan  2) quota months  3) invoices  4) billing day  5) a steady use of your own  6) quit
choice> 3
Invoices with the billing day the 1st, for the 12 cycles inside 2027, each allowing 5,000,000:
  cycle            days  steady                        month-end
  Jan 1 - Jan 31     31   5,115,000, 115,000 over       4,905,000
  Feb 1 - Feb 28     28   4,620,000                     4,970,000
  Mar 1 - Mar 31     31   5,115,000, 115,000 over       4,905,000
  Apr 1 - Apr 30     30   4,950,000                     4,980,000
  May 1 - May 31     31   5,115,000, 115,000 over       4,905,000
  Jun 1 - Jun 30     30   4,950,000                     4,980,000
  Jul 1 - Jul 31     31   5,115,000, 115,000 over       4,905,000
  Aug 1 - Aug 31     31   5,115,000, 115,000 over       4,985,000
  Sep 1 - Sep 30     30   4,950,000                     4,900,000
  Oct 1 - Oct 31     31   5,115,000, 115,000 over       4,985,000
  Nov 1 - Nov 30     30   4,950,000                     4,900,000
  Dec 1 - Dec 31     31   5,115,000, 115,000 over       4,985,000
steady: over in 7 of 12 invoices, 805,000 calls in all, billed 322.00.
month-end: over in 0 of 12 invoices, billed 0.00.
With the billing day on the 1st each cycle is a quota month, and the invoices bill what the quota counted.

1) the plan  2) quota months  3) invoices  4) billing day  5) a steady use of your own  6) quit
choice> 5
calls a day (1 to 999999)> 165000
At 165,000 calls a day: 4,620,000 in a 28-day month, 4,950,000 in 30 days, 5,115,000 in 31.
Over the quota in 7 of 12 months of 2027. With the billing day the 1st, over in 7 of 12 invoices, 805,000 calls in all, billed 322.00.
Under the quota every month up to 161,290 a day; over it every month from 178,572 a day.

1) the plan  2) quota months  3) invoices  4) billing day  5) a steady use of your own  6) quit
choice> 5
calls a day (1 to 999999)> 170000
At 170,000 calls a day: 4,760,000 in a 28-day month, 5,100,000 in 30 days, 5,270,000 in 31.
Over the quota in 11 of 12 months of 2027. With the billing day the 1st, over in 11 of 12 invoices, 2,290,000 calls in all, billed 916.00.
Under the quota every month up to 161,290 a day; over it every month from 178,572 a day.

1) the plan  2) quota months  3) invoices  4) billing day  5) a steady use of your own  6) quit
choice> 6
Bye.
What was typed (11 lines)
1
2
3
4
1
3
5
165000
5
170000
6

Modules

The program as written, entry module first. Each module transpiles to its own Python file, which is what eml project run executes.

main.eml(entry)

eml
# P161 subscription billing: an API plan whose quota resets on the 1st,
# invoiced over a cycle that starts on the billing day - the quota months,
# the invoices, a billing day of your own and a steady use of your own.
import billing

def plain(s):
    0 => i
    len(s) => j
    while i < j and s[i] == " ":
        i + 1 => i
    while j > i and s[j - 1] == " ":
        j - 1 => j
    return s[i:j]

def pad(s, n):
    s => out
    while len(out) < n:
        out + " " => out
    return out

def lpad(s, n):
    s => out
    while len(out) < n:
        " " + out => out
    return out

def rstrip(s):
    len(s) => j
    while j > 0 and s[j - 1] == " ":
        j - 1 => j
    return s[0:j]

def commas(n):
    str(n) => s
    "" => out
    0 => k
    len(s) => i
    while i > 0:
        if k == 3:
            "," + out => out
            0 => k
        s[i - 1] + out => out
        k + 1 => k
        i - 1 => i
    return out

def money(cents):
    cents % 100 => c
    if c < 10:
        return commas(int((cents - c) / 100)) + ".0" + str(c)
    return commas(int((cents - c) / 100)) + "." + str(c)

def ordinal(n):
    if n % 10 == 1 and n != 11:
        return str(n) + "st"
    if n % 10 == 2 and n != 12:
        return str(n) + "nd"
    if n % 10 == 3 and n != 13:
        return str(n) + "rd"
    return str(n) + "th"

def digits(t):
    for c in t:
        if c < "0" or c > "9":
            return False
    return len(t) > 0

def label(cy):
    return billing.month_name(cy[0]) + " " + str(cy[1]) + " - " + billing.month_name(cy[2]) + " " + str(cy[3])

def show_plan(b):
    ("The plan: " + commas(billing.quota()) + " calls a calendar month; the count resets at midnight on the 1st, and every response says how many are left.") ^0
    "Calls over the quota cost 0.40 for each 1,000 or part of 1,000." ^0
    ("The invoice covers a cycle from the billing day to the day before it a month later. The billing day is the " + ordinal(b) + ".") ^0
    "The customers, through 2027:" ^0
    "  steady     165,000 calls every day" ^0
    "  month-end  480,000 calls a day over the last 10 days of Jan, Mar, May, Jul, Sep and Nov," ^0
    "             350,000 a day over the first 14 days of the month after, 5,000 a day otherwise" ^0

def show_months():
    ("Calls in each month of 2027, against the quota of " + commas(billing.quota()) + " (* over it):") ^0
    ("  " + pad("month", 5) + lpad("days", 6) + lpad("steady", 11) + "  " + lpad("month-end", 12)) ^0
    billing.customers() => cus
    [0, 0] => n_over
    [0, 0] => busiest
    1 => m
    while m <= 12:
        "  " + pad(billing.month_name(m), 5) + lpad(str(billing.days_in(m)), 6) => line
        0 => k
        while k < 2:
            billing.month_calls(cus[k], m) => n
            "  " => mark
            if n > billing.quota():
                " *" => mark
                n_over[k] + 1 => n_over[k]
            if n > busiest[k]:
                n => busiest[k]
            line + lpad(commas(n), 11 + k) + mark => line
            k + 1 => k
        rstrip(line) ^0
        m + 1 => m
    ("steady: over the quota in " + str(n_over[0]) + " of 12 months, all of them 31 days long, at the same 165,000 calls every day; February holds " + commas(billing.month_calls(cus[0], 2)) + ". A monthly quota is 28 to 31 days of use.") ^0
    ("month-end: over the quota in " + str(n_over[1]) + " of 12 months; its busiest month holds " + commas(busiest[1]) + ". The header never showed its quota run out.") ^0

def cell(n):
    lpad(commas(n), 10) => out
    if billing.over(n) > 0:
        out + ", " + commas(billing.over(n)) + " over" => out
    return out

def tally(cu, b):
    # [invoices over the quota, calls over, cents billed]
    [0, 0, 0] => t
    for cy in billing.cycles(b):
        billing.over(billing.span(cu, cy[0], cy[1], cy[2], cy[3])) => o
        if o > 0:
            t[0] + 1 => t[0]
            t[1] + o => t[1]
            t[2] + billing.charge(o) => t[2]
    return t

def invoiced(t, n):
    if t[0] == 0:
        return "over in 0 of " + str(n) + " invoices, billed 0.00."
    return "over in " + str(t[0]) + " of " + str(n) + " invoices, " + commas(t[1]) + " calls in all, billed " + money(t[2]) + "."

def show_invoices(b):
    billing.cycles(b) => cys
    ("Invoices with the billing day the " + ordinal(b) + ", for the " + str(len(cys)) + " cycles inside 2027, each allowing " + commas(billing.quota()) + ":") ^0
    ("  " + pad("cycle", 17) + lpad("days", 4) + "  " + pad("steady", 30) + "month-end") ^0
    billing.customers() => cus
    for cy in cys:
        billing.span(cus[0], cy[0], cy[1], cy[2], cy[3]) => s
        billing.span(cus[1], cy[0], cy[1], cy[2], cy[3]) => e
        ("  " + pad(label(cy), 17) + lpad(str(billing.cycle_days(cy)), 4) + "  " + pad(cell(s), 30) + cell(e)) ^0
    tally(cus[1], b) => te
    ("steady: " + invoiced(tally(cus[0], b), len(cys))) ^0
    ("month-end: " + invoiced(te, len(cys))) ^0
    if te[0] > 0:
        "The month-end customer never ran out of quota: a cycle that holds the 1st holds two quota months, and the invoice allows one." ^0
    else:
        "With the billing day on the 1st each cycle is a quota month, and the invoices bill what the quota counted." ^0

def set_day(b):
    plain(input("billing day (1 to 28)> ")) => t
    if t == "":
        "Cancelled." ^0
        return b
    if len(t) > 2 or not digits(t) or int(t) < 1 or int(t) > 28:
        "Type a whole number from 1 to 28." ^0
        return b
    ("The billing day is now the " + ordinal(int(t)) + ".") ^0
    return int(t)

def own(b):
    plain(input("calls a day (1 to 999999)> ")) => t
    if t == "":
        "Cancelled." ^0
        return
    if len(t) > 6 or not digits(t) or int(t) < 1:
        "Type a whole number from 1 to 999999." ^0
        return
    int(t) => r
    ["yours", r] => cu
    ("At " + commas(r) + " calls a day: " + commas(28 * r) + " in a 28-day month, " + commas(30 * r) + " in 30 days, " + commas(31 * r) + " in 31.") ^0
    0 => n
    1 => m
    while m <= 12:
        if billing.month_calls(cu, m) > billing.quota():
            n + 1 => n
        m + 1 => m
    tally(cu, b) => tt
    ("Over the quota in " + str(n) + " of 12 months of 2027. With the billing day the " + ordinal(b) + ", " + invoiced(tt, len(billing.cycles(b)))) ^0
    "Under the quota every month up to 161,290 a day; over it every month from 178,572 a day." ^0

"== Subscription billing ==" ^0
"An API plan whose quota resets on the 1st, invoiced over a cycle that starts on the billing day." ^0
18 => day
True => running
while running:
    "" ^0
    "1) the plan  2) quota months  3) invoices  4) billing day  5) a steady use of your own  6) quit" ^0
    plain(input("choice> ")) => choice
    if choice == "1":
        show_plan(day)
    elif choice == "2":
        show_months()
    elif choice == "3":
        show_invoices(day)
    elif choice == "4":
        set_day(day) => day
    elif choice == "5":
        own(day)
    elif choice == "6":
        False => running
    else:
        "Pick a number from 1 to 6." ^0
"Bye." ^0
Python projection (main.py)
import billing

def plain(s):
    i = 0
    j = len(s)
    while i < j and s[i] == " ":
        i = i + 1
    while j > i and s[j - 1] == " ":
        j = j - 1
    return s[i:j]

def pad(s, n):
    out = s
    while len(out) < n:
        out = out + " "
    return out

def lpad(s, n):
    out = s
    while len(out) < n:
        out = " " + out
    return out

def rstrip(s):
    j = len(s)
    while j > 0 and s[j - 1] == " ":
        j = j - 1
    return s[0:j]

def commas(n):
    s = str(n)
    out = ""
    k = 0
    i = len(s)
    while i > 0:
        if k == 3:
            out = "," + out
            k = 0
        out = s[i - 1] + out
        k = k + 1
        i = i - 1
    return out

def money(cents):
    c = cents % 100
    if c < 10:
        return commas(int((cents - c) / 100)) + ".0" + str(c)
    return commas(int((cents - c) / 100)) + "." + str(c)

def ordinal(n):
    if n % 10 == 1 and n != 11:
        return str(n) + "st"
    if n % 10 == 2 and n != 12:
        return str(n) + "nd"
    if n % 10 == 3 and n != 13:
        return str(n) + "rd"
    return str(n) + "th"

def digits(t):
    for c in t:
        if c < "0" or c > "9":
            return False
    return len(t) > 0

def label(cy):
    return billing.month_name(cy[0]) + " " + str(cy[1]) + " - " + billing.month_name(cy[2]) + " " + str(cy[3])

def show_plan(b):
    print("The plan: " + commas(billing.quota()) + " calls a calendar month; the count resets at midnight on the 1st, and every response says how many are left.")
    print("Calls over the quota cost 0.40 for each 1,000 or part of 1,000.")
    print("The invoice covers a cycle from the billing day to the day before it a month later. The billing day is the " + ordinal(b) + ".")
    print("The customers, through 2027:")
    print("  steady     165,000 calls every day")
    print("  month-end  480,000 calls a day over the last 10 days of Jan, Mar, May, Jul, Sep and Nov,")
    print("             350,000 a day over the first 14 days of the month after, 5,000 a day otherwise")

def show_months():
    print("Calls in each month of 2027, against the quota of " + commas(billing.quota()) + " (* over it):")
    print("  " + pad("month", 5) + lpad("days", 6) + lpad("steady", 11) + "  " + lpad("month-end", 12))
    cus = billing.customers()
    n_over = [0, 0]
    busiest = [0, 0]
    m = 1
    while m <= 12:
        line = "  " + pad(billing.month_name(m), 5) + lpad(str(billing.days_in(m)), 6)
        k = 0
        while k < 2:
            n = billing.month_calls(cus[k], m)
            mark = "  "
            if n > billing.quota():
                mark = " *"
                n_over[k] = n_over[k] + 1
            if n > busiest[k]:
                busiest[k] = n
            line = line + lpad(commas(n), 11 + k) + mark
            k = k + 1
        print(rstrip(line))
        m = m + 1
    print("steady: over the quota in " + str(n_over[0]) + " of 12 months, all of them 31 days long, at the same 165,000 calls every day; February holds " + commas(billing.month_calls(cus[0], 2)) + ". A monthly quota is 28 to 31 days of use.")
    print("month-end: over the quota in " + str(n_over[1]) + " of 12 months; its busiest month holds " + commas(busiest[1]) + ". The header never showed its quota run out.")

def cell(n):
    out = lpad(commas(n), 10)
    if billing.over(n) > 0:
        out = out + ", " + commas(billing.over(n)) + " over"
    return out

def tally(cu, b):
    t = [0, 0, 0]
    for cy in billing.cycles(b):
        o = billing.over(billing.span(cu, cy[0], cy[1], cy[2], cy[3]))
        if o > 0:
            t[0] = t[0] + 1
            t[1] = t[1] + o
            t[2] = t[2] + billing.charge(o)
    return t

def invoiced(t, n):
    if t[0] == 0:
        return "over in 0 of " + str(n) + " invoices, billed 0.00."
    return "over in " + str(t[0]) + " of " + str(n) + " invoices, " + commas(t[1]) + " calls in all, billed " + money(t[2]) + "."

def show_invoices(b):
    cys = billing.cycles(b)
    print("Invoices with the billing day the " + ordinal(b) + ", for the " + str(len(cys)) + " cycles inside 2027, each allowing " + commas(billing.quota()) + ":")
    print("  " + pad("cycle", 17) + lpad("days", 4) + "  " + pad("steady", 30) + "month-end")
    cus = billing.customers()
    for cy in cys:
        s = billing.span(cus[0], cy[0], cy[1], cy[2], cy[3])
        e = billing.span(cus[1], cy[0], cy[1], cy[2], cy[3])
        print("  " + pad(label(cy), 17) + lpad(str(billing.cycle_days(cy)), 4) + "  " + pad(cell(s), 30) + cell(e))
    te = tally(cus[1], b)
    print("steady: " + invoiced(tally(cus[0], b), len(cys)))
    print("month-end: " + invoiced(te, len(cys)))
    if te[0] > 0:
        print("The month-end customer never ran out of quota: a cycle that holds the 1st holds two quota months, and the invoice allows one.")
    else:
        print("With the billing day on the 1st each cycle is a quota month, and the invoices bill what the quota counted.")

def set_day(b):
    t = plain(input("billing day (1 to 28)> "))
    if t == "":
        print("Cancelled.")
        return b
    if len(t) > 2 or not digits(t) or int(t) < 1 or int(t) > 28:
        print("Type a whole number from 1 to 28.")
        return b
    print("The billing day is now the " + ordinal(int(t)) + ".")
    return int(t)

def own(b):
    t = plain(input("calls a day (1 to 999999)> "))
    if t == "":
        print("Cancelled.")
        return
    if len(t) > 6 or not digits(t) or int(t) < 1:
        print("Type a whole number from 1 to 999999.")
        return
    r = int(t)
    cu = ["yours", r]
    print("At " + commas(r) + " calls a day: " + commas(28 * r) + " in a 28-day month, " + commas(30 * r) + " in 30 days, " + commas(31 * r) + " in 31.")
    n = 0
    m = 1
    while m <= 12:
        if billing.month_calls(cu, m) > billing.quota():
            n = n + 1
        m = m + 1
    tt = tally(cu, b)
    print("Over the quota in " + str(n) + " of 12 months of 2027. With the billing day the " + ordinal(b) + ", " + invoiced(tt, len(billing.cycles(b))))
    print("Under the quota every month up to 161,290 a day; over it every month from 178,572 a day.")

print("== Subscription billing ==")
print("An API plan whose quota resets on the 1st, invoiced over a cycle that starts on the billing day.")
day = 18
running = True
while running:
    print("")
    print("1) the plan  2) quota months  3) invoices  4) billing day  5) a steady use of your own  6) quit")
    choice = plain(input("choice> "))
    if choice == "1":
        show_plan(day)
    elif choice == "2":
        show_months()
    elif choice == "3":
        show_invoices(day)
    elif choice == "4":
        day = set_day(day)
    elif choice == "5":
        own(day)
    elif choice == "6":
        running = False
    else:
        print("Pick a number from 1 to 6.")
print("Bye.")

billing.eml

eml
# P161 subscription billing - the plan, the customers and the calendar of
# 2027. As in the corpus case the-quota-renewed-monthly-and-the-billing-cycle-
# did-not, the quota is counted per calendar month and resets on the 1st,
# while the invoice is computed over a billing cycle that starts on the
# billing day: two windows a month long that are not the same month. And as
# in the-target-was-per-calendar-month-and-the-months-were-unequal, a monthly
# number is a different number of days each month, 28 to 31.

def quota():
    return 5000000

def price_cents():
    # for each 1,000 calls over the quota, or part of 1,000
    return 40

def month_name(m):
    return ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][m - 1]

def days_in(m):
    # 2027 is not a leap year; m is 1 to 12
    return [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][m - 1]

def customers():
    # [name, calls a day]; the month-end customer's calls follow its jobs
    return [["steady", 165000], ["month-end", 0]]

def calls(cu, m, d):
    # the calls customer cu makes on day d of month m
    if cu[0] != "month-end":
        return cu[1]
    if m % 2 == 1 and d > days_in(m) - 10:
        return 480000
    if m % 2 == 0 and d <= 14:
        return 350000
    return 5000

def span(cu, m1, d1, m2, d2):
    # calls from day d1 of month m1 to day d2 of month m2, both included
    0 => t
    m1 => m
    d1 => d
    while m < m2 or (m == m2 and d <= d2):
        t + calls(cu, m, d) => t
        if d == days_in(m):
            m + 1 => m
            1 => d
        else:
            d + 1 => d
    return t

def month_calls(cu, m):
    return span(cu, m, 1, m, days_in(m))

def cycles(b):
    # the billing cycles inside 2027 for billing day b, as [m1, d1, m2, d2]:
    # each runs from the billing day to the day before it a month later
    [] => out
    1 => m
    while m <= 12:
        if b == 1:
            out + [[m, 1, m, days_in(m)]] => out
        elif m < 12:
            out + [[m, b, m + 1, b - 1]] => out
        m + 1 => m
    return out

def cycle_days(cy):
    if cy[0] == cy[2]:
        return cy[3] - cy[1] + 1
    return days_in(cy[0]) - cy[1] + 1 + cy[3]

def over(n):
    # calls over the quota in a window of n calls
    if n > quota():
        return n - quota()
    return 0

def charge(n):
    # cents for n calls over the quota: 40 for each 1,000 or part of 1,000
    int((n - n % 1000) / 1000) => k
    if n % 1000 > 0:
        k + 1 => k
    return k * price_cents()
Python projection (billing.py)
def quota():
    return 5000000

def price_cents():
    return 40

def month_name(m):
    return ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][m - 1]

def days_in(m):
    return [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][m - 1]

def customers():
    return [["steady", 165000], ["month-end", 0]]

def calls(cu, m, d):
    if cu[0] != "month-end":
        return cu[1]
    if m % 2 == 1 and d > days_in(m) - 10:
        return 480000
    if m % 2 == 0 and d <= 14:
        return 350000
    return 5000

def span(cu, m1, d1, m2, d2):
    t = 0
    m = m1
    d = d1
    while m < m2 or m == m2 and d <= d2:
        t = t + calls(cu, m, d)
        if d == days_in(m):
            m = m + 1
            d = 1
        else:
            d = d + 1
    return t

def month_calls(cu, m):
    return span(cu, m, 1, m, days_in(m))

def cycles(b):
    out = []
    m = 1
    while m <= 12:
        if b == 1:
            out = out + [[m, 1, m, days_in(m)]]
        elif m < 12:
            out = out + [[m, b, m + 1, b - 1]]
        m = m + 1
    return out

def cycle_days(cy):
    if cy[0] == cy[2]:
        return cy[3] - cy[1] + 1
    return days_in(cy[0]) - cy[1] + 1 + cy[3]

def over(n):
    if n > quota():
        return n - quota()
    return 0

def charge(n):
    k = int((n - n % 1000) / 1000)
    if n % 1000 > 0:
        k = k + 1
    return k * price_cents()

Built on these corpus cases

ΣEML 2026

Efficient New Language — a high-density semantic overlay for humans and AI agents.

This site’s demos run on the real EML toolchain, in your browser.

© 2026 EveMissLab (一言諾科技有限公司) / Neo.K. All rights reserved.